Bottom Overflowed using SingleChildScrollView - flutter

#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Color(0xff003859),
appBar: AppBar(
title: Text(
"Conversor de moedas 360",
style: TextStyle(
color: Color(0xff003859)
)
),
backgroundColor: Color(0xffffa300),
),
body: FutureBuilder<Map>(
future: getData(),
builder: (context, snapshot) {
switch(snapshot.connectionState){
case ConnectionState.none:
case ConnectionState.waiting:
return Center(
child: Text(
"Carregando Dados...",
style: TextStyle(
color: Color(0xffffa300),
fontSize: 25.0
),
textAlign: TextAlign.center,
)
);
default:
if (snapshot.hasError){
return Center(
child: Text(
"Erro ao carregar dados...",
style: TextStyle(
color: Color(0xffffa300),
fontSize: 25.0
),
textAlign: TextAlign.center,
)
);
} else {
dolar = snapshot.data["results"]["currencies"]["USD"]["buy"];
euro = snapshot.data["results"]["currencies"]["EUR"]["buy"];
return Column(
children: <Widget>[
Image.asset(
"images/360Tecnologia.jpg",
fit: BoxFit.fitWidth,
),
SingleChildScrollView(
padding: EdgeInsets.all(10.0),
child: Column(
children: <Widget>[
TextField(
decoration: InputDecoration(
labelText: "Reais",
labelStyle: TextStyle(
color: Color(0xffffa300),
),
border: OutlineInputBorder(),
prefixText: "R\$ "
),
style: TextStyle(
color: Color(0xffffa300),
fontSize: 25.0
)
),
Divider(),
TextField(
decoration: InputDecoration(
labelText: "Dólares",
labelStyle: TextStyle(
color: Color(0xffffa300),
),
border: OutlineInputBorder(),
prefixText: "U\$ "
),
style: TextStyle(
color: Color(0xffffa300),
fontSize: 25.0
)
),
Divider(),
TextField(
decoration: InputDecoration(
labelText: "Euros",
labelStyle: TextStyle(
color: Color(0xffffa300),
),
border: OutlineInputBorder(),
prefixText: "€ "
),
style: TextStyle(
color: Color(0xffffa300),
fontSize: 25.0
)
),
Divider(),
TextField(
decoration: InputDecoration(
labelText: "Libra",
labelStyle: TextStyle(
color: Color(0xffffa300),
),
border: OutlineInputBorder(),
prefixText: "£\$ "
),
style: TextStyle(
color: Color(0xffffa300),
fontSize: 25.0
)
),
Divider(),
TextField(
decoration: InputDecoration(
labelText: "Bitcoin",
labelStyle: TextStyle(
color: Color(0xffffa300),
),
border: OutlineInputBorder(),
prefixText: "BTC "
),
style: TextStyle(
color: Color(0xffffa300),
fontSize: 25.0
)
),
Divider(),
TextField(
decoration: InputDecoration(
labelText: "Bitcoin",
labelStyle: TextStyle(
color: Color(0xffffa300),
),
border: OutlineInputBorder(),
prefixText: "BTC "
),
style: TextStyle(
color: Color(0xffffa300),
fontSize: 25.0
)
),
],
)
)
],
);
}
}
}
)
);
}
}
I want to show an image on top below the top bar. The image is fixed.
Below the top bar I have any text field inside the SingleChildScrollView widget, but this not work when I try to scroll the elements.
The text field can't rolling when I roll the screen to up or to down.
The stackoverflow want I type more text because I put many code, but my doubt is explained on text up...
Any help?

To address the singleChildScrollView issue, you can wrap that in an Expanded widget and that will solve that problem. Though, you may want to look into using a SliverList for what you're doing if you want the image to be up top and fixed in the app bar.

