Flutter AutoSizeTextField multiline labelText - flutter

the labeltext field I set for AutoSizeTextField is insufficient. Is there a way to do multiline?
AutoSizeTextField(
...
style: TextStyle(
fontSize: 22, color: Colors.black),
decoration: InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(10.0),
),
labelText: AppLocalizations.of(context)
.translate('total_spent'),
labelStyle: TextStyle(
fontSize: 22, color: Colors.black,),
hintText: spent.toString(),
contentPadding: const EdgeInsets.all(10.0),
...

labelText size depends on AutoSizeTextField's font size if we don't specify the font size on labelStyle.
You can solve it by reducing the fontSize on labelStyle or separate the hit text using \n, label\ntext.
Or providing enough width to AutoSizeTextField.

Related

Text inside textform field is padded up

I am observing that the text for the below form field somehow padded up. Also the cursor has become very small like a dot. Any ideas ?
I want the text field height same as the right side round button
final border = OutlineInputBorder(
borderSide: BorderSide(
color: Colors.transparent,
),
borderRadius: const BorderRadius.all(
const Radius.circular(
10.0,
),
),
);
return TextFormField(
controller: controller,
onChanged: onChanged,
validator: validator,
autovalidateMode: AutovalidateMode.onUserInteraction,
cursorColor: Theme.of(context).highlightColor,
style: GoogleFonts.poppins(
color: Theme.of(context).highlightColor,
fontSize: 16,
fontWeight: FontWeight.w300,
height: 0.1,
),
textInputAction: TextInputAction.done,
decoration: InputDecoration(
fillColor: Theme.of(context).primaryColorLight,
filled: true,
enabledBorder: border,
focusedBorder: border,
border: border,
labelText: labelText,
// remove label while in focus
floatingLabelBehavior: FloatingLabelBehavior.never,
labelStyle: GoogleFonts.poppins(
color: Theme.of(context).highlightColor,
fontSize: 15,
fontWeight: FontWeight.w300,
),
),
);
The reason for for the additional padding and the small cursor is the font height which you are setting to 0.1 (keep the default 1.0 if you don't want the additional padding).
You can fix the cursor issue by setting cursorHeight to match your original font size
Note: use cursorHeight only if you want to keep the height as 0.1

Flutter DateTimeFormField Hint Text Color Doesn't Change

I have a big problem with DateTimeFormField on Flutter. I can't change hint, label, or default text style color change.
I already try this;
var textStyle = TextStyle(
color: Hexcolor("#D8D8D8"),
fontSize: ScreenUtil().setSp(42.0),
);
return DateTimeFormField(
mode: widget.mode,
label: widget.label,
decoration: InputDecoration(
filled: true,
fillColor: Hexcolor("#F9F9F9"),
contentPadding: EdgeInsets.only(
left: 20.0,
top: 20.0,
bottom: 5.0,
),
prefixStyle: textStyle,
hintStyle: textStyle,
labelStyle: textStyle,
border: defaultBorder,
focusedBorder: focusedBorder,
enabledBorder: enabledBorder,
),
onDateSelected: widget.onDateSelected,
//controller: widget.controller,
//maxLines: maxLines,
//obscureText: obscureText,
);
But color looks like this image :
How can I change the field default color?
Never used the Hexcolor plugin, why don't you try with a basic Color like:
Colors.lightBlue
And then maybe other method with Hexa:
Color(0xFF8BC34A)

Flutter Fill in Blank with RichText

I am almost done with fill in blanks implementation for my app but unfortunately I keep running into layout issues.
However as I keep solving the issues I am almost done with it, this is the code so far:
RichText(
text: TextSpan(
text: "dummy",
style: TextStyle(
color: Colors.white,
fontSize: 20,
height: 1.5,
fontWeight: FontWeight.bold),
children: <InlineSpan>[
TextSpan(
text:
' to to to to gdfgdfgdf to to to to to to to ',
style: TextStyle(
height: 1.0,
color: Colors.grey,
fontSize: 20,
fontWeight: FontWeight.bold)),
WidgetSpan(
alignment: PlaceholderAlignment.middle,
child: SecretWord("turtle"),
),
TextSpan(
text:
' to to to to gdfgdfgdf to to to to to to to ',
style: TextStyle(
height: 1.0,
color: Colors.grey,
fontSize: 20,
fontWeight: FontWeight.bold)),
)
And my SecretWord class:
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
class SecretWord extends StatelessWidget {
final String answer;
int answerLength;
String answerHint;
double answerWidth;
SecretWord(this.answer){
this.answerLength = answer.length;
this.answerHint = '.' * answerLength;
this.answerWidth = this.answerLength * 15.0;
}
String value = "";
#override
Widget build(BuildContext context) {
return Container(
//alignment: Alignment.bottomCenter,
width: answerWidth,
height: null,
// margin: const EdgeInsets.only(right: 10, left: 10),
child: TextFormField(
maxLines: null,
cursorColor: Colors.cyanAccent,
cursorRadius: Radius.circular(12.0),
cursorWidth: 2.0,
style: TextStyle(
color: (value == answer) ? Colors.amberAccent : Colors.lightGreenAccent,
fontWeight: FontWeight.bold,
fontSize: 20,
letterSpacing: 3,
// height: 0.5,
),
//textAlign: TextAlign.left,
autofocus: false,
maxLength: answerLength,
onChanged: (text) {
value = text;
},
decoration: new InputDecoration(
//labelText: 'Name *',
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
counterText: '',
hintText: answerHint,
hintStyle: TextStyle(
color: Colors.lightGreenAccent,
fontWeight: FontWeight.bold,
letterSpacing: 4,
// height: 0.5,
),
)
)
);
}
}
Unfortunately this create some issues: the container height of SecretWord is superior to TextSpan, how could I succeed to reduce the height of the Container with TextFormField to match the height of TextSpan ?
Notice that the second line has more space with first and third line than what I was expecting, it is because SecretWord is considered to take more space vertically. I know the cause but not how to solve it.
Hello I've come up with a solution to reduce the inner padding of TextField/TextFormField which looks like your problem.
Setting these values for the InputDecoration of the TextField should remove the vertical padding:
TextFormField(
decoration: InputDecoration(
isDense: true,
contentPadding: const EdgeInsets.symmetric(vertical: -5),
counterText: '',
),
)
isDense=true makes the input is part of dense form (i.e., uses less vertical
/// space).
setting contentPadding: const EdgeInsets.symmetric(vertical: -5) will reduce the vertical padding
As you already did in your example counterText: '' will prevent the counter text being shown.
So here is your new SecretWordClass with the changes. I also moved the properties under the build method since stateless widgets are immutable and their properties should be final.
import 'dart:ui';
import 'package:flutter/material.dart';
import 'package:flutter/painting.dart';
class SecretWord extends StatelessWidget {
final String answer;
SecretWord(this.answer);
#override
Widget build(BuildContext context) {
String value = "";
int answerLength = answer.length;
String answerHint = '.' * answerLength;
double answerWidth = answerLength * 15.0;
return Container(
width: answerWidth,
height: null,
child: TextFormField(
maxLines: null,
cursorColor: Colors.cyanAccent,
cursorRadius: Radius.circular(12.0),
cursorWidth: 2.0,
style: TextStyle(
color:
(value == answer) ? Colors.amberAccent : Colors.lightGreenAccent,
fontWeight: FontWeight.bold,
fontSize: 20,
letterSpacing: 3,
),
autofocus: false,
maxLength: answerLength,
onChanged: (text) {
value = text;
},
decoration: new InputDecoration(
isDense: true,
contentPadding: const EdgeInsets.symmetric(vertical: -5),
counterText: '',
border: InputBorder.none,
focusedBorder: InputBorder.none,
enabledBorder: InputBorder.none,
errorBorder: InputBorder.none,
disabledBorder: InputBorder.none,
hintText: answerHint,
hintStyle: TextStyle(
color: Colors.lightGreenAccent,
fontWeight: FontWeight.bold,
letterSpacing: 4,
),
),
),
);
}
}
Here are the results:

Is there a way that I can the input field text when the field is focussed?

I have the following inputfield
child: TextFormField
(
decoration: InputDecoration
(
hintText: 'Enter your name',
labelStyle: Theme.of(context).textTheme.body1,
hintStyle: Theme.of(context).textTheme.body1,
helperStyle: Theme.of(context).textTheme.body1,
prefixStyle: Theme.of(context).textTheme.body1,
counterStyle: Theme.of(context).textTheme.body1,
suffixStyle: Theme.of(context).textTheme.body1,
errorStyle: Theme.of(context).textTheme.body1,
border: OutlineInputBorder
(
borderSide: BorderSide
(
color: Theme.of(context).primaryColor,
width: 2.0,
),
),
enabledBorder: OutlineInputBorder
(
borderSide: BorderSide
(
color: Theme.of(context).primaryColor,
width: 2.0,
),
)
),
validator: (value) {
return value.isEmpty ? 'Please enter your name' : null;
},
),
When I render it it's height is way to big.
The I noticed that when I type something the text is huge
I tried changing all he styles but nothing helps. How can I that text smaller?
Change the font size of TextFormField, not the decoration:
TextFormField(
style: TextStyle(fontSize: 8), // set your font size here
decoration: InputDecoration
( ...
PS
'body1' is deprecated and shouldn't be used. This is the term used in
the 2014 version of material design. The modern term is bodyText2.
This feature was deprecated after v1.13.8

How to get rid of padding to the left of suffixIcon? Because of the padding cursor is not centered correctly

Here is the code:
TextField(
controller: _textEditingController,
decoration: new InputDecoration(
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Theme.of(context).accentColor,
width: 4.0,
),
borderRadius: new BorderRadius.circular(8.0)),
focusedBorder: new OutlineInputBorder(
borderRadius: new BorderRadius.circular(8.0),
borderSide: new BorderSide(
style: BorderStyle.solid,
color: Theme.of(context).accentColor,
width: 4.0,
),
),
filled: true,
fillColor: _getFillColorBasedOnInput(context),
suffixIcon: IconButton(
icon: SvgPicture.asset(
'assets/images/checkmark_yellow.svg',
color: _textEditingController.text.isEmpty ? Colors.black12 : null,
width: 32.0,
height: 32.0,
)),
),
keyboardType: TextInputType.text,
textCapitalization: TextCapitalization.sentences,
textAlign: TextAlign.center,
cursorColor: Theme.of(context).accentColor,
style: new TextStyle(
fontSize: 24,
color: Theme.of(context).accentColor,
))
Here is how it looks like:
Can anyone suggest some solutions to center cursor against the beginning of an input field and a checkmark icon (see red dotted line). I have tried a lot of ideas but none of them led to the desired result. Thank you.
There's 2 things that you can do here:
1) Change the code of the suffix icon in the flutter files by removing the extra padding.
2) This is a workaround, you can use Stack Widget to keep your icon above the Textfield. This way you'll have the cursor centred.
Although, it will look unpleasant if your typed text is too long (i.e. Your typed input below icon). In that case you might limit your lnput.