flutter center text with suffix icon - flutter

SizedBox(
width: 150,
child: TextField(
textAlign: TextAlign.center,
decoration: InputDecoration(
suffixIcon: Icon(
Icons.keyboard_arrow_down_outlined,
color: kGreyColor,
),
hintStyle: TextStyle(fontSize: 20),
hintText: "Bugün"),
),
),
how can i make this design I did something but it didn't turn out well
eddit:Content padding coming theme but not looking exactly center

You can achieve this by using a Container and a Stack.
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5),
border: Border.all(color: Colors.grey)),
child: Stack(
children: const [
Padding(
padding: EdgeInsets.symmetric(horizontal: 40, vertical: 5),
child: Text("Bugün"),
),
Positioned.fill(
child: Align(
alignment: Alignment.centerRight,
child: Icon(
Icons.keyboard_arrow_down_outlined,
),
),
)
],
),
)
You can check the code on this DartPad

/* Don't change your code just add this you will get your exact answer. */
SizedBox(
width: 150,
child: TextField(
textAlign: TextAlign.end,
decoration: InputDecoration(
suffixIcon: Icon(
Icons.keyboard_arrow_down_outlined,
color: Colors.grey,
),
hintStyle: TextStyle(fontSize: 20,),
hintText: "Bugün"),
),
),

Related

Attach two suffix icon with background on textfield in flutter?

I want the outcome to be like this,
but so far what I have achieved is
The 'From' tag is not an issue but the outline is.
here is code for my text field.
TextField(
enabled: false,
decoration: InputDecoration(
disabledBorder: OutlineInputBorder(
borderSide:
BorderSide(color: colorx.Colors.black, width: 0.7),
),
hintText: 'YYYY-MM-DD',
hintStyle: TextStyle(color: Colors.black12),
suffixIcon: Container(
height: 58,
width: 80,
decoration:
BoxDecoration(color: colorx.Colors.paleGreyTwo,),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
// added line
mainAxisSize: MainAxisSize.min,
// added line
children: [
Image.asset(
"graphics/calender.png",
),
Image.asset(
"graphics/refresh_date.png",
),
],
),
),
),
style: TextStyle(color: Colors.black),
),
Try below code hope its help to you. just change my icons to your Images
TextField(
enabled: false,
decoration: InputDecoration(
disabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.black, width: 0.7,),
),
hintText: 'YYYY-MM-DD',
hintStyle: TextStyle(color: Colors.black12,),
suffixIcon: Container(
margin: EdgeInsets.all(1),
height: 58,
width: 100,
decoration: BoxDecoration(
color: Colors.grey,
border: Border(
left: BorderSide(
color: Colors.black,
width: 1.0,
),
),),
child: IntrinsicHeight(
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Icon(Icons.date_range,),
VerticalDivider(
color: Colors.black,
thickness: 1,
),
Icon(Icons.close,),
],
),
),
),
),
style: TextStyle(
color: Colors.black,
),
),
Your result screen->

Flutter: RenderPhysicalModel object was given an infinite size during layout