Column(
children: <Widget>[
replace that with:
Stack(
children: <Widget>[
You are seeing that error because your SingleChildScrollView is inside a Column.
Another solution is to wrap your Parent Column with SingleChildScrollView instead of second one. But that will scroll your image too.
Or, if your image is a fixed one, you can add that to AppBar bottom:
AppBar(
//...
bottom: PreferredSize(
preferredSize: Size.fromHeight(129.0),
child: Image.asset(
"images/360Tecnologia.jpg",
fit: BoxFit.fitWidth,
),
),
),
Of course in this case if your snapshot.hasError or when connection is waiting, you will see this image(You can have a condition like isDataAvailable and make it true when connection state done and check it in bottom).
Another way is wrap parent Column with another SingleChildScrollView but that will make two scroll views. So to avoid image (Outher scroll view) to not to scroll add scrollPysics: NeverScrollPhysics()(But I dont recommend unnecessary wrap with extra widget).

Related

text align : center in a textfield in flutter

I want to make the text be written at the center of the container but it keeps being at the bottom.
Container(
width: 250.yswx,
padding: EdgeInsets.symmetric(horizontal: 5.yswx),
child: Center(
child: TextField(
textAlignVertical: TextAlignVertical.center,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.black,
fontSize: 13.yswx
),
cursorColor: Colors.black,
decoration: InputDecoration(
border: InputBorder.none,
hintText: widget.placeHolder,
hintStyle: TextStyle(
color: Color(0xffbfbfbf),
fontSize: 13.yswx
)
),
),
),
);
the result:
Hope this helps:
TextField(
textAlign: TextAlign.center,
decoration: InputDecoration(
hintText: "Testing Centered",
),

Width of my ElevatedButton is not reducing

The Width of the Elevated Button is not reducing, it is coming in taking all the width on the screen.The parent widget is ListView.I have even tried to reduce it through ButtomTheme but still it is not working. I have added the code below. Everywhere I have seen the way to reduce the width is this way.But don't know why it is not reducing the width
ListView(
children: [
Row(
children: [
RotatedBox(
quarterTurns: 3,
child: Padding(
padding: const EdgeInsets.only(right: 30.0),
child: Text(
'Sign Up',
style: TextStyle(
color: Colors.white,
fontSize: 50,
fontFamily: 'Pacifico'),
),
),
),
SizedBox(
width: 20,
),
Text(
'BRUXTER',
style: TextStyle(
fontSize: 30,
fontFamily: 'RockSalt',
color: Colors.black,
fontWeight: FontWeight.bold),
)
],
),
SizedBox(
height: 50,
),
Form(
child: Column(
children: [
TextFormField(
style: TextStyle(color: Colors.black, fontSize: 30),
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Enter Your Name',
hintStyle: TextStyle(color: Colors.white60),
),
),
TextFormField(
style: TextStyle(color: Colors.black, fontSize: 30),
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Enter Your Email',
hintStyle: TextStyle(color: Colors.white60),
),
),
TextFormField(
style: TextStyle(color: Colors.black, fontSize: 30),
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Enter Your PassWord',
hintStyle: TextStyle(color: Colors.white60),
),
),
],
),
),
SizedBox(
height: 20,
),
Container(
width: MediaQuery.of(context).size.width *
0.5, // Will take 50% of screen space
child: ElevatedButton(
child: Text('Go to screen two'),
onPressed: () {},
),
)
],
You need to replace your ListView with Column
Column(
children: [
Row(
children: [
RotatedBox(
quarterTurns: 3,
child: Padding(
padding: const EdgeInsets.only(right: 30.0),
child: Text(
'Sign Up',
style: TextStyle(
color: Colors.white,
fontSize: 50,
fontFamily: 'Pacifico'),
),
),
),
SizedBox(
width: 20,
),
Text(
'BRUXTER',
style: TextStyle(
fontSize: 30,
fontFamily: 'RockSalt',
color: Colors.black,
fontWeight: FontWeight.bold),
)
],
),
SizedBox(
height: 50,
),
Form(
child: Column(
children: [
TextFormField(
style: TextStyle(color: Colors.black, fontSize: 30),
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Enter Your Name',
hintStyle: TextStyle(color: Colors.white60),
),
),
TextFormField(
style: TextStyle(color: Colors.black, fontSize: 30),
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Enter Your Email',
hintStyle: TextStyle(color: Colors.white60),
),
),
TextFormField(
style: TextStyle(color: Colors.black, fontSize: 30),
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Enter Your PassWord',
hintStyle: TextStyle(color: Colors.white60),
),
),
],
),
),
SizedBox(
height: 20,
),
Container(
width: MediaQuery.of(context).size.width *
0.5, // Will take 50% of screen space
child: ElevatedButton(
child: Text('Go to screen two'),
onPressed: () {},
),
)
],
)
Please refer to below code
Replace width with margin in Container widget
Container(
// Replace width with margin
margin: EdgeInsets.symmetric(horizontal: 80.0,),
// width: MediaQuery.of(context).size.width *
// 0.5, // Will take 50% of screen space
child: ElevatedButton(
child: Text('Go to screen two'),
onPressed: () {},
),
)
Complete code
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: darkBlue,
),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
#override
Widget build(BuildContext context) {
return ListView(children: [
Row(
children: [
RotatedBox(
quarterTurns: 3,
child: Padding(
padding: const EdgeInsets.only(right: 30.0),
child: Text(
'Sign Up',
style: TextStyle(
color: Colors.white, fontSize: 50, fontFamily: 'Pacifico'),
),
),
),
SizedBox(
width: 20,
),
Text(
'BRUXTER',
style: TextStyle(
fontSize: 30,
fontFamily: 'RockSalt',
color: Colors.black,
fontWeight: FontWeight.bold),
)
],
),
SizedBox(
height: 50,
),
Form(
child: Column(
children: [
TextFormField(
style: TextStyle(color: Colors.black, fontSize: 30),
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Enter Your Name',
hintStyle: TextStyle(color: Colors.white60),
),
),
TextFormField(
style: TextStyle(color: Colors.black, fontSize: 30),
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Enter Your Email',
hintStyle: TextStyle(color: Colors.white60),
),
),
TextFormField(
style: TextStyle(color: Colors.black, fontSize: 30),
decoration: InputDecoration(
border: InputBorder.none,
hintText: 'Enter Your PassWord',
hintStyle: TextStyle(color: Colors.white60),
),
),
],
),
),
SizedBox(
height: 20,
),
Container(
// Replace width with margin
margin: EdgeInsets.symmetric(
horizontal: 80.0,
),
// width: MediaQuery.of(context).size.width *
// 0.5, // Will take 50% of screen space
child: ElevatedButton(
child: Text('Go to screen two'),
onPressed: () {},
),
)
]);
}
}
Instead of using Column, I would actually recommend staying with ListView for performance reasons in most cases.
You could also fix this issue by wrapping the Container in a Center widget (or an Align if you want a different alignment than centered).
These widgets provide loose constraints to their children so they can be any size they want, but no larger than the parent, which is exactly what you want in this case.
It wasn't working in your case, because the ListView forces children to take up the entire width, so what size the direct children want to take up is ignored.

