how do i center this? You can see the Code next to the Emulator
Padding(
padding: const EdgeInsets.all(8.0),
child: SizedBox(
width: 120,
child: TextFormField(
inputFormatters: [
LengthLimitingTextInputFormatter(3),
],
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
style: const TextStyle(
fontSize: 16,
),
autovalidateMode: AutovalidateMode.disabled,
controller: controller,
cursorColor: Colors.white,
decoration: InputDecoration(
alignLabelWithHint: true,
floatingLabelAlignment: FloatingLabelAlignment.center,
labelText: lableText,
labelStyle: const TextStyle(fontSize: 16)),
),
),
),
I added code Snippet so you can see it better :)
you can do like this
SizedBox(
width: 120,
child: TextField(
textAlign: TextAlign.center,
decoration: InputDecoration(
border: OutlineInputBorder(),
hintText: 'In jahren',
),
),)
delete labelText and Use label instead.
give Text to label as child.
wrap label with Center.
TextFormField(
.
.
.
label: Center(
child: Text('In jahren'),
),//center
),//TextFormField
Related
I want to make the text be written at the center of the container but it keeps being at the bottom.
Container(
width: 250.yswx,
padding: EdgeInsets.symmetric(horizontal: 5.yswx),
child: Center(
child: TextField(
textAlignVertical: TextAlignVertical.center,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.black,
fontSize: 13.yswx
),
cursorColor: Colors.black,
decoration: InputDecoration(
border: InputBorder.none,
hintText: widget.placeHolder,
hintStyle: TextStyle(
color: Color(0xffbfbfbf),
fontSize: 13.yswx
)
),
),
),
);
the result:
Hope this helps:
TextField(
textAlign: TextAlign.center,
decoration: InputDecoration(
hintText: "Testing Centered",
),
I am trying to add a search input control to the app header in my Flutter web app.
See...
Widget _buildSearchControl() {
return Container(
alignment: Alignment.centerLeft,
color: Colors.white,
padding: EdgeInsets.only(right: 20),
margin: EdgeInsets.all(10),
width: 300,
child: TextField(
style: TextStyle(backgroundColor: Colors.white, color: Colors.black),
decoration: InputDecoration(
prefixIcon: const Icon(Icons.search,color: Colors.black,),
suffixIcon: IconButton(
icon: const Icon(Icons.clear,color: Colors.black,),
onPressed: () {
/* Clear the search field */
},
),
hintText: 'Search...',
border: InputBorder.none),
),
);
}
However, when entering the text, the characters are not vertically centre aligned as I wpuld expect
Is there a way I can have the characters input to the TextField control vertically centered so that they line up with the icons?
Have you tried this textAlignVertical property?
TextField(
textAlignVertical: TextAlignVertical.center,
....
),
I wrap the Container with Padding.
And add contentPadding: const EdgeInsets.all(5), to InputDecoration
...
Padding(
padding: const EdgeInsets.all(8.0).copyWith(bottom: 0),
child: Container(
decoration: BoxDecoration(
border: Border.all(color: Theme.of(context).primaryColor, width: 2),
borderRadius: const BorderRadius.all(Radius.circular(10)),
color: Colors.white
),
child: TextFormField(
controller: _controller,
onChanged: (string) {},
style: TextStyle(color: Theme.of(context).primaryColor),
cursorColor: Theme.of(context).primaryColor,
decoration: InputDecoration(
contentPadding: const EdgeInsets.all(5),
enabledBorder: InputBorder.none,
focusedBorder: InputBorder.none,
labelText: 'Enter',
labelStyle: TextStyle(
color: Theme.of(context).primaryColor,
fontSize: 16,
fontWeight: FontWeight.w500),
prefixIcon: Icon(
Icons.document_scanner_sharp,
color: Theme.of(context).primaryColor,
),
suffixIcon: Padding(
padding: const EdgeInsets.only(top: 5.0),
child: IconButton(
alignment: Alignment.topLeft,
icon: const Icon(
Icons.clear,
size: 25,
color: Colors.red,
),
tooltip: 'Clear',
onPressed: () {
FocusScope.of(context).unfocus();
_controller.clear();
}
),
)
)
),
),
),
Use this , maybe it depends on your contentPadding
Container(
width: 300,
height: 56,
margin: EdgeInsets.fromLTRB(0, 0, 0, 20),
child: TextFormField(
key: widget.globalKey,
autocorrect: false,
onTap: widget.onClick,
minLines: widget.minLines,
maxLines: widget.maxLines,
textInputAction: TextInputAction.done,
onChanged: (val) => widget.onChangeValue(val),
style: getInputStyle,
initialValue: widget.initialValue,
textAlign: TextAlign.left,
autovalidateMode: AutovalidateMode.onUserInteraction,
controller: widget.controller,
keyboardAppearance: Brightness.dark,
decoration: InputDecoration(
contentPadding: REdgeInsets.fromLTRB(
14, 16, 0, 16),
labelText: widget.labelText,
hintText: widget.hintText,
floatingLabelBehavior: FloatingLabelBehavior.auto,
labelStyle: getLabelStyle,
hintStyle: getLabelStyle,
fillColor: widget.backGroundColor ,
filled: true,
prefix: widget.prefix,
),
),
)
I want to reduce space between line and text with flutter.
SizedBox(
width: 60.0,
child: TextField(
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
style: TextStyle(color: Colors.black),
decoration: InputDecoration(
hintText: '125',
),
),
),
Instead of wrapping TextField inside SizedBox use constraints property of Input Decoration to give the TextField min or max height/width:
TextField(
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
style: TextStyle(color: Colors.black),
decoration: InputDecoration(
hintText: '125',
isDense: true,
constraints: BoxConstraints(
maxWidth: 60
)
),
)
Inside InputDecoration() set the contentPadding: EdgeInsets.zero. And set isDense: true
I don't understand why is this Scaffold not moving up when the keyboard is shown.
#override
Widget build(BuildContext context) {
if (widget.usuario.city.length < 3) {
controladorUbicacion.text = ciudadPropuesta + ", " + provinciaPropuesta;
}
if (widget.usuario.country.length < 3) {
controladorPais.text = paisPropuesto;
}
return SafeArea(
top: false,
bottom: true,
child: Scaffold(
appBar: AppBar(
backgroundColor: AppColors.rojoMovMap,
title: Text("miperfil".tr()),
),
body: SingleChildScrollView(
child: Column(
children: [
//username
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
onChanged: (text) {},
controller: controladorUsername,
decoration: InputDecoration(
hintText: 'tuusername'.tr().toString(),
hintStyle: TextStyle(color: Colors.black, fontSize: 14),
labelText: 'tuusername'.tr().toString(),
labelStyle:
TextStyle(fontSize: 18, color: AppColors.negroMovMap),
),
)),
//ubicacion
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
onChanged: (text) {},
controller: controladorUbicacion,
decoration: InputDecoration(
hintText: 'tuubicacion'.tr().toString(),
hintStyle: TextStyle(color: Colors.black, fontSize: 14),
labelText: 'tuubicacion'.tr().toString(),
labelStyle:
TextStyle(fontSize: 18, color: AppColors.negroMovMap),
),
)),
//pais
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
onChanged: (text) {},
controller: controladorPais,
decoration: InputDecoration(
hintText: 'tupais'.tr().toString(),
hintStyle: TextStyle(color: Colors.black, fontSize: 14),
labelText: 'tupais'.tr().toString(),
labelStyle:
TextStyle(fontSize: 18, color: AppColors.negroMovMap),
),
)),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
onChanged: (text) {},
controller: controladorNombre,
decoration: InputDecoration(
hintText: 'tunombre'.tr().toString(),
hintStyle: TextStyle(color: Colors.black, fontSize: 14),
labelText: 'tunombre'.tr().toString(),
labelStyle:
TextStyle(fontSize: 18, color: AppColors.negroMovMap),
),
)),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
onChanged: (text) {},
controller: controladorApellidos,
decoration: InputDecoration(
hintText: 'tusapellidos'.tr().toString(),
hintStyle: TextStyle(color: Colors.black, fontSize: 14),
labelText: 'tusapellidos'.tr().toString(),
labelStyle:
TextStyle(fontSize: 18, color: AppColors.negroMovMap),
),
)),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
onChanged: (text) {},
controller: controladorWeb,
decoration: InputDecoration(
hintText: 'tuweb'.tr().toString(),
hintStyle: TextStyle(color: Colors.black, fontSize: 14),
labelText: 'tuweb'.tr().toString(),
labelStyle:
TextStyle(fontSize: 18, color: AppColors.negroMovMap),
),
)),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
onChanged: (text) {},
decoration: InputDecoration(
hintText: 'PersonalInfoWeight'.tr().toString(),
hintStyle: TextStyle(color: Colors.black, fontSize: 14),
labelText: 'PersonalInfoWeight'.tr().toString(),
labelStyle:
TextStyle(fontSize: 18, color: AppColors.negroMovMap),
),
)),
],
),
),
),
);
}
}
Try to add inside Scaffold widget
Refer resizeToAvoidBottomInset
resizeToAvoidBottomInset: true,
When a user double taps the text to bring up "Cut Copy Paste", there is a sizing error with the pop-up and the text is cut off. I can't find any questions around this that can help.
See Screenshot and code below
Padding(
padding: const EdgeInsets.only(left: 12.0),
child: CupertinoTextField(
textCapitalization: TextCapitalization.words,
focusNode: titleFocus,
autofocus: true,
controller: titleController,
keyboardType: TextInputType.multiline,
maxLines: null,
cursorColor: Theme.of(context).cursorColor,
onSubmitted: (text) {
titleFocus.unfocus();
FocusScope.of(context)
.requestFocus(contentFocus);
},
textInputAction: TextInputAction.next,
style: GoogleFonts.roboto(
textStyle: TextStyle(
//color: Color(0xff3a4759),
fontSize: 20,
color: Theme.of(context).accentColor,
fontWeight: FontWeight.w700),
),
placeholder: "Sermon Title",
placeholderStyle: TextStyle(
color: Colors.grey.shade400,
fontSize: 20,
fontFamily: 'Helvetica Neue',
fontWeight: FontWeight.w500),
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey.withOpacity(0.0),
),
),
),
),
Try below code hope its help to you
Declare one Controller
final TextEditingController _controller = new TextEditingController();
Your Widget :
Column(
children:[
SizedBox(
height:30,
),
Padding(
padding: const EdgeInsets.all( 16.0),
child: CupertinoTextField(
textCapitalization: TextCapitalization.words,
autofocus: true,
controller: _controller,
keyboardType: TextInputType.multiline,
maxLines: null,
cursorColor: Theme.of(context).cursorColor,
textInputAction: TextInputAction.next,
placeholder: "Sermon Title",
placeholderStyle: TextStyle(
color: Colors.grey.shade400,
fontSize: 20,
fontFamily: 'Helvetica Neue',
fontWeight: FontWeight.w500),
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey.withOpacity(0.0),
),
),
),
),
],
),
Your result screen ->