I am making a SignUp Screen, at first I had like no problems as when I run the code but the Bottom OverFlow by some pixels as I haven't inserted ScrollView or ListView, but as I add the ScrollView or ListView over my Scaffold I get the error like:
════════ Exception caught by rendering library ═════════════════════════════════
RenderPhysicalModel object was given an infinite size during layout.
The relevant error-causing widget was
Scaffold
lib\screens\home.dart:22
════════════════════════════════════════════════════════════════════════════════
Here's my code:
Widget buildSignInScreen(){
return SingleChildScrollView(
child: Scaffold(
body: Container(
padding: EdgeInsets.symmetric(vertical: 40),
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
colors: [
Colors.deepPurple.shade900,
Colors.deepPurple.shade800,
Colors.deepPurple.shade400,
]
)
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(height: 70,),
Padding(
padding: EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text("Login",style: TextStyle(color: Colors.white,fontSize: 30 ),),
SizedBox(height: 10,),
Text("Welcome Back",style: TextStyle(color: Colors.white,fontSize: 30 ),),
],
),
),
Expanded(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(topLeft: Radius.circular(50),topRight: Radius.circular(50),)
),
child: Padding(
padding: EdgeInsets.all(20),
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
boxShadow: [BoxShadow(
color: Color.fromARGB(220, 90, 30, 10),
blurRadius: 20,
offset: Offset(0,10),
)]
),
child: Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey.shade200))
),
child: TextField(
decoration: InputDecoration(
hintText: "Phone Number",
hintStyle: TextStyle(color: Colors.grey),
border: InputBorder.none,
),
),
),
Container(
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey.shade200))
),
child: TextField(
decoration: InputDecoration(
hintText: "Password",
hintStyle: TextStyle(color: Colors.grey),
border: InputBorder.none,
),
),
)
],
),
),
SizedBox(height: 40,),
Text("Forget Password",style: TextStyle(color: Colors.grey),),
SizedBox(height: 40,),
Container(
height: 50,
margin: EdgeInsets.symmetric(horizontal: 50),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50),
color: Colors.deepPurple[900],
),
child: Center(
child: Text("Login",style: TextStyle(color: Colors.white,fontSize: 18,fontWeight: FontWeight.bold),),
),
),
SizedBox(height: 60,),
Text("Continue with social media",style: TextStyle(color: Colors.grey,),),
SizedBox(height: 20,),
Row(
children: <Widget>[
Expanded(
child: Container(
height: 50,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50),
color: Colors.blueAccent,
),
child: Center(
child: Text("Twitter",style: TextStyle(color: Colors.white),),
),
),
),
SizedBox(width: 30,),
Expanded(
child: Container(
height: 50,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50),
color: Colors.deepPurpleAccent,
),
child: Center(
child: Text("Skype",style: TextStyle(color: Colors.white),),
),
),
),
SizedBox(width: 30,),
],
)
],
),
),
),
)
],
),
),
),
);
}
Just remove the Expanded widget from the Column and load SingleChildScrollView to the parent of Container not Scaffold. Please find the code snippets below,
Widget buildSignInScreen() {
return Scaffold(
body: SingleChildScrollView(
child: Container(
padding: EdgeInsets.symmetric(vertical: 40),
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(begin: Alignment.topCenter, colors: [
Colors.deepPurple.shade900,
Colors.deepPurple.shade800,
Colors.deepPurple.shade400,
])),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 70,
),
Padding(
padding: EdgeInsets.all(20),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Text(
"Login",
style: TextStyle(color: Colors.white, fontSize: 30),
),
SizedBox(
height: 10,
),
Text(
"Welcome Back",
style: TextStyle(color: Colors.white, fontSize: 30),
),
],
),
),
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(50),
topRight: Radius.circular(50),
)),
child: Padding(
padding: EdgeInsets.all(20),
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Color.fromARGB(220, 90, 30, 10),
blurRadius: 20,
offset: Offset(0, 10),
)
]),
child: Column(
children: <Widget>[
Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.grey.shade200))),
child: TextField(
decoration: InputDecoration(
hintText: "Phone Number",
hintStyle: TextStyle(color: Colors.grey),
border: InputBorder.none,
),
),
),
Container(
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.grey.shade200))),
child: TextField(
decoration: InputDecoration(
hintText: "Password",
hintStyle: TextStyle(color: Colors.grey),
border: InputBorder.none,
),
),
)
],
),
),
SizedBox(
height: 40,
),
Text(
"Forget Password",
style: TextStyle(color: Colors.grey),
),
SizedBox(
height: 40,
),
Container(
height: 50,
margin: EdgeInsets.symmetric(horizontal: 50),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50),
color: Colors.deepPurple[900],
),
child: Center(
child: Text(
"Login",
style: TextStyle(
color: Colors.white,
fontSize: 18,
fontWeight: FontWeight.bold),
),
),
),
SizedBox(
height: 60,
),
Text(
"Continue with social media",
style: TextStyle(
color: Colors.grey,
),
),
SizedBox(
height: 20,
),
Row(
children: <Widget>[
Expanded(
child: Container(
height: 50,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50),
color: Colors.blueAccent,
),
child: Center(
child: Text(
"Twitter",
style: TextStyle(color: Colors.white),
),
),
),
),
SizedBox(
width: 30,
),
Expanded(
child: Container(
height: 50,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50),
color: Colors.deepPurpleAccent,
),
child: Center(
child: Text(
"Skype",
style: TextStyle(color: Colors.white),
),
),
),
),
SizedBox(
width: 30,
),
],
)
],
),
),
)
],
),
),
),
);
}

Allow widget to be pushed off the screen by content below when the keyboard is opened