Can't vertically center both input text and suffix in the Flutter TextField widget

I'm having a hard time aligning input ext and suffix in TextField Flutter widget. I try to center them vertically but can't do that for some reason.
When I don't specify suffix, the input text is vertically centered as desired:
When I specify the suffix, the input text goes down while the suffix goes up so that none of them are vertically centered:
My code:
return Scaffold(
backgroundColor: Colors.blue,
appBar: AppBar(
title: Text('test'),
),
body: Container(
color: Colors.grey.shade800,
margin: EdgeInsets.symmetric(
horizontal: 20,
vertical: 10,
),
height: 70,
alignment: Alignment.centerLeft,
child: TextField(
style: TextStyle(
textBaseline: TextBaseline.alphabetic,
color: Colors.white,
fontSize: 17,
fontWeight: FontWeight.w400,
decoration: TextDecoration.none,
),
textAlignVertical: TextAlignVertical.center,
decoration: InputDecoration(
suffix: Icon(
Icons.clear,
color: Colors.red,
),
suffixStyle: TextStyle(
color: Theme.of(context).textTheme.bodyText1.color,
fontWeight: FontWeight.w400,
fontSize: 17,
textBaseline: TextBaseline.ideographic,
),
border: InputBorder.none,
hintText: "Search",
),
),
),
);
The question:
What should I do to center input text and suffix vertically?
Wrap icon in Transform.translate and set propper offset to it

Using SingleChildScrollview inside Column widget content is not scrolling

Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: Colors.white,
body: Container(
child: Column(
children: <Widget>[
Stack(
fit: StackFit.loose,
children: <Widget>[
HeadersVC(),
Container(
margin: EdgeInsets.only(top: 40.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
FlatButton(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
onPressed: () {
Navigator.pop(context);
},
child: Icon(
Icons.arrow_back,
size: 30,
color: Colors.white,
),
),
Text(
widget.headertitleladderPre,
style: TextStyle(
fontSize: 22.0,
color: Colors.white,
fontWeight: FontWeight.bold),
),
],
),
)
],
),
SingleChildScrollView(
padding: EdgeInsets.only(top: 20.0, left: 30.0, right: 30.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Padding(
padding: EdgeInsets.only(top: 10.0),
),
//******************************************** Date Picker */
TextFormField(
onTap: () async {
FocusScope.of(context).requestFocus(new FocusNode());
_selectDate(context);
},
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Colors.black26, width: 1.5)),
contentPadding: EdgeInsets.only(left: 0.0, right: 0.0),
labelText: formatDate(formatedDate),
labelStyle: TextStyle(
fontFamily: "Montserrat", color: Colors.black),
suffixIcon: new Padding(
padding: const EdgeInsets.only(
top: 0.0, left: 0.0, right: 0.0, bottom: 0.0),
child: SizedBox(
height: 15,
child: Icon(
Icons.calendar_today,
color: Colors.red,
),
),
)),
),
Padding(
padding: EdgeInsets.only(left: 0.0, top: 10.0),
),
//******************************************** DropDown Button */
Container(
child: DropdownButton(
underline: Container(
height: 1.0,
decoration: const BoxDecoration(
border: Border(
bottom: BorderSide(
color: Colors.black26, width: 1.5))),
),
value: _selectedladleno,
items: _dropDownladleItems,
onChanged: changedDropDownItem,
isExpanded: true,
isDense: false,
icon: Icon(
Icons.arrow_drop_down,
color: Colors.red,
),
iconSize: 30,
elevation: 12,
style: TextStyle(
fontSize: 15,
),
),
),
//******************************************** Radio Button */
ButtonBar(
alignment: MainAxisAlignment.start,
buttonPadding: EdgeInsets.only(left: 0.0),
children: <Widget>[
Radio(
groupValue: _character,
onChanged: (SingingCharacter value) {
setState(() {
_character = value;
print(_character);
});
},
value: SingingCharacter.New,
activeColor: Colors.red,
),
Text(
"New",
style: TextStyle(fontSize: 13.0),
),
Radio(
groupValue: _character,
onChanged: (SingingCharacter value) {
setState(() {
_character = value;
print(_character);
});
},
value: SingingCharacter.Repair,
activeColor: Colors.red,
),
Text(
"Repair",
style: TextStyle(fontSize: 13.0),
),
Radio(
groupValue: _character,
onChanged: (SingingCharacter value) {
setState(() {
_character = value;
print(_character.toString());
});
},
value: SingingCharacter.OnlyMachineChange,
activeColor: Colors.red,
),
Text(
"Machine Change",
style: TextStyle(fontSize: 13.0),
),
],
),
//******************************************** Machine Number */
TextFormField(
decoration: InputDecoration(
labelText: "Machine Number *",
labelStyle: TextStyle(
fontFamily: "Montserrat", color: Colors.black)),
),
TextFormField(
decoration: InputDecoration(
labelText: "Well Block Party *",
labelStyle: TextStyle(
fontFamily: "Montserrat", color: Colors.black)),
),
TextFormField(
decoration: InputDecoration(
labelText: "Well Block Party *",
labelStyle: TextStyle(
fontFamily: "Montserrat", color: Colors.black)),
),
TextFormField(
decoration: InputDecoration(
labelText: "Well Block Party *",
labelStyle: TextStyle(
fontFamily: "Montserrat", color: Colors.black)),
),
TextFormField(
decoration: InputDecoration(
labelText: "Well Block Party *",
labelStyle: TextStyle(
fontFamily: "Montserrat", color: Colors.black)),
),
TextFormField(
decoration: InputDecoration(
labelText: "Well Block Party *",
labelStyle: TextStyle(
fontFamily: "Montserrat", color: Colors.black)),
),
TextFormField(
decoration: InputDecoration(
labelText: "Well Block Party *",
labelStyle: TextStyle(
fontFamily: "Montserrat", color: Colors.black)),
),
TextFormField(
decoration: InputDecoration(
labelText: "Well Block Party *",
labelStyle: TextStyle(
fontFamily: "Montserrat", color: Colors.black)),
),
TextFormField(
decoration: InputDecoration(
labelText: "Well Block Party *",
labelStyle: TextStyle(
fontFamily: "Montserrat", color: Colors.black)),
),
TextFormField(
decoration: InputDecoration(
labelText: "Well Block Party *",
labelStyle: TextStyle(
fontFamily: "Montserrat", color: Colors.black)),
)
],
),
)
],
),
),
);
}
I got Error Something Like this :
Performing hot reload... ⣟flutter: ══╡ EXCEPTION CAUGHT BY RENDERING LIBRARY ╞═════════════════════════════════════════════════════════
flutter: The following assertion was thrown during layout:
flutter: A RenderFlex overflowed by 158 pixels on the bottom.
flutter:
flutter: The relevant error-causing widget was:
flutter: Column file:///Users/baps/Projects/Flutter%20Projects/TRLApp/trlapp/lib/ladlePreheating.dart:64:16
flutter:
flutter: The overflowing RenderFlex has an orientation of Axis.vertical.
flutter: The edge of the RenderFlex that is overflowing has been marked in the rendering with a yellow and
flutter: black striped pattern. This is usually caused by the contents being too big for the RenderFlex.
flutter: Consider applying a flex factor (e.g. using an Expanded widget) to force the children of the
flutter: RenderFlex to fit within the available space instead of being sized to their natural size.
flutter: This is considered an error condition because it indicates that there is content that cannot be
flutter: seen. If the content is legitimately bigger than the available space, consider clipping it with a
flutter: ClipRect widget before putting it in the flex, or using a scrollable container rather than a Flex,
flutter: like a ListView.
flutter: The specific RenderFlex in question is: RenderFlex#4bdfd relayoutBoundary=up1 OVERFLOWING:
flutter: needs compositing
flutter: creator: Column ← Container ← _BodyBuilder ← MediaQuery ← LayoutId-[<_ScaffoldSlot.body>] ←
flutter: CustomMultiChildLayout ← AnimatedBuilder ← DefaultTextStyle ← AnimatedDefaultTextStyle ←
flutter: _InkFeatures-[GlobalKey#9c17c ink renderer] ← NotificationListener ←
flutter: PhysicalModel ← ⋯
flutter: parentData: offset=Offset(0.0, 0.0); id=_ScaffoldSlot.body (can use size)
flutter: constraints: BoxConstraints(0.0<=w<=414.0, 0.0<=h<=736.0)
flutter: size: Size(414.0, 736.0)
flutter: direction: vertical
flutter: mainAxisAlignment: start
flutter: mainAxisSize: max
flutter: crossAxisAlignment: center
flutter: verticalDirection: down
flutter: ◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤◢◤
flutter: ════════════════════════════════════════════════════════════════════════════════════════════════════
Missed to Expand the ScrollView as Column container would not know how much space it needs to take and due to that, it calculates the size which is more than of screen size.
So Just place Expanded in to it:
...
Expanded(
child: SingleChildScrollView(
padding:...
SingleChildScrollView should be Wrapped around Column:
Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: Colors.white,
body: Container(
child: SingleChildScrollView( // <--- Put it here.
child: Column( // <--- Your Column.
Solution: You need to use SingleChildScrollView before column .If you want to keep separated stack part ,you can use CustomScrollView . CustomScrollView
Widget build(BuildContext context) {
return Scaffold(
resizeToAvoidBottomInset: false,
backgroundColor: Colors.white,
body: SingleChildScrollView(
padding: EdgeInsets.only(top: 20.0, left: 30.0, right: 30.0),
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Stack(
fit: StackFit.loose,
children: <Widget>[
Container(
margin: EdgeInsets.only(top: 40.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
FlatButton(
splashColor: Colors.transparent,
highlightColor: Colors.transparent,
onPressed: () {
Navigator.pop(context);
},
child: Icon(
Icons.arrow_back,
size: 30,
color: Colors.white,
),
),
Text(
"headertitleladderPre",
style: TextStyle(
fontSize: 22.0,
color: Colors.white,
fontWeight: FontWeight.bold),
),
],
),
)
],
),
Padding(
padding: EdgeInsets.only(top: 10.0),
),
//******************************************** Date Picker */
TextFormField(
onTap: () async {},
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Colors.black26, width: 1.5)),
contentPadding: EdgeInsets.only(left: 0.0, right: 0.0),
labelText: "formatedDate",
labelStyle: TextStyle(
fontFamily: "Montserrat", color: Colors.black),
suffixIcon: new Padding(
padding: const EdgeInsets.only(
top: 0.0, left: 0.0, right: 0.0, bottom: 0.0),
child: SizedBox(
height: 15,
child: Icon(
Icons.calendar_today,
color: Colors.red,
),
),
)),
),
Padding(
padding: EdgeInsets.only(left: 0.0, top: 10.0),
),
//******************************************** DropDown Button */
Container(
child: DropdownButton<String>(
value: dropdownValue,
icon: Icon(Icons.arrow_downward),
iconSize: 24,
elevation: 16,
style: TextStyle(color: Colors.deepPurple),
underline: Container(
height: 2,
color: Colors.deepPurpleAccent,
),
onChanged: (String newValue) {},
items: <String>['One', 'Two', 'Free', 'Four']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
),
//******************************************** Radio Button */
ButtonBar(
alignment: MainAxisAlignment.start,
buttonPadding: EdgeInsets.only(left: 0.0),
children: <Widget>[
Text("Radio Here"),
Text(
"New",
style: TextStyle(fontSize: 13.0),
),
Text("One More Radio Here"),
Text(
"Repair",
style: TextStyle(fontSize: 13.0),
),
Text("One More Radio Here"),
Text(
"Machine Change",
style: TextStyle(fontSize: 13.0),
),
],
),
//******************************************** Machine Number */
TextFormField(
decoration: InputDecoration(
labelText: "Machine Number *",
labelStyle: TextStyle(
fontFamily: "Montserrat", color: Colors.black)),
),
TextFormField(
decoration: InputDecoration(
labelText: "Well Block Party *",
labelStyle: TextStyle(
fontFamily: "Montserrat", color: Colors.black)),
),
TextFormField(
decoration: InputDecoration(
labelText: "Well Block Party *",
labelStyle: TextStyle(
fontFamily: "Montserrat", color: Colors.black)),
),
TextFormField(
decoration: InputDecoration(
labelText: "Well Block Party *",
labelStyle: TextStyle(
fontFamily: "Montserrat", color: Colors.black)),
),
TextFormField(
decoration: InputDecoration(
labelText: "Well Block Party *",
labelStyle: TextStyle(
fontFamily: "Montserrat", color: Colors.black)),
),
TextFormField(
decoration: InputDecoration(
labelText: "Well Block Party *",
labelStyle: TextStyle(
fontFamily: "Montserrat", color: Colors.black)),
),
TextFormField(
decoration: InputDecoration(
labelText: "Well Block Party *",
labelStyle: TextStyle(
fontFamily: "Montserrat", color: Colors.black)),
),
TextFormField(
decoration: InputDecoration(
labelText: "Well Block Party *",
labelStyle: TextStyle(
fontFamily: "Montserrat", color: Colors.black)),
),
TextFormField(
decoration: InputDecoration(
labelText: "Well Block Party *",
labelStyle: TextStyle(
fontFamily: "Montserrat", color: Colors.black)),
),
TextFormField(
decoration: InputDecoration(
labelText: "Well Block Party *",
labelStyle: TextStyle(
fontFamily: "Montserrat", color: Colors.black)),
)
],
),
),
));
}
Avoid Using
child: ConstrainedBox(
constraints: BoxConstraints()),
In side SingleChildScrollView when i remove this widget rendering error is gone.
Sample Code of my layout.
#override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: kBackgroundColorGray,
appBar: commonAppBar,
body: SafeArea(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
],
),
),
)
);
}

