Related
I am new to using flutter. I want to ask. How to change the spacing between textformfield? I have done the same as textformfield address, Postcode and District for textformfield firstname, last name, and relationship but still not successful. I have changed the container margin and padding and used spacing wrap for textformfield firstname, last name and relationship but still not successful. Where is my coding error? Please, someone, help me in solving this problem.
This is my code:
Container(
width: double.infinity,
//margin: EdgeInsets.symmetric(vertical: 50),
margin: EdgeInsets.symmetric(
horizontal: 10, vertical: 40),
padding: EdgeInsets.symmetric(horizontal: 210),
decoration: BoxDecoration(
border: Border.all(
color: Colors.transparent,
width: 1.0,
),
borderRadius: BorderRadius.circular(5)),
/*decoration: BoxDecoration(
border: Border(
/* top: BorderSide(
color: Colors.blue,
width: 2.0,
),*/
bottom: BorderSide(
color: Colors.blue, width: 2.0))),*/
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
height: 30,
child: Text(
'Next of kin 1',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.bold),
),
),
Container(
//height: 51,
//width: 30,
width: double.infinity,
//margin: EdgeInsets.symmetric(horizontal: 10),
/*padding: EdgeInsets.symmetric(horizontal: 5),*/
decoration: BoxDecoration(
border: Border.all(
color: Colors.transparent,
width: 1.0,
),
borderRadius: BorderRadius.circular(5)),
child: Row(
children: [
Expanded(
child: Wrap(
direction: Axis.horizontal,
alignment: WrapAlignment.start,
//spacing: 20.0,
children: [
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisAlignment:
MainAxisAlignment.start,
children: [
SizedBox(
height: 30,
child: Text(
'First Name',
style: TextStyle(
fontWeight:
FontWeight.bold,
fontSize: 16),
),
),
SizedBox(
width: 300,
//height: 100,
child: TextFormField(
style: const TextStyle(
color: Colors.black),
controller:
nextOfKinFirstName,
onSaved: (String? value) {
nextOfKinFirstName.text =
value!;
},
decoration:
const InputDecoration(
border:
OutlineInputBorder(),
hintText: 'First Name',
hintStyle: TextStyle(
color: Colors.black,
fontSize: 16),
),
),
),
],
)
],
),
),
Expanded(
child: Wrap(
children: [
Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
SizedBox(
height: 30,
child: Text(
'Last Name',
style: TextStyle(
fontWeight:
FontWeight.bold,
fontSize: 16),
),
),
SizedBox(
width: 300,
//height: 100,
child: TextFormField(
style: const TextStyle(
color: Colors.black),
controller: nextOfKinLastName,
onSaved: (String? value) {
nextOfKinLastName.text =
value!;
},
decoration:
const InputDecoration(
border:
OutlineInputBorder(),
hintText: 'Last Name',
hintStyle: TextStyle(
color: Colors.black,
fontSize: 16),
),
),
),
],
),
],
)),
Expanded(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
SizedBox(
height: 30,
child: Text(
'Relationship',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 16),
),
),
Container(
height: 51,
padding: EdgeInsets.symmetric(
horizontal: 10, vertical: 5),
decoration: BoxDecoration(
border: Border.all(
color: Colors.black12,
width: 1.0,
),
borderRadius:
BorderRadius.circular(5)),
child: SizedBox(
width: 300,
child: DropdownButton<String>(
underline: Container(
color:
Colors.transparent),
hint: _nextOfKinRelationship ==
null
? Text('Relationship')
: Text(
_nextOfKinRelationship),
isExpanded: true,
value:
_nextOfKinRelationship,
items: <String>[
'Father',
'Mother',
'Husband',
'Wife',
'Son',
'Daughter',
'Brother',
'Sister',
'Grandfather',
'Grandmother',
'Grandson',
'Grandaughter',
'Uncle',
'Aunt',
'Cousin',
'Nephew',
'Neice',
'Father in law',
'Mother in law',
'Son in law',
'Daughter in law',
'Brother in law',
'Sister in law',
'Friend'
].map((String value) {
return new DropdownMenuItem<
String>(
value: value,
child: new Text(value),
);
}).toList(),
onChanged: (value) {
setState(() {
_nextOfKinRelationship =
value!;
});
},
)),
),
],
),
)
],
))
],
),
),
you use Row to cover 3 TextField and wrap it with expanded, the space that available will be devide into 3.
but for the TextField you wrap it with certain width (SizedBox). and i think current screen is wider than all children inside Row
my suggestion is change it with Container which is fit available space.
Row(
children: [
// option 1
Expanded(
child: Column(
children: [
Text("label"),
TextField(), // without sizebox ,
],
),
),
//option 2
Expanded(
child: Column(
children: [
Text("label"),
Container(
width: double.infinity, // push to maximum space available
child: TextField(),
) // use container insted if you want to make decoration ,
],
),
),
],
);
I want to insert background image in one row in flutter
when I insert background image does not take up the entire row, only is displayed in one container
you can see this issue below image (I insert black background image for to be seen better):
Widget getBody() {
var size = MediaQuery.of(context).size;
return Container(
width: size.width,
height: size.height,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10)),
color: Colors.red),
child: SingleChildScrollView(
child: Column(
children: [
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Container(
height: 1,
decoration:
BoxDecoration(color: Colors.grey.withOpacity(0.2)),
),
),
SizedBox(
width: 10,
),
Text(
"درصد تخفیف برای 30 عدد",
style: TextStyle(color: Colors.black54),
),
SizedBox(
width: 10,
),
Flexible(
child: Container(
height: 1,
decoration:
BoxDecoration(color: Colors.grey.withOpacity(0.2)),
),
),
],
),
SizedBox(
height: 15,
),
Column(
children: List.generate(nardeban_data.length, (index) {
return Column(
children: [
Padding(
padding: const EdgeInsets.only(right: 20, left: 20),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage("assets/images/bg.png"),
fit: BoxFit.cover,
),
),
width: (size.width - 40) * 0.68,
child: Row(
children: [
Container(
width: 40,
decoration: BoxDecoration(
color: Colors.blue,
border: Border.all(color: Colors.blue),
borderRadius:
BorderRadius.circular(40.0)),
child: Padding(
padding: EdgeInsets.all(10.0),
child: Text("14",
style: TextStyle(
fontSize: 13.0,
fontWeight: FontWeight.bold,
color: Colors.white)))),
SizedBox(
width: 10,
),
Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
nardeban_data[index]['name'],
style: TextStyle(
fontSize: 14,
color: Colors.black54,
fontWeight: FontWeight.w400),
overflow: TextOverflow.ellipsis,
),
Text(
nardeban_data[index]['takhfif'],
style: TextStyle(
fontSize: 12,
color: Colors.blue,
),
overflow: TextOverflow.ellipsis,
),
],
),
)
],
),
),
Container(
width: (size.width - 90) * 0.32,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(color: Colors.green)),
child: Padding(
padding: const EdgeInsets.only(
right: 10, bottom: 4, left: 10, top: 4),
child: Row(
children: [
SizedBox(
width: 25,
height: 25,
child: TextField(
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: '4%',
border: InputBorder.none,
contentPadding: EdgeInsets.only(
bottom: 8,
top: 3,
),
),
),
)
],
),
),
),
Icon(
Icons.notifications,
size: 22,
color: Colors.blue.withOpacity(0.7),
)
],
),
)
],
),
),
SizedBox(
height: 5,
),
Divider()
],
);
})),
],
),
),
);
}
wrap Row with Container and add decoration in container
like this:
Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage("assets/images/bg.png"),
fit: BoxFit.cover,
),),
child: Row(
........
)
Full code:
Widget getBody() {
var size = MediaQuery.of(context).size;
return Container(
width: size.width,
height: size.height,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
bottomLeft: Radius.circular(10),
bottomRight: Radius.circular(10)),
color: Colors.red),
child: SingleChildScrollView(
child: Column(
children: [
SizedBox(
height: 10,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Flexible(
child: Container(
height: 1,
decoration:
BoxDecoration(color: Colors.grey.withOpacity(0.2)),
),
),
SizedBox(
width: 10,
),
Text(
"درصد تخفیف برای 30 عدد",
style: TextStyle(color: Colors.black54),
),
SizedBox(
width: 10,
),
Flexible(
child: Container(
height: 1,
decoration:
BoxDecoration(color: Colors.grey.withOpacity(0.2)),
),
),
],
),
SizedBox(
height: 15,
),
Column(
children: List.generate(5, (index) {
return Column(
children: [
Padding(
padding: const EdgeInsets.only(right: 20, left: 20),
child: Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage("assets/images/bg.png"),
fit: BoxFit.cover,
),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
width: (size.width - 40) * 0.68,
child: Row(
children: [
Container(
width: 40,
decoration: BoxDecoration(
color: Colors.blue,
border: Border.all(color: Colors.blue),
borderRadius:
BorderRadius.circular(40.0)),
child: Padding(
padding: EdgeInsets.all(10.0),
child: Text("14",
style: TextStyle(
fontSize: 13.0,
fontWeight: FontWeight.bold,
color: Colors.white)))),
SizedBox(
width: 10,
),
Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
"Name",
style: TextStyle(
fontSize: 14,
color: Colors.black54,
fontWeight: FontWeight.w400),
overflow: TextOverflow.ellipsis,
),
Text(
' nardeban_data',
style: TextStyle(
fontSize: 12,
color: Colors.blue,
),
overflow: TextOverflow.ellipsis,
),
],
),
)
],
),
),
Container(
width: (size.width - 90) * 0.32,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(10),
border: Border.all(color: Colors.green)),
child: Padding(
padding: const EdgeInsets.only(
right: 10, bottom: 4, left: 10, top: 4),
child: Row(
children: [
SizedBox(
width: 25,
height: 25,
child: TextField(
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
decoration: InputDecoration(
hintText: '4%',
border: InputBorder.none,
contentPadding: EdgeInsets.only(
bottom: 8,
top: 3,
),
),
),
)
],
),
),
),
Icon(
Icons.notifications,
size: 22,
color: Colors.blue.withOpacity(0.7),
)
],
),
)
],
),)
),
SizedBox(
height: 5,
),
Divider()
],
);
})),
],
),
),
);
}
Add this code
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage("filename")// or networkImage() or anything,
),),
to the row's container
Container(
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(5.0),
bottomLeft: Radius.circular(5.0)
),
color: Colors.white,
),
padding: EdgeInsets.only(left: 15.w, right: 15.w),
child: TextField(
maxLines: 1,
style: TextStyle(
fontSize: 12, //This line!!!!!!!!!
textBaseline: TextBaseline.alphabetic,
),
decoration: InputDecoration(
border: InputBorder.none,
hintText: configNotifier.translationObject["SearchOrder"],
hintStyle: TextStyle(
color: fromCSSColor("#808080"),
textBaseline: TextBaseline.alphabetic
),
),
),
)
Before I add "fontSize: 12"
After I add "fontSize: 12"
How to apply font size to textfield with vertical center alignment?
Remark: I've tried "textAlignVertical: TextAlignVertical.center" and hint->textstyle "height:1.0" which is not working
========Edit 1===========
IOS Device is work fine but not on Samsung Galaxy Tab A (8.0", 2019) which model is SM-T295C).
========Edit 2===========
With Parent Widget
Container(
margin: EdgeInsets.only(left: 70, right: 70),
height: 50.h,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(5.0),
bottomLeft: Radius.circular(5.0)
),
color: Colors.white,
),
padding: EdgeInsets.only(left: 15.w, right: 15.w),
child: TextField(
maxLines: 1,
style: TextStyle(
fontSize: 12, //This line!!!!!!!!!
textBaseline: TextBaseline.alphabetic,
),
decoration: InputDecoration(
border: InputBorder.none,
hintText: configNotifier.translationObject["SearchOrder"],
hintStyle: TextStyle(
color: fromCSSColor("#808080"),
textBaseline: TextBaseline.alphabetic
),
),
),
),
),
GestureDetector(
onTap: (){
//...
},
child: Container(
width: 100.w,
height: 50.h,
margin: EdgeInsets.only(right: 10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.0),
color: fromCSSColor("#000000"),
),
child: Center(
child: Text(
"Submit",
style: TextStyle(
color: fromCSSColor("#000000"),
fontSize: 12
),
textAlign: TextAlign.center,
),
)
)
),
GestureDetector(
onTap: (){
//...
},
child: Container(
width: 65.w,
height: 50.h,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.0),
color: fromCSSColor("#000000"),
),
child: Center(
child: Container(
width: 41.w,
height: 41.h,
alignment: Alignment.center,
child: Image.asset('assets/images/icon_scan_white.png', fit: BoxFit.contain),
),
),
)
)
],
)
)
Try to textalign.center in TextField like below
TextField(
textAlign : TextAlign.center,
),
your screen look like this-
try contentPadding inside decoration. and dont need to use padding on Expanded Container.
import 'package:flutter/material.dart';
class CounterList extends StatefulWidget {
#override
_CounterListState createState() => _CounterListState();
}
class _CounterListState extends State<CounterList> {
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.red,
body: Padding(
padding: const EdgeInsets.all(8.0),
child: ListView(
children: [
CustomField(
fontSize: 17,
),
SizedBox(
height: 22,
),
CustomField(
fontSize: 37,
),
SizedBox(
height: 20,
),
CustomField(
fontSize: 11,
),
SizedBox(
height: 20,
),
CustomField(
fontSize: 22,
),
],
),
));
}
}
class CustomField extends StatelessWidget {
final double fontSize;
CustomField({
Key? key,
required this.fontSize,
}) : super(key: key);
#override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.only(left: 70, right: 70),
height: 50,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Container(
alignment: Alignment.center,
decoration: BoxDecoration(
borderRadius: BorderRadius.only(
topLeft: Radius.circular(5.0),
bottomLeft: Radius.circular(5.0)),
color: Colors.white,
),
// padding: EdgeInsets.only(left: 15.w, right: 15.w),
child: TextField(
maxLines: 1,
style: TextStyle(
fontSize: fontSize, //This line!!!!!!!!!
textBaseline: TextBaseline.alphabetic,
),
decoration: InputDecoration(
contentPadding: EdgeInsets.only(left: 15, right: 15),
border: InputBorder.none,
hintText: "search",
// hintText: configNotifier.translationObject["SearchOrder"],
hintStyle: TextStyle(
// color: fromCSSColor("#808080"),
color: Colors.grey,
textBaseline: TextBaseline.alphabetic,
),
),
),
),
),
GestureDetector(
onTap: () {
//...
},
child: Container(
width: 100,
height: 50,
margin: EdgeInsets.only(right: 10),
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.0),
// color: fromCSSColor("#000000"),
color: Colors.black,
),
child: Center(
child: Text(
"Submit",
style: TextStyle(
// color: fromCSSColor("#000000"),
color: Colors.black,
fontSize: 12,
),
textAlign: TextAlign.center,
),
))),
GestureDetector(
onTap: () {
//...
},
child: Container(
width: 65,
height: 50,
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(5.0),
// color: fromCSSColor("#000000"),
color: Colors.black,
),
child: Center(
child: Container(
width: 41,
height: 41,
alignment: Alignment.center,
child: Image.asset(
// 'assets/images/icon_scan_white.png',
"assets/me.jpg",
fit: BoxFit.contain,
),
),
),
))
],
));
}
}
Try it:
TextField(
textAlign : TextAlign.center,
textAlignVertical: TextAlignVertical.center,
),
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 use standard tabs after a few of my blocks. The content in the tabs is styled using a container. The main parent element is Column in which I build all my blocks. I have tried various options using Expanded.
The error sometimes changes to "RenderFlex children have non-zero flex but incoming height constraints are unbounded." This only happens when i try to add tabs, any other block is displayed correctly in my main Column.
body: SafeArea(
child: SingleChildScrollView(
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/background.png"),
fit: BoxFit.fill,
),
),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: < Widget > [
SizedBox(height: 20),
Container(
margin: EdgeInsets.symmetric(horizontal: 15),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(32),
),
child: TextField(
decoration: InputDecoration(
hintStyle: TextStyle(fontSize: 14),
hintText: 'Найти услугу...',
suffixIcon: Icon(Icons.search),
border: InputBorder.none,
contentPadding:
EdgeInsets.symmetric(horizontal: 20, vertical: 15),
),
),
),
SizedBox(height: 20),
Container(
height: 450,
padding: EdgeInsets.only(top: 35),
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage("assets/ps-bg.png"),
fit: BoxFit.cover,
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: < Widget > [
SvgPicture.asset(
'assets/ps-logo.svg',
),
Container(
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height * 0.35,
decoration: BoxDecoration(
gradient: LinearGradient(
begin: Alignment.topCenter,
end: Alignment.bottomCenter,
colors: [
Color.fromRGBO(6, 85, 152, 0),
Color(0xFF084A82),
],
)
),
child: CarouselSlider(
options: CarouselOptions(
autoPlay: false,
aspectRatio: 16 / 10,
enlargeCenterPage: true,
viewportFraction: 0.6,
),
items: imgList.map((item) => LayoutBuilder(builder: (context, constraints) {
return ClipRRect(
borderRadius: BorderRadius.all(
Radius.circular(20.0),
),
child: Stack(
children: < Widget > [
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(20.0),
),
),
child: Column(
mainAxisSize: MainAxisSize.min,
children: < Widget > [
Image.asset(
'assets/psplus-1month.png',
fit: BoxFit.cover,
width: constraints.maxWidth,
height: constraints.maxHeight / 2,
),
SizedBox(height: 23),
Text(
'Playstation Plus',
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(0xFF4F4F4F),
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 5),
Text(
'1 месяц',
style: TextStyle(
color: const Color(0xFFA5ABC8),
fontSize: 12,
),
),
SizedBox(height: 5),
Text(
'1 500 рублей',
style: TextStyle(
color: const Color(0xFF789EEB),
fontSize: 16,
fontWeight: FontWeight.w600,
),
),
SizedBox(height: 5),
],
),
),
Positioned(
bottom: constraints.maxHeight / 2 - 18,
left: 0.0,
right: 0.0,
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: < Widget > [
Container(
decoration: BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
boxShadow: [
BoxShadow(
blurRadius: 7,
color: Colors.black.withOpacity(0.10),
spreadRadius: 2)
],
),
child: CircleAvatar(
backgroundColor: Colors.white,
radius: 18,
child: Icon(Icons.add),
),
)
],
),
),
],
),
);
}, ), ).toList()
)
),
]
),
),
SizedBox(height: 20),
DefaultTabController(
length: 3,
child: Column(
children: [
Container(
margin: EdgeInsets.symmetric(horizontal: 15.0),
child: TabBar(
indicator: BoxDecoration(
borderRadius: BorderRadius.circular(50), // Creates border
color: const Color(0xFF62A6E9)
),
labelColor: Colors.white,
unselectedLabelColor: Colors.grey,
labelStyle: TextStyle(fontSize: 13.0),
tabs: [
Tab(text: 'Инструкция'),
Tab(text: 'Оплаты'),
Tab(text: 'Информация'),
],
),
),
TabBarView(
children: [
Container(
margin: EdgeInsets.all(15.0),
padding: EdgeInsets.all(20.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(30))
),
child: Text(
'Text',
textAlign: TextAlign.left,
style: TextStyle(
color: const Color(0xFF4F4F4F),
height: 1.5,
fontSize: 15,
fontFamily: 'Montserrat',
fontWeight: FontWeight.w500,
),
),
),
Container(
margin: EdgeInsets.all(15.0),
padding: EdgeInsets.all(20.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(30))
),
child: Text(
'Text',
textAlign: TextAlign.left,
style: TextStyle(
color: const Color(0xFF4F4F4F),
height: 1.5,
fontSize: 15,
fontFamily: 'Montserrat',
fontWeight: FontWeight.w500,
),
),
),
Container(
margin: EdgeInsets.all(15.0),
padding: EdgeInsets.all(20.0),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(Radius.circular(30))
),
child: Text(
'Text',
textAlign: TextAlign.left,
style: TextStyle(
color: const Color(0xFF4F4F4F),
height: 1.5,
fontSize: 15,
fontFamily: 'Montserrat',
fontWeight: FontWeight.w500,
),
),
),
],
),
]
)
),
GridView.count(
crossAxisCount: 2,
shrinkWrap: true,
physics: ScrollPhysics(),
scrollDirection: Axis.vertical,
children: List.generate(10, (index) {
return Container(
child: Container(
margin: EdgeInsets.all(15.0),
child: ClipRRect(
borderRadius: BorderRadius.all(Radius.circular(30.0)),
child: Stack(
children: < Widget > [
Image.network(
'https://images.unsplash.com/photo-1519125323398-675f0ddb6308?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=94a1e718d89ca60a6337a6008341ca50&auto=format&fit=crop&w=1950&q=80',
fit: BoxFit.cover,
width: 1000.0),
Positioned(
bottom: 0.0,
left: 0.0,
right: 0.0,
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: < Widget > [
Container(
decoration:
BoxDecoration(color: Colors.white),
padding: EdgeInsets.only(
top: 15.0,
bottom: 15.0
),
child: Text(
'PUBG',
textAlign: TextAlign.center,
style: TextStyle(
color: const Color(0xFF4F4F4F),
fontSize: 16,
fontWeight: FontWeight.bold,
),
),
),
],
),
),
Positioned(
bottom: 40.0,
left: 0.0,
right: 0.0,
child: Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment:
CrossAxisAlignment.stretch,
children: < Widget > [
CircleAvatar(
backgroundColor: Colors.white,
radius: 15,
child: Icon(Icons.add),
),
],
),
),
],
)),
),
);
}),
),
]
)
)
))
Ok i found solution, TabBarView need height, Expanded not help.
Container(
height: MediaQuery.of(context).size.height,
child: TabBarView(
children: [
Icon(Icons.directions_car),
Icon(Icons.directions_car),
Icon(Icons.directions_car)
],
),
)
Wrap in LayoutBuilder:
LayoutBuilder(
builder: (_, BoxConstraints viewportConstraints) {
return SingleChildScrollView(
child: ConstrainedBox(
constraints: BoxConstraints(
minHeight: viewportConstraints.maxHeight,
),
child: Column(),
);
},
),