Flutter can't use textfield properly - flutter

I can't properly see a text written inside textfield
In addition when I reach the end of the TextField my text vanishes
I solve it by wrapping TextField in Expanded Widget it worked till today
https://imgur.com/XjsWqwX
SizedBox(
height: device.height * 39 / 812,
width: double.infinity,
child: Container(
padding: EdgeInsets.all(7),
margin: EdgeInsets.only(top: 7),
decoration: BoxDecoration(
border: new Border.all(color: Color.fromRGBO(49, 80, 175, 0.36)),
color: Color.fromRGBO(249, 248, 255, 1),
borderRadius: new BorderRadius.all(
Radius.circular(7.0),
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: <Widget>[
Container(
margin: EdgeInsets.only(left: 7, right: 10),
child: CheckBox(
null,
false,
Colors.white,
),
),
Container(
alignment: Alignment.bottomCenter,
width: 300,
// height: 30,
color: Colors.red,
child: TextFormField(
decoration: new InputDecoration(
border: InputBorder.none,
focusedBorder: InputBorder.none,
),
),
),
],
),
),
);

Try to wrap your textfield with Flexible widget as follows
Flexible(
child: Container(
padding: EdgeInsets.fromLTRB(3.0, 3.0, 3.0, 12.0),
child: TextFormField (
decoration: new InputDecoration(
border: InputBorder.none,
focusedBorder: InputBorder.none,
),
)
)

Related

Bottom overflowed by 249 pixels when I click on a form field

Here is my code
Expanded(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(topLeft: Radius.circular(60),topRight: Radius.circular(60)),
),
child: Container(
padding: EdgeInsets.all(20),
child: Column( ----->line54:26
children: [
SizedBox(height: 40.0,),
Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
boxShadow: [
BoxShadow(
color: Color.fromRGBO(225, 95, 27, .3),
blurRadius: 20.0,
offset: Offset(0,10)
)
]
),
child: Form(
child: Column(
children: [
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey.shade200))
),
child: TextField(
decoration: InputDecoration(
hintText: "Votre nom",
hintStyle: TextStyle(color: Colors.grey),
border: InputBorder.none
),
),
),
SizedBox(height: 10),
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey.shade200))
),
child: TextFormField(
decoration: InputDecoration(
hintText: "Votre prénom"
),
),
),
SizedBox(height: 10),
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey.shade200))
),
child: TextField(
decoration: InputDecoration(
hintText: "Numéro client",
hintStyle: TextStyle(color: Colors.grey),
border: InputBorder.none
),
),
),
],
),
),
),
SizedBox(height: 40.0),
Container(
height: 50,
margin: EdgeInsets.symmetric(horizontal: 50),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50),
color: Colors.green
),
child: Center(
child: TextButton(
onPressed: (){print("gfhjk");},
child: Text(
"Activer",
style: TextStyle(fontWeight: FontWeight.bold,color: Colors.white,fontSize: 16),
),
),
)
)
],
),
),
),
),
The following assertion was thrown during layout:
A RenderFlex overflowed by 249 pixels on the bottom.
The relevant error-causing widget was:
Column Column:file:///xxxxxxx/lib/ecrans/auth/activation_screen.dart:54:26
The overflowing RenderFlex has an orientation of Axis.vertical.
The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and black striped pattern. This is usually caused by the contents being too big for the RenderFlex.
Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the RenderFlex to fit within the available space instead of being sized to their natural size.
This is considered an error condition because it indicates that there is content that cannot be seen. If the content is legitimately bigger than the available space, consider clipping it with a ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex, like a ListView.
The specific RenderFlex in question is: RenderFlex#1a283 relayoutBoundary=up5 OVERFLOWING
... needs compositing
... parentData: offset=Offset(20.0, 20.0) (can use size)
... constraints: BoxConstraints(0.0<=w<=371.4, h=148.1)
... size: Size(371.4, 148.1)
... direction: vertical
... mainAxisAlignment: start
... mainAxisSize: max
... crossAxisAlignment: center
... verticalDirection: down
I need help
Wrap your main container with SingleChildScrollView instead of the Expanded
SingleChildScrollView(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(60), topRight: Radius.circular(60)),
),
child: Container(
padding: EdgeInsets.all(20),
child: Column(
children: <Widget>[
SizedBox(
height: 40.0,
),
Container(
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10.0),
boxShadow: [
BoxShadow(
color: Color.fromRGBO(225, 95, 27, .3),
blurRadius: 20.0,
offset: Offset(0, 10))
]),
child: Form(
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
border: Border(
bottom:
BorderSide(color: Colors.grey.shade200))),
child: TextField(
decoration: InputDecoration(
hintText: "Votre nom",
hintStyle: TextStyle(color: Colors.grey),
border: InputBorder.none),
),
),
SizedBox(height: 10),
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
border: Border(
bottom:
BorderSide(color: Colors.grey.shade200))),
child: TextFormField(
decoration:
InputDecoration(hintText: "Votre prénom"),
),
),
SizedBox(height: 10),
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
border: Border(
bottom:
BorderSide(color: Colors.grey.shade200))),
child: TextField(
decoration: InputDecoration(
hintText: "Numéro client",
hintStyle: TextStyle(color: Colors.grey),
border: InputBorder.none),
),
),
],
),
),
),
SizedBox(height: 40.0),
Container(
height: 50,
margin: EdgeInsets.symmetric(horizontal: 50),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(50),
color: Colors.green),
child: Center(
child: TextButton(
onPressed: () {
print("gfhjk");
},
child: Text(
"Activer",
style: TextStyle(
fontWeight: FontWeight.bold,
color: Colors.white,
fontSize: 16),
),
),
))
],
),
),
),
),

My second container is taking all the space.How to avoid that

The second Container which is in the red color is taking all the remaining space. How to avoid that. I want my second container to take the minimum space.
Container(
height: 600,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(60),
),
),
child: Padding(
padding: const EdgeInsets.only(top: 80.0, right: 50, left: 50),
child: Container(
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.all(
Radius.circular(20),
),
),
child: Column(
children: [
TextFormField(
decoration: const InputDecoration(
border: UnderlineInputBorder(),
labelText: "Email or Phone Number"),
),
SizedBox(
height: 20,
),
TextField(
decoration:
new InputDecoration.collapsed(hintText: 'PassWord'),
)
],
),
),
),
),[![][1]][1]
Remove parent Container height and set Column <mainAxisSize: MainAxisSize.min,>.
It is taking full height because of Container height and the default behavior of Column.
And to improve UI, use padding on Container<padding:x,child Column>
Container(
// height: 600,
decoration: const BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(60),
),
),
child: Padding(
padding: const EdgeInsets.only(top: 80.0, right: 50, left: 50),
child: Container(
padding: const EdgeInsets.all(40), //here padding
decoration: const BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.all(
Radius.circular(20),
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
TextFormField(
decoration: const InputDecoration(
border: UnderlineInputBorder(),
labelText: "Email or Phone Number"),
),
const SizedBox(
height: 20,
),
const TextField(
decoration: InputDecoration.collapsed(hintText: 'PassWord'),
),
],
),
),
),
),
Try below code hope its helpful to you. Just remove your container extra/large height
Container(
height: 180,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(
60,
),
),
),
child: Padding(
padding: const EdgeInsets.only(top: 80.0, right: 50, left: 50),
child: Container(
decoration: BoxDecoration(
color: Colors.red,
borderRadius: BorderRadius.all(
Radius.circular(20),
),
),
child: Column(
children: [
TextFormField(
decoration: const InputDecoration(
border: UnderlineInputBorder(),
labelText: "Email or Phone Number",
),
),
SizedBox(
height: 20,
),
TextField(
decoration: InputDecoration.collapsed(
hintText: 'PassWord',
),
)
],
),
),
),
),
Your result screen->

Bottom overflowed by 182 pixels

I am trying to add textfields in a widget on Flutter, and it renders correctly, but when the text is pressed to enter the data, appears the following error:
"Bottom overflowed by 182 pixels"
The error is when the default keyboard appears. I don't know why is it happening since i am wrapping everything in a SingleChildScrollView widget, therefore, should work just fine.
Attached the code:
class TextFieldsState extends State<TextFields> {
#override
Widget build(BuildContext context) {
const colorRed = Color(0xFFF0786E);
return SingleChildScrollView(
child: Container(
margin: EdgeInsets.symmetric(
horizontal: 20.0,
vertical: 20.0,
),
//color: Colors.greenAccent,
height: 500,
child: Stack(
//alignment: Alignment.bottomCenter,
children: <Widget>[
Container (
height: 500,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(22.0),
color: colorRed,
),
child: Container (
height: 500,
margin: EdgeInsets.only(right: 10,),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(22),
),
),
),
Center(
child: Positioned (
child: SizedBox(
height: 136,
//width: size.width,
child: Column(
children: <Widget>[
Container(
height: 30,
width: 160,
child: TextField(
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.blue,
),
borderRadius: BorderRadius.circular(10.0),
),
hintText: 'Name',
),
textAlign: TextAlign.center,
),
),
SizedBox(height: 20.0),
Container(
height: 30,
width: 160,
child: TextField(
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.blue,
),
borderRadius: BorderRadius.circular(10.0),
),
hintText: 'Surname',
),
textAlign: TextAlign.center,
),
),
SizedBox(height: 20.0),
Container(
height: 30,
width: 160,
child: TextField(
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.blue,
),
borderRadius: BorderRadius.circular(10.0),
),
hintText: 'Nationality',
),
textAlign: TextAlign.center,
),
),
],
),
),
),
),
],
),
),
);
}
}
What is the solution, please?
try this please
SingleChildScrollView(
column( // your column
)
)
overflow error is in column and you should add SingleChildScrollView as parent of this column.
Please check the edited below code.
class TextFieldsState extends State<TextFields> {
#override
Widget build(BuildContext context) {
const colorRed = Color(0xFFF0786E);
return Scaffold(
body: SingleChildScrollView(
child: Container(
margin: EdgeInsets.symmetric(
horizontal: 20.0,
vertical: 20.0,
),
//color: Colors.greenAccent,
height: 500,
child: Stack(
//alignment: Alignment.bottomCenter,
children: <Widget>[
Container(
height: 500,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(22.0),
color: colorRed,
),
child: Container(
height: 500,
margin: EdgeInsets.only(
right: 10,
),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(22),
),
),
),
Center(
child: SizedBox(
height: 136,
//width: size.width,
child: SingleChildScrollView(
child: Column(
children: <Widget>[
Container(
height: 30,
width: 160,
child: TextField(
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.blue,
),
borderRadius: BorderRadius.circular(10.0),
),
hintText: 'Name',
),
textAlign: TextAlign.center,
),
),
SizedBox(height: 20.0),
Container(
height: 30,
width: 160,
child: TextField(
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.blue,
),
borderRadius: BorderRadius.circular(10.0),
),
hintText: 'Surname',
),
textAlign: TextAlign.center,
),
),
SizedBox(height: 20.0),
Container(
height: 30,
width: 160,
child: TextField(
decoration: InputDecoration(
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.blue,
),
borderRadius: BorderRadius.circular(10.0),
),
hintText: 'Nationality',
),
textAlign: TextAlign.center,
),
),
],
),
),
),
),
],
),
),
),
);
}
}
I ended up wrapping everything with a Expanded widget and the column with the Text fields I wrapped it with a SingleChilsScrollView and it worked perfectly.

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

Flutter giving me massive migraine : "positional arguments must occur before named arguments"

Throws error # Scaffold saying too many positional arguments, and another # Padding saying positional arguments must occur before named arguments.
import 'package:flutter/material.dart';
void main() =>
runApp(MaterialApp
(debugShowCheckedModeBanner: false,
home: LoginScreen()
)
);
class LoginScreen extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
body: Container(
child: Column(
children: <Widget>[
Container(
height: 260,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/RightLogo.jpg"),
fit: BoxFit.fill))),
Positioned(
child: Container(
margin: EdgeInsets.only(top: 25),
child: Center(
child: Text(
"Login",
style: TextStyle(
color: Colors.blue,
fontSize: 30,
fontWeight: FontWeight.bold),
),
),
),
)
],
),
),
Padding(
padding: EdgeInsets.all(30.0),
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Color.fromRGBO(143, 148, 251, .8),
blurRadius: 20.0,
offset: Offset(0, 10)
)
]
),
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.all(8.0),
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey[100]))
),
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: "User Name/Login",
hintStyle: TextStyle(color: Colors.grey[400])
),
)
),
Container(
padding: EdgeInsets.all(8.0),
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Password",
hintStyle: TextStyle(color: Colors.grey[400])
),
)
)
],
),
),
SizedBox(height: 30,),
Container(
height: 50,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
gradient: LinearGradient(
colors: [
Color.fromRGBO(143, 148, 251, 1),
Color.fromRGBO(143, 148, 251, .6),
]
)
),
)
])
),
);
}
}
So what's the reason? I know its a mistake by me but I'd appreciate it if someone pointed out the flaw. Also the rest of the code is probably useless.
Edited after comment about missing code. Sorry for inconvenience.
That's because your padding is not inside of your column widget's children list. It is used as a positional argument to scaffold.
Simply ctrl + x your padding and paste it into column's children.
Column(
children: <Widget>[
Container(
height: 260,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/images/RightLogo.jpg"),
fit: BoxFit.fill))),
Positioned(
child: Container(
margin: EdgeInsets.only(top: 25),
child: Center(
child: Text(
"Login",
style: TextStyle(
color: Colors.blue,
fontSize: 30,
fontWeight: FontWeight.bold),
),
),
),
),
Padding(
padding: EdgeInsets.all(30.0),
child: Column(children: <Widget>[
Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(10),
boxShadow: [
BoxShadow(
color: Color.fromRGBO(143, 148, 251, .8),
blurRadius: 20.0,
offset: Offset(0, 10))
]),
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.all(8.0),
decoration: BoxDecoration(
border: Border(
bottom:
BorderSide(color: Colors.grey[100]))),
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: "User Name/Login",
hintStyle:
TextStyle(color: Colors.grey[400])),
)),
Container(
padding: EdgeInsets.all(8.0),
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: "Password",
hintStyle:
TextStyle(color: Colors.grey[400])),
))
],
),
),
SizedBox(
height: 30,
),
Container(
height: 50,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
gradient: LinearGradient(colors: [
Color.fromRGBO(143, 148, 251, 1),
Color.fromRGBO(143, 148, 251, .6),
])),
)
])),
],
),