text align : center in a textfield in flutter - flutter

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",
),

Related

Center TextFormField Flutter

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

Flutter: Align TextField text in a larger container

I can align the hint text to the center with no issues, but when the user starts typing into the textbox, I can't seem to get it to align to the center.
When maxLines are set to 1, there isn't an issue, but when it is set to more than 1 (or to null in my case), then it seems to align to the top by default.
Screenshot1
Screenshot2
Is there any way to correct this?
Container(
width: screenWidth / 1.2,
height: 120,
padding:
EdgeInsets.symmetric(horizontal: 0),
child: TextField(
// autofocus: false,
controller: postText,
keyboardType: TextInputType.text,
maxLines: 10,
textAlign: TextAlign.center,
textAlignVertical:
TextAlignVertical.center,
style: TextStyle(
fontFamily: 'Michroma',
color: selectedFont,
fontSize: 12, // 12
),
decoration: InputDecoration(
hintText: '\n\nType away ! :\n\n\n',
hintStyle: TextStyle(
color: fontColour,
fontFamily: 'Michroma',
fontWeight: FontWeight.bold,
fontSize: 12,
),
filled: true,
fillColor: screenColour,
contentPadding: EdgeInsets.symmetric(
vertical: 8.0,
horizontal: 10.0,
),
border: OutlineInputBorder(
borderRadius: BorderRadius.all(
Radius.circular(20.0),
), // 32
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(
color: borderColour,
width: 1.0,
),
borderRadius: BorderRadius.all(
Radius.circular(20.0),
), // 32
),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: borderColour,
width: 2.0,
),
borderRadius: BorderRadius.all(
Radius.circular(20.0),
), // 32
),
),
),
),
You need to delete \n\n expression in front of the hint text value because \n provides us to switch to a new line.
In your case, you switch the line you in two times. That is why the hint text is not appearing where you type.
decoration: InputDecoration(
hintText: 'Type away ! :', <--- here
hintStyle: TextStyle(
color: fontColour,
fontFamily: 'Michroma',
fontWeight: FontWeight.bold,
fontSize: 12),
When you remove that expression, probably it will not be in the center. so you can center it by doing following;
child: TextField(
controller: postTextController,
keyboardType: TextInputType.multiline,
textAlign: TextAlign.center,
maxLines: null,
expands: true,
textAlignVertical: TextAlignVertical.center,
style: TextStyle(
fontFamily: 'Michroma',
fontSize: 12),
decoration: InputDecoration(
hintText: 'Type away ! :',
hintStyle: TextStyle(
fontFamily: 'Michroma',
fontWeight: FontWeight.bold,
fontSize: 12),

Flutter UI not moving up when keyboard appears

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,

Flutter Cupertino Text Field Sizing Error

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 ->

How to align the HelperText in center?

TextFormField has a hintText and a HelperText , but i can seem to find a way to align the helperText in center , this is my code :
child: Container(
child: TextFormField(
textAlign: TextAlign.center,
style: TextStyle(fontSize: 21),
decoration: InputDecoration(
hintText: "hint text",
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: primaryColor)),
helperText: "THIS IS THE HELPER TEXT TO BE ALIGNED ",
helperStyle:
TextStyle(color: oASDC, fontSize: 15),
),
onChanged: (value) {
setState(() {.......});
},
),
),
is there a way to align the helper text in center?
You try this way:
https://i.stack.imgur.com/7LFJc.png
return TextFormField(
textAlign: TextAlign.center,
style: TextStyle(fontSize: 21),
decoration: InputDecoration(
contentPadding: EdgeInsets.only(left: 50, right: 50),
hintText: "hint text",
focusedBorder:
UnderlineInputBorder(borderSide: BorderSide(color: Colors.green)),
helperText: "THIS IS THE HELPER TEXT TO BE ALIGNED ",
helperStyle: TextStyle(
color: Colors.blue,
fontSize: 15,
),
),
);
From what I understand the position of the helperText is like the position of the errorText,
issue 1
issue 2
according to these issues, there seems to be no solution to this.
However, if you only need text , you can easily add Text widget below the TextFormField
like so:
Container(
child: Column(
children: [
TextFormField(
textAlign: TextAlign.center,
style: TextStyle(fontSize: 21),
decoration: InputDecoration(
hintText: "hint text",
focusedBorder: UnderlineInputBorder(borderSide: BorderSide(color: primaryColor),),
// helperText: "THIS IS THE HELPER TEXT TO BE ALIGNED ",
helperStyle: TextStyle(color: oASDC, fontSize: 15),
),
onChanged: (value) {
// setState(() {.......});
},
),
Text(
'THIS IS THE HELPER TEXT TO BE ALIGNED',
textAlign: TextAlign.center,
),
],
),
),
As far as I know, there is nothing conventional to align the helpertext.
Use contentPadding instead, not a proper way, but it's a day saver!
Container(
child: TextFormField(
textAlign: TextAlign.center,
style: TextStyle(fontSize: 21),
decoration: InputDecoration(
hintText: "hint text",
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.yellow)),
helperText: "THIS IS THE HELPER TEXT TO BE ALIGNED ",
helperStyle: TextStyle(
color: Colors.red,
fontSize: 15,
),
contentPadding: EdgeInsets.symmetric(horizontal: 25)),
onChanged: (value) {
print(value);
},
),
),