Flutter - Responsive ui for different screen sizes

I am trying to figure out the responsive aspect of flutter. So as you can see from the image things are not going all that well for the different screen sizes of iPhone.
I am working with a Stack and FractionallySizedBox but not sure if what I am doing is correct. Any help is appreciate.
Code is available here -> https://gist.github.com/GY22/1eefb5e48fdca9d785365cbccbdcb478
import 'package:flutter/material.dart';
class SignIn extends StatelessWidget {
//textfields + logo
List<Widget> _buildChildrenForm() {
return [
//logo
Text(
'THE GUEST LIST',
style: TextStyle(
color: Colors.white,
fontFamily: 'futura',
fontSize: 60.0
)
),
//email
TextField(
cursorColor: Colors.white,
cursorWidth: 3.0,
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.white
)
),
labelText: 'EMAIL',
labelStyle: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
//hintText: 'DEMO#MAIL.COM',
hintStyle: TextStyle(
fontSize: 20.0,
color: Colors.white,
),
),
style: TextStyle(
color: Colors.white,
fontSize: 20.0
),
),
SizedBox(height: 20.0,),
//password
TextField(
cursorColor: Colors.white,
cursorWidth: 3.0,
obscureText: true,
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(
color: Colors.white
)
),
labelText: 'PASSWORD',
labelStyle: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
hintStyle: TextStyle(
color: Colors.white
),
),
style: TextStyle(
color: Colors.white,
),
),
SizedBox(height: 65.0,),
//submit button
FlatButton(
child: Text(
'SIGN IN',
style: TextStyle(
fontSize: 35.0,
color: Colors.white
),
),
onPressed: () {},
),
SizedBox(height: 10.0),
//forget password
FlatButton(
child: Text(
'FORGOT PASSWORD',
style: TextStyle(
color: Colors.white,
fontSize: 17.0
),
),
onPressed: () {},
)
];
}
Widget _formSignIn(BuildContext context) {
return Padding(
padding: const EdgeInsets.all(30.0),
child: Column(
children: _buildChildrenForm(),
),
);
}
#override
Widget build(BuildContext context) {
final double screenHeight = MediaQuery.of(context).size.height;
final double halfScreen = screenHeight / 2;
final double finalHeight = halfScreen / screenHeight;
debugPrint(MediaQuery.of(context).size.height.toString());
//debugPrint(MediaQuery.of(context).size.width.toString());
return Scaffold(
body: Stack(
fit: StackFit.expand,
children: <Widget>[
//bg image
FractionallySizedBox(
alignment: Alignment.topLeft,
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('images/backgroundWithOpacity.png'),
fit: BoxFit.cover
)
),
),
),
//form
FractionallySizedBox(
alignment: Alignment.center,
heightFactor: 1 - finalHeight,
child: ListView(
children: <Widget>[
_formSignIn(context)
],
),
)
],
),
);
}
}
Use FittedBox for compressing the title in device width.
Use Align for centering, we need ListView only for keyboard appearences, normally the content you wanna show to the user is even small enough for iPhone 5s.
You have extra line of codes and I removed.
import 'package:flutter/material.dart';
void main() {
runApp(MaterialApp(
home: Scaffold(
body: SignIn(),
)));
}
class SignIn extends StatelessWidget {
List<Widget> _buildChildrenForm() => [
//logo
SizedBox(
width: double.infinity,
child: FittedBox(
fit: BoxFit.fitWidth,
child: Text('THE GUEST LIST',
style: TextStyle(
color: Colors.white, fontFamily: 'futura', fontSize: 60.0)),
),
),
//email
TextField(
cursorColor: Colors.white,
cursorWidth: 3.0,
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white)),
labelText: 'EMAIL',
labelStyle: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
//hintText: 'DEMO#MAIL.COM',
hintStyle: TextStyle(
fontSize: 20.0,
color: Colors.white,
),
),
style: TextStyle(color: Colors.white, fontSize: 20.0),
),
//password
SizedBox(height: 20),
TextField(
cursorColor: Colors.white,
cursorWidth: 3.0,
obscureText: true,
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: Colors.white)),
labelText: 'PASSWORD',
labelStyle: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
hintStyle: TextStyle(color: Colors.white),
),
style: TextStyle(
color: Colors.white,
),
),
//submit button
SizedBox(height: 65),
FlatButton(
child: Text(
'SIGN IN',
style: TextStyle(fontSize: 35.0, color: Colors.white),
),
onPressed: () {},
),
SizedBox(height: 10),
//forget password
FlatButton(
child: Text(
'FORGOT PASSWORD',
style: TextStyle(color: Colors.white, fontSize: 17.0),
),
onPressed: () {},
)
];
#override
Widget build(BuildContext context) {
return Scaffold(
body: Stack(
fit: StackFit.expand,
children: <Widget>[
//bg image
FractionallySizedBox(
alignment: Alignment.topLeft,
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/backgroundWithOpacity.png'),
fit: BoxFit.cover)),
),
),
//form
Align(
alignment: Alignment.center,
child: Padding(
padding: const EdgeInsets.symmetric(horizontal: 32.0),
child: ListView(
shrinkWrap: true,
children: _buildChildrenForm(),
),
),
)
],
),
);
}
}
Avoid SizeConfig (custom class) and hard coded dimensions as much as you can.
Example: MediaQuery.of(context).size.width - someValue
Best easiest way to to make responsive UI for different screen size is Sizer plugin.
Check it this plugin ⬇️
https://pub.dev/packages/sizer
You can use SingleChildScrollView or ListView, and using relative proportions