What I'm trying to do is have an image widget at the top of the screen then have some inputs and a button at the bottom for logging in like so:
And then when the user opens the keyboard I want the inputs to stick to the bottom of screen being pushed up by the keyboard which is pretty easy to do on a large device but on smaller devices the inputs hit the image and get covered by the keyboard causing errors so instead I want to have the image simply pushed upwards and off the screen by the inputs but I can't figure out how to do it so far I've managed to get this:
Which is obviously not quite what I'm after as I don't want the image to shrink I just want it to be pushed off the screen any suggestions would be much appreciated
Minimal code to get the results shown in the images
return Stack(
children: [
Scaffold(
body: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Container(child: Image.asset('assets/temp.png', height: 115)),
),
Padding(
padding: EdgeInsets.fromLTRB(
50, 0, 50, isKeyboardVisible ? 10 : 50),
child: Column(
children: [
TextFormField(
style: TextStyle(fontSize: 20.0),
decoration: InputDecoration(
filled: true,
fillColor: Colors.grey[350],
hintText: 'Username',
contentPadding:
EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(40.0),
),
),
),
SizedBox(height: 20.0),
TextFormField(
style: TextStyle(fontSize: 20.0),
decoration: InputDecoration(
filled: true,
fillColor: Colors.grey[350],
hintText: 'Password',
contentPadding:
EdgeInsets.fromLTRB(20.0, 15.0, 20.0, 15.0),
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(40.0),
),
),
),
SizedBox(height: 20.0),
Center(
child: Material(
elevation: 5.0,
borderRadius: BorderRadius.circular(20),
color: Colors.lightGreen,
child: MaterialButton(
onPressed: () {},
child: Text(
'Login',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20.0,
),
),
),
),
),
],
),
),
],
),
),
],
);
EDIT: So I've been playing around for a little while and I've managed to get further but now all the way this is the code I have now:
return Stack(
children: [
Scaffold(
body: SingleChildScrollView(
child: Container(
height: MediaQuery.of(context).size.height -
MediaQuery.of(context).viewInsets.bottom, // screen height minus keyboard height but interestingly if i just do MediaQuery.of(context).size.height i dont get errors so its almost working
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Center(
child: Image.asset('assets/temp.png', height: 115),
),
Padding(
padding: EdgeInsets.fromLTRB(
50, 0, 50, isKeyboardVisible ? 10 : 50),
child: Column(
children: [
TextFormField(
style: TextStyle(fontSize: 20.0),
decoration: InputDecoration(
filled: true,
fillColor: Colors.grey[350],
hintText: 'Username',
contentPadding: EdgeInsets.fromLTRB(
20.0, 15.0, 20.0, 15.0),
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(40.0),
),
),
),
SizedBox(height: 20.0),
TextFormField(
style: TextStyle(fontSize: 20.0),
decoration: InputDecoration(
filled: true,
fillColor: Colors.grey[350],
hintText: 'Password',
contentPadding: EdgeInsets.fromLTRB(
20.0, 15.0, 20.0, 15.0),
border: OutlineInputBorder(
borderSide: BorderSide.none,
borderRadius: BorderRadius.circular(40.0),
),
),
),
SizedBox(height: 20.0),
Center(
child: Material(
elevation: 5.0,
borderRadius: BorderRadius.circular(20),
color: Colors.lightGreen,
child: MaterialButton(
onPressed: () {},
child: Text(
'Login',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold,
fontSize: 20.0,
),
),
),
),
),
],
),
),
],
),
),
),
),
],
);
As you can see in the comment thats in the code I'm taking the screen height then taking the keyboard height away as it then shrinks the Columns pushing the inputs up but I get errors however if I don't take the keyboard height away it almost works but there is a massive gap between the image and the inputs which is not what I want hence why I'm removing the keyboard height but then that causes issues so I can't figure out what I'm supposed to do to get the desired result.
remove Flexible and then
try wrapping your column with SingleChildScrollView
Scaffold(
body: SingleChildScrollView(child:Column(

Textfield height is not decreasing in flutter | Flutter

Container(
height: 30,
child: Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
decoration: InputDecoration(
suffixIcon: Padding(
padding: const EdgeInsets.all(8.0),
child: IconButton(
icon: Icon(
Icons.search,
),
onPressed: () {},
),
),
border: new OutlineInputBorder(
borderRadius: const BorderRadius.all(
const Radius.circular(30.0),
),
),
filled: true,
hintStyle: new TextStyle(
color: Colors.grey[500],
),
hintText: "Search Here",
fillColor: Colors.white70,
),
),
),
),
I want to reduce the textfield size, wrapping it with container and giving height is not working. is there any way to reduce the textfield size
Container(
width: 100.0,
child: TextField(
style: TextStyle(
fontSize: 30.0,
height: 2.0,
)
)
)

How to style this kind of Text Field

I want to style this kind of TextField.
The main problem that I'm facing is to design the US$ part in leading the TextField. This is my code so far.
/// My Place Bid Text Field
Container(
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.circular(4),
),
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
SizedBox(
child: Container(
//width: mySize.width * 0.2,
//height: 50,
padding: const EdgeInsets.all(8),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4),
bottomLeft: Radius.circular(4),
),
color: Colors.grey[200]),
child: Text(
"RS \u20B9",
style: TextStyle(fontSize: 24),
),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
labelText: "Place Bid",
labelStyle: TextStyle(fontSize: 24)),
),
),
],
),
),
Which gives me output
I know this question is not that complicated, but I'm still relatively new to flutter so your help would be much appreciated.
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("Sample"),
),
body: Padding(
padding: EdgeInsets.all(10),
child: Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey[500],
),
borderRadius: BorderRadius.all(Radius.circular(8))),
width: double.infinity,
height: 50,
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.all(10),
color: Colors.grey.shade300,
height: 50,
child: Align(
alignment: Alignment.center,
child: Text(
"RS \u20B9",
style: TextStyle(
fontSize: 24, fontWeight: FontWeight.bold),
),
)),
SizedBox(
width: 10,
),
Expanded(
child: Container(
height: 50,
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Enter Bid",
labelStyle: TextStyle(fontSize: 24)),
)))
],
),
),
));
}
Output
You can use the prefixIcon to add a widget at the beginning of the textfield:
Container(
child: Row(
children: [
Expanded(
child: TextField(
decoration: InputDecoration(
prefixIcon: Padding(
padding: const EdgeInsetsDirectional.only(start: 2.0),
child: Container(
padding: const EdgeInsets.all(13),
decoration: BoxDecoration(
border: Border.all(color: Colors.grey),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4),
bottomLeft: Radius.circular(4),
),
color: Colors.grey[200]),
child: Text(
"RS \u20B9",
style: TextStyle(fontSize: 24),
),
),
),
border: const OutlineInputBorder(),
labelText: 'Hint Text',
),
),
),
],
),
)
example:
https://dartpad.dev/a89aff20d67e2cb31da6a07ba7c17910
Based on your solution.
Notice the "IntrinsicHeight" widget. It makes all the children inside the child the same size (depending on the biggest one). The "Center" widget inside the prefix makes the Container go max height + center the text inside of it. Just make sure not to use IntrinsicHeight too much, since the docs state that it's a bit resource heavy.
Container(
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
border: Border.all(color: Colors.grey[200]),
),
child: IntrinsicHeight(
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(horizontal: 10.0),
decoration: BoxDecoration(
color: Colors.grey[100],
border: Border(
right: BorderSide(color: Colors.grey[200]),
),
),
child: Center(
child: Text(
'RS \u20B9',
style: TextStyle(fontSize: 24),
),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
border: InputBorder.none,
labelText: "Place Bid",
),
),
),
],
),
),
),
The second code is almost the same, except there's no label after typing the text inside the TextField.
Container(
margin: EdgeInsets.symmetric(horizontal: 20.0),
width: double.infinity,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
border: Border.all(color: Colors.grey[200]),
),
child: IntrinsicHeight(
child: Row(
children: <Widget>[
Container(
padding: EdgeInsets.symmetric(horizontal: 10.0),
decoration: BoxDecoration(
color: Colors.grey[100],
border: Border(
right: BorderSide(color: Colors.grey[200]),
),
),
child: Center(
child: Text(
'RS \u20B9',
style: TextStyle(fontSize: 24),
),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
contentPadding: EdgeInsets.symmetric(
horizontal: 20.0,
vertical: 20.0,
),
border: InputBorder.none,
hintText: "Place Bid",
),
),
),
],
),
),
),
Container(
decoration: BoxDecoration(
),
child: Row(
mainAxisSize: MainAxisSize.max,
children: [
SizedBox(
child: Container(
//width: mySize.width * 0.2,
//height: 50,
padding: const EdgeInsets.all(10),
decoration: BoxDecoration(
border:Border.all(color:Colors.grey),
borderRadius: BorderRadius.only(
topLeft: Radius.circular(4),
bottomLeft:Radius.circular(4),
),
color: Colors.grey[200]),
child: Text(
"RS \u20B9",
style: TextStyle(fontSize: 24),
),
),
),
Expanded(
child: TextField(
decoration: InputDecoration(
border: new OutlineInputBorder(
borderRadius: BorderRadius.only(
topRight: Radius.circular(4),
bottomRight:
Radius.circular(4),
),
),
isDense: true,
labelText: "Place Bid",
labelStyle:
TextStyle(fontSize:24)),
),
),
],
),
),