I am working on my new app. While creating the login page, i faced some issue. My code works fine till a point and after that point or line, it stops building more widgets.
My code(working portion):
void main() => runApp(
MaterialApp(
debugShowCheckedModeBanner:false,
home: Background1(),
),
);
class Background1 extends StatelessWidget {
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold( //Whole screen
body: Container(
padding: EdgeInsets.all(20),
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
colors: [
Colors.purple.shade700,
Colors.purple.shade500,
Colors.purple.shade300,
],
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox (height: 80),
Padding(
padding: EdgeInsets.all(20),
child: Column(
children: <Widget>[
Text("LOGIN", style: TextStyle(color: Colors.white,fontSize: 40,fontWeight: FontWeight.bold)),
],
),
),
Expanded(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(topLeft: Radius.circular(20), topRight: Radius.circular(20),bottomLeft: Radius.circular(20),bottomRight: Radius.circular(20)),
color: Colors.transparent,
),
child: Padding(
padding: EdgeInsets.all(20),
child: Column(
children: <Widget>[
SizedBox(
height: 20,
),
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
boxShadow: [BoxShadow(
color: Color.fromRGBO(225, 95, 27, 0.3),
blurRadius: 20,
offset: Offset(0,10),
)],
),
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
border: Border(bottom: BorderSide(color: Colors.grey[200])),
),
child: TextField(
decoration: InputDecoration(
hintText: "Email or phone number",
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[200])),
),
child: TextField(
decoration: InputDecoration(
hintText: "Password",
hintStyle: TextStyle(color: Colors.grey),
border: InputBorder.none,
),
),
),
],
),
),
SizedBox(height: 40),
Text("Forgot Password?", style: TextStyle(color: Colors.white)),
SizedBox(height: 40),
Container(
height: 40,
margin: EdgeInsets.symmetric(horizontal: 50),
padding: EdgeInsets.all(20),
decoration: BoxDecoration(
color: Colors.purple.shade800,
borderRadius: BorderRadius.circular(20)),
child: Center(
child: Text("LOGIN", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
),
),
],
),
),
),
),
],
),
),
),
);
}
}
Couldn't able to create center() and Text() widget, which is at the end of the code.
child: Text("LOGIN", style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold)),
),
),
And also it doesn't build widgets as i write further. I've attached an image showing my emulator where it doesn't show LOGIN in white color on the purple button. enter image description here
just remove the padding of the container and it will work fine.
code after removing the container padding:
void main() => runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
home: Background1(),
),
);
class Background1 extends StatelessWidget {
#override
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
//Whole screen
body: Container(
padding: EdgeInsets.all(20),
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
colors: [
Colors.purple.shade700,
Colors.purple.shade500,
Colors.purple.shade300,
],
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(height: 80),
Padding(
padding: EdgeInsets.all(20),
child: Column(
children: <Widget>[
Text("LOGIN",
style: TextStyle(
color: Colors.white,
fontSize: 40,
fontWeight: FontWeight.bold)),
],
),
),
Expanded(
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(20),
topRight: Radius.circular(20),
bottomLeft: Radius.circular(20),
bottomRight: Radius.circular(20)),
color: Colors.transparent,
),
child: Padding(
padding: EdgeInsets.all(20),
child: Column(
children: <Widget>[
SizedBox(
height: 20,
),
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(20),
boxShadow: [
BoxShadow(
color: Color.fromRGBO(225, 95, 27, 0.3),
blurRadius: 20,
offset: Offset(0, 10),
)
],
),
child: Column(
children: <Widget>[
Container(
padding: EdgeInsets.all(10),
decoration: BoxDecoration(
border: Border(
bottom:
BorderSide(color: Colors.grey[200])),
),
child: TextField(
decoration: InputDecoration(
hintText: "Email or phone number",
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[200])),
),
child: TextField(
decoration: InputDecoration(
hintText: "Password",
hintStyle: TextStyle(color: Colors.grey),
border: InputBorder.none,
),
),
),
],
),
),
SizedBox(height: 40),
Text("Forgot Password?",
style: TextStyle(color: Colors.white)),
SizedBox(height: 40),
Container(
height: 40,
margin: EdgeInsets.symmetric(horizontal: 50),
decoration: BoxDecoration(
color: Colors.purple.shade800,
borderRadius: BorderRadius.circular(20)),
child: Center(
child: Text("LOGIN",
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold)),
),
),
],
),
),
),
),
],
),
),
),
);
}
}
You might be using all of the space on the screen, rather then using a column use a listview, this will allow you to scroll. Additionally Listview.builder will allow you to build the children of the list view dynamically.
checkout https://api.flutter.dev/flutter/widgets/ListView-class.html for info on the listview class
Related
I am trying to create an simple login form, there are 3 components in a column: row and 2 text fields.
The row contains an image and text.
The problem is whenever the keyboard appears while I want to type something in the textfield, all UI is shrinking.
I have attached before and after keyboard appears
How to make it such that whenever keyboard appears the elements hidden below the keyboard?
Here is my code:
Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Flexible(
fit: FlexFit.tight,
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Flexible(
child: Padding(
padding: EdgeInsets.only(top: 50),
child: Hero(
tag: "logo",
child: Image.asset(
"images/flash.png", width: 70, height: 50,)
),
),
),
Flexible(
child: Padding(
padding: EdgeInsets.only(top: 50),
child: Text(
"Demo Chat",
style: TextStyle(
fontSize: 40,
color: Colors.black,
fontWeight: FontWeight.bold
),
),
),
)
],
),
),
Flexible(
fit: FlexFit.tight,
child: SizedBox(
height: 50,
),
),
Flexible(
fit: FlexFit.tight,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: TextField(
decoration: kTextFieldDecorationEmail,
keyboardType: TextInputType.emailAddress,
),
),
),
Flexible(
fit: FlexFit.tight,
child: SizedBox(
height: 50,
),
),
Flexible(
fit: FlexFit.tight,
child: Padding(
padding: const EdgeInsets.all(16.0),
child: TextField(
decoration: kTextFieldDecorationPassword,
keyboardType: TextInputType.visiblePassword,
obscureText: true,
),
),
),
Flexible(
fit: FlexFit.tight,
child: SizedBox(
height: 70,
),
),
Flexible(
fit: FlexFit.tight,
child: Padding(
padding: EdgeInsets.all(20),
child: MaterialButton(
color: Colors.blueAccent,
onPressed: (){},
height: 50,
child: Text(
"Login",
style: TextStyle(
color: Colors.black
),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)
),
),
),
)
],
),
That is because you are using flexible with FlexFit.tight, this allows it to fit into screen regardless of the size. I would suggest you to use MediaQuery or some other field for this to tackle. An example to eliminate this would be something like this. I have edited your code a slight bit since I do not have the image and decoration at the moment which you are using I have put in some random one for the time being.
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Scaffold(
body: SafeArea(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Padding(
padding: EdgeInsets.only(top: 50),
child: Text(
"Demo Chat",
style: TextStyle(
fontSize: 40,
color: Colors.black,
fontWeight: FontWeight.bold),
),
)
],
),
SizedBox(
height: 50,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Username',
filled: true,
fillColor: Colors.grey,
contentPadding:
const EdgeInsets.only(left: 14.0, bottom: 6.0, top: 8.0),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red),
borderRadius: BorderRadius.circular(10.0),
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey),
borderRadius: BorderRadius.circular(10.0),
),
),
keyboardType: TextInputType.emailAddress,
),
),
SizedBox(
height: 50,
),
Padding(
padding: const EdgeInsets.all(16.0),
child: TextField(
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Password',
filled: true,
fillColor: Colors.grey,
contentPadding:
const EdgeInsets.only(left: 14.0, bottom: 6.0, top: 8.0),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red),
borderRadius: BorderRadius.circular(10.0),
),
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.grey),
borderRadius: BorderRadius.circular(10.0),
),
),
keyboardType: TextInputType.visiblePassword,
obscureText: true,
),
),
Flexible(
fit: FlexFit.tight,
child: SizedBox(
height: 70,
),
),
Padding(
padding: EdgeInsets.all(20),
child: MaterialButton(
color: Colors.blueAccent,
onPressed: () {},
height: 50,
child: Text(
"Login",
style: TextStyle(color: Colors.black),
),
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20)),
),
)
],
),
),
);
}
}
Screen:
I have made a Login Screen, the problem is I am getting a black stripe at the end of my screen, while in my code I have'nt added any color at the end, moreover I thought that this might because of sizebox, but even if I remove it, nothing really happens. Moreover at first when I was creating and debugging this code, there was no such line and once everything is done, it started appearing at the bottom..
Here's the output picture:
Here's my UI code:
Widget build(BuildContext context) {
return SafeArea(
child: Scaffold(
body: SingleChildScrollView(
child: Container(
padding: EdgeInsets.symmetric(vertical: 40),
width: double.infinity,
decoration: BoxDecoration(
gradient: LinearGradient(begin: Alignment.topCenter, colors: [
Colors.black,
Colors.black87,
Color(0xff0a0b0d),
])),
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,fontFamily: 'Signatra'),
),
SizedBox(
height: 10,
),
Text(
"Welcome to T Post",
style: TextStyle(color: Colors.white, fontSize: 30, fontFamily: 'Signatra'),
),
],
),
),
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: Color(0xff0a0b0d),
),
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,
),
],
)
],
),
),
)
],
),
),
),
),
);
}
It looks like you have containers wrapping their content, so it appears like a stripe. Try having one of the containers filling the screen instead of wrapping the content. What happens when you make the following change to the SingleChildScrollView?
Container(
padding: EdgeInsets.symmetric(vertical: 40),
width: double.infinity,
height: MediaQuery.of(context).size.height, // <<<<<< Add this line.
decoration: BoxDecoration(
gradient: LinearGradient(begin: Alignment.topCenter, colors: [
Colors.black,
Colors.black87,
Color(0xff0a0b0d),
]))
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,
),
],
)
],
),
),
)
],
),
),
),
);
}
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)),
),
),
],
),
),
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),
])),
)
])),
],
),