Using SingleChildScrollview inside Column widget content is not scrolling - flutter

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: [
],
),
),
)
);
}

Related

How to Place two Text Form Fields side by side in flutter

I am trying to create a form in flutter. In which I want to keep the two text fields side by side as shown below:
I want to place Department and Year of Study field in same row as shown in picture. I am unable to do it. I have tried this using Row widget as shown below:
Row(
children: <Widget>[
Column(
children: [
const Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 5),
child: Text(
"Department",
style: TextStyle(
color: Colors.black,
fontSize: 16,
fontFamily: "Poppins",
fontWeight: FontWeight.w700,
),
),
),
TextFormField(
decoration: const InputDecoration(
border: OutlineInputBorder(
borderRadius:
BorderRadius.all(Radius.circular(8))),
),
),
],
),
Column(
children: [
const Padding(
padding: EdgeInsets.fromLTRB(0, 0, 0, 5),
child: Text(
"Year of Study",
style: TextStyle(
color: Colors.black,
fontSize: 16,
fontFamily: "Poppins",
fontWeight: FontWeight.w700,
),
),
),
TextFormField(
decoration: const InputDecoration(
border: OutlineInputBorder(
borderRadius:
BorderRadius.all(Radius.circular(8))),
),
),
],
),
However, its giving me error. On searching the google I have got some idea to wrap TextFormField in Flexible() widget but that also didn't worked for me and giving me a different type of error. I have also tried to wrap in Expanded() but the error is still coming.
Try below code as per your above image show.
Column(
children: [
ListTile(
title: Text('Full Name'),
subtitle: TextFormField(
decoration: const InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(8))),
hintText: 'Full Name',
),
),
),
SizedBox(
height: 5,
),
Row(
children: [
Expanded(
child: ListTile(
title: Text('Department'),
subtitle: TextFormField(
decoration: const InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(8))),
hintText: ' Department',
),
),),
),
SizedBox(
width: 5,
),
Expanded(
child:ListTile(
title: Text('Year Of Study'),
subtitle: TextFormField(
decoration: const InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(8))),
hintText: ' Year Of Study',
),
),),
),
],
)
],
),
Result Screen->
Wrap each of them in sized boxed and give them a fixed width. The problem is because Rows and TextFormFields expand infinitely. And when putting a textformfield inside a row, you'll get a renderflex error. A sized box would solve this by giving it a limited width.
You can wrap the childrens into Expanded Widget:
Row(
children: [
Expanded(
flex: 3,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Padding(
padding: EdgeInsets.fromLTRB(10, 0, 0, 5),
child: Text(
"Department",
style: TextStyle(
color: Colors.black,
fontSize: 16,
fontFamily: "Poppins",
fontWeight: FontWeight.w700,
),
),
),
TextFormField(
decoration: const InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(8))),
),
),
],
),
),
SizedBox(width: 8),
Expanded(
flex: 2,
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
const Padding(
padding: EdgeInsets.fromLTRB(10, 0, 0, 5),
child: Text(
"Year of Study",
style: TextStyle(
color: Colors.black,
fontSize: 16,
fontFamily: "Poppins",
fontWeight: FontWeight.w700,
),
),
),
TextFormField(
decoration: const InputDecoration(
border: OutlineInputBorder(
borderRadius: BorderRadius.all(Radius.circular(8))),
),
),
],
),
),
],
),
I also added a SizedBox in between, the flex property to have different sizes for the text fields and the crossAxisAlignment: CrossAxisAlignment.start to have the text on the left side.

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.

Flutter: Bottom part of the screen doesnt show up in release apk of android and adhoc build of ios

When i run my app from android studio, my screen renders fine.
However, when i create and install an apk or create an adhoc build for ios, my screen renders like this:
As you see the textfield and the buttons below it dont show up. I dont understand what is going wrong. Can you help please.
This is the code for the screen:
var child = Stack(
children: <Widget>[
Column(
mainAxisSize: MainAxisSize.max,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Expanded(
//flex: 90,
child: Image.asset(
"${Constants.imagesPath}login-cover-bg.png",
fit: BoxFit.cover,
),
),
Expanded(
//flex: 100,
child: Container(
child: ListView(
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 50, left: 25),
child: Text(
'Please sign in',
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 22,
),
),
),
SizedBox(
height: 40,
),
Expanded(
flex: 1,
child: Container(
color: Colors.orange,
padding: EdgeInsets.only(left: 25, bottom: 15, right: 25),
child: TextField(
maxLines: 1,
keyboardType: TextInputType.emailAddress,
onSubmitted: (_) {
_checkEmailValid();
FocusScope.of(context).nextFocus();
},
textInputAction: TextInputAction.next,
controller: _emailController,
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: disableRedColor),
// when the TextFormField in unfocused
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: themeRedColor),
// when the TextFormField in focused
),
border: UnderlineInputBorder(),
hintText: 'Email',
errorText: isEmailValid == true ? '' : 'Invalid email'
),
),
),
),
Expanded(
flex: 2,
child: Container(
color: Colors.yellow,
padding: EdgeInsets.only(left: 25, right: 25),
child: TextField(
maxLines: 1,
onSubmitted: (_) {
_checkPasswordValid();
FocusScope.of(context).unfocus();
},
keyboardType: TextInputType.text,
textInputAction: TextInputAction.done,
controller: _passwordController,
decoration: InputDecoration(
enabledBorder: UnderlineInputBorder(
borderSide: BorderSide(color: disableRedColor),
// when the TextFormField in unfocused
),
focusedBorder: UnderlineInputBorder(
borderSide: BorderSide(color: themeRedColor),
// when the TextFormField in focused
),
border: UnderlineInputBorder(),
hintText: 'Password',
errorText: isPasswordValid == true ? '' : 'Invalid password',
suffixIcon: IconButton(
icon: Icon(
shouldObscureText == false ? Icons.visibility : Icons.visibility_off,
color: themeRedColor,
),
onPressed: (){
setState(() {
shouldObscureText = !shouldObscureText;
});
},
)
),
obscureText: shouldObscureText,
),
),
),
SizedBox(
height: 65,
),
Expanded(
flex: 1,
child: GestureDetector(
onTap: () {
Util.navigateView(context, SignupScreen());
},
child: Container(
padding: EdgeInsets.only(left: 25, right: 25),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
'Forgot Password?',
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 15,
color: Colors.black54),
),
Text(
'Sign up',
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 15,
color: Colors.black54),
),
],
),
),
)),
],
),
color: Colors.white,
),
),
],
),
Padding(
padding: const EdgeInsets.all(16.0),
child: Container(
width: 200,
child: Text(
'Welcome Back',
maxLines: 2,
style: TextStyle(
color: Colors.white,
fontSize: 35,
fontWeight: FontWeight.bold,
),
),
),
),
Align(
alignment: Alignment.centerRight,
child: InkWell(
onTap: () {
print('skip press');
if(isEmailValid && isPasswordValid && _emailController.text.isNotEmpty && _passwordController.text.isNotEmpty){
hitTheLoginAPI();
}
else {
isEmailValid = false;
isPasswordValid = false;
Util.showToast('Invalid username or password');
}
},
child: Container(
margin: EdgeInsets.only(right: 20, bottom: 35),
width: 80,
height: 80,
decoration: BoxDecoration(
shape: BoxShape.circle,
color: themeRedColor,
),
child: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Icon(
Icons.arrow_forward,
color: Colors.white,
),
Text(
'Skip',
style: TextStyle(color: Colors.white, fontSize: 17),
),
],
),
),
),
),
),
],
);
what is going wrong??
You are using Expanded widgets inside a ListView. Expanded is supposed to be used inside a Column or a Row instead.
The incorrect usage throws an exception in debug mode & still prints the UI, since it isn't a breaking issue as such.
In release mode however, Flutter does not show errors or warnings - instead it simply shows a greyed out container, which is what is taking up some space on your app in release mode.
I think the problem is with responsiveness. Maybe, You might have used a really small or really large screen size emulator and it didnt fit according to that. Try using the ListView widget.
you can use 'SingleChildScrollView' to let the user scroll down
just wrap with widget
SingleChildScrollView(
child:...
);
you can also use 'MediaQuery' and adapt the size by the device size
MediaQuery

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

I have a section with Scroll a Form but scroll not working properly in flutter

I am getting this bar on the bottom saying "Bottom Overflowed by 27 pixels."
Here is how my UI looks like
class _RegisterPageState extends State<RegisterPage> {
#override
Widget build(BuildContext context) {
final fullname = TextFormField(
style: TextStyle(color: Colors.white, fontSize: 17.0),
decoration: InputDecoration(
icon: Icon(Icons.person_outline, size: 30.0, color: Colors.white),
labelText: "FULL NAME",
labelStyle: TextStyle(color: Colors.white, height: 0.5, fontSize: 15.0),
contentPadding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0,15.0),
border: InputBorder.none,
),
);
final username = TextFormField(
keyboardType: TextInputType.emailAddress,
style: TextStyle(color: Colors.white, fontSize: 17.0),
decoration: InputDecoration(
icon: Icon(Icons.alternate_email, size: 30.0, color: Colors.white),
labelText: "EMAIL ADDRESS",
labelStyle: TextStyle(color: Colors.white, height: 0.5, fontSize: 15.0),
contentPadding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0,15.0),
border: InputBorder.none,
),
);
final mobilenumber = TextFormField(
keyboardType: TextInputType.number,
style: TextStyle(color: Colors.white, fontSize: 17.0),
decoration: InputDecoration(
icon: Icon(Icons.phone_android, size: 30.0, color: Colors.white),
labelText: "MOBILE NUMBER",
labelStyle: TextStyle(color: Colors.white, height: 0.5, fontSize: 15.0),
contentPadding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0,15.0),
border: InputBorder.none,
),
);
final registerButton = Padding(
padding: EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 10.0),
child: FlatButton(
shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0)),
padding: EdgeInsets.fromLTRB(0.0, 20.0, 0.0, 20.0),
onPressed: (){
},
color: Colors.pink,
child: Text("Register", style: TextStyle(color: Colors.white, fontSize: 18.0)),
),
);
final password = TextFormField(
obscureText: true,
style: TextStyle(color: Colors.white, fontSize: 17.0),
decoration: InputDecoration(
icon: Icon(Icons.lock_outline, size: 30.0, color: Colors.white),
labelText: "PASSWORD",
labelStyle: TextStyle(color: Colors.white, height: 0.5, fontSize: 15.0),
contentPadding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0,15.0),
border: InputBorder.none,
),
);
final repassword = TextFormField(
obscureText: true,
style: TextStyle(color: Colors.white, fontSize: 17.0),
decoration: InputDecoration(
icon: Icon(Icons.lock_outline, size: 30.0, color: Colors.white),
labelText: "RE-TYPE PASSWORD",
labelStyle: TextStyle(color: Colors.white, height: 0.5, fontSize: 15.0),
contentPadding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0,15.0),
border: InputBorder.none,
),
);
List<DropdownMenuItem<String>> genderNames = [];
String selectedItem;
void loadGenders(){
genderNames = [];
genderNames.add(new DropdownMenuItem(child: new Text("Male"), value: "male",));
genderNames.add(new DropdownMenuItem(child: new Text("Female"), value: "female"));
}
loadGenders();
final genderDropDown = Container(
child : Row(
children: <Widget>[
Icon(Icons.wc, size: 30.0, color: Colors.white),
SizedBox(width: 15.0),
DropdownButtonHideUnderline(
child: DropdownButton(
value: selectedItem,
items: genderNames,
hint: Text("SELECT GENDER"),
iconSize: 40.0,
onChanged: (value) {
selectedItem = value;
setState(() {
});
},
),
)
],
)
);
final inputboarder = new Container(
height: 1.0,
margin: EdgeInsets.fromLTRB(0.0, 7.0, 0.0, 0.0),
decoration: BoxDecoration(
image: DecorationImage(
image: new AssetImage("assets/transparentborder.png"),
)
),
);
final appbar = Stack(
children: <Widget>[
AppBar(
backgroundColor: Colors.transparent,
elevation: 0.0,
title: Text("Create Account"),
)
],
);
return Scaffold(
body : Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage("assets/Social-free-psd.jpg"),
fit: BoxFit.fill,
),
),
child: NestedScrollView(
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return <Widget>[
new SliverAppBar(
backgroundColor: Colors.transparent,
elevation: 0.0,
pinned: true,
title: new Text('Flutter Demo'),
),
];
},
body: Column(
children: <Widget>[
Container(
padding: EdgeInsets.only(left: 40.0, right: 40.0),
child: ListView(
shrinkWrap: true,
children: <Widget>[
SizedBox(height: 58.0),
fullname,
inputboarder,
SizedBox(height: 28.0),
username,
inputboarder,
SizedBox(height: 28.0),
password,
inputboarder,
SizedBox(height: 28.0),
repassword,
inputboarder,
SizedBox(height: 28.0),
mobilenumber,
inputboarder,
SizedBox(height: 28.0),
genderDropDown,
inputboarder,
SizedBox(height: 28.0),
registerButton
],
)
),
],
),
)
),
);
}
}
I am not sure where is the problem, I am new to flutter. But this looks like a debug error. Am I getting it right? Even if it is then how can I resolve this issue?
It started coming when I Put "NestedScrollView" to scroll the form. I guess ListView inside ListView does not provide default scroll behavior.
Any suggestions will be helpful.
Thank you!
So i've made a couple of changes to your code so that I can compile it qucikly and help you. (if you copy paste my code here do not forget to modify your assets to your needs)
First I've made it a StatlessWidget for my needs, but you can leave it as a StatefulWidget.
Then, I included your appBar inside the Scaffold itself.
Then the childof your Scaffoldshould be a Stackthis way you can stack up all of your different TextFormFieldand scroll along the screen.
You may need to replace the return new MaterialApp( home: part to return new Scaffold.
Here is the code:
import 'package:flutter/material.dart';
void main() => runApp(new MyApp());
class MyApp extends StatelessWidget {
#override
Widget build(BuildContext context) {
final fullname = TextFormField(
style: TextStyle(color: Colors.white, fontSize: 17.0),
decoration: InputDecoration(
icon: Icon(Icons.person_outline, size: 30.0, color: Colors.white),
labelText: "FULL NAME",
labelStyle: TextStyle(color: Colors.white, height: 0.5, fontSize: 15.0),
contentPadding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0,15.0),
border: InputBorder.none,
),
);
final username = TextFormField(
keyboardType: TextInputType.emailAddress,
style: TextStyle(color: Colors.white, fontSize: 17.0),
decoration: InputDecoration(
icon: Icon(Icons.alternate_email, size: 30.0, color: Colors.white),
labelText: "EMAIL ADDRESS",
labelStyle: TextStyle(color: Colors.white, height: 0.5, fontSize: 15.0),
contentPadding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0,15.0),
border: InputBorder.none,
),
);
final mobilenumber = TextFormField(
keyboardType: TextInputType.number,
style: TextStyle(color: Colors.white, fontSize: 17.0),
decoration: InputDecoration(
icon: Icon(Icons.phone_android, size: 30.0, color: Colors.white),
labelText: "MOBILE NUMBER",
labelStyle: TextStyle(color: Colors.white, height: 0.5, fontSize: 15.0),
contentPadding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0,15.0),
border: InputBorder.none,
),
);
final registerButton = Padding(
padding: EdgeInsets.fromLTRB(0.0, 10.0, 0.0, 10.0),
child: FlatButton(
shape: new RoundedRectangleBorder(borderRadius: new BorderRadius.circular(30.0)),
padding: EdgeInsets.fromLTRB(0.0, 20.0, 0.0, 20.0),
onPressed: (){
},
color: Colors.pink,
child: Text("Register", style: TextStyle(color: Colors.white, fontSize: 18.0)),
),
);
final password = TextFormField(
obscureText: true,
style: TextStyle(color: Colors.white, fontSize: 17.0),
decoration: InputDecoration(
icon: Icon(Icons.lock_outline, size: 30.0, color: Colors.white),
labelText: "PASSWORD",
labelStyle: TextStyle(color: Colors.white, height: 0.5, fontSize: 15.0),
contentPadding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0,15.0),
border: InputBorder.none,
),
);
final repassword = TextFormField(
obscureText: true,
style: TextStyle(color: Colors.white, fontSize: 17.0),
decoration: InputDecoration(
icon: Icon(Icons.lock_outline, size: 30.0, color: Colors.white),
labelText: "RE-TYPE PASSWORD",
labelStyle: TextStyle(color: Colors.white, height: 0.5, fontSize: 15.0),
contentPadding: EdgeInsets.fromLTRB(0.0, 0.0, 0.0,15.0),
border: InputBorder.none,
),
);
List<DropdownMenuItem<String>> genderNames = [];
String selectedItem;
void loadGenders(){
genderNames = [];
genderNames.add(new DropdownMenuItem(child: new Text("Male"), value: "male",));
genderNames.add(new DropdownMenuItem(child: new Text("Female"), value: "female"));
}
loadGenders();
final genderDropDown = Container(
child : Row(
children: <Widget>[
Icon(Icons.wc, size: 30.0, color: Colors.white),
SizedBox(width: 15.0),
DropdownButtonHideUnderline(
child: DropdownButton(
value: selectedItem,
items: genderNames,
hint: Text("SELECT GENDER"),
iconSize: 40.0,
onChanged: (value) {
selectedItem = value;
/*setState(() {
});*/
},
),
)
],
)
);
final inputboarder = new Container(
height: 1.0,
margin: EdgeInsets.fromLTRB(0.0, 7.0, 0.0, 0.0),
decoration: BoxDecoration(
image: DecorationImage(
image: new AssetImage("assets/tmp/birds.jpg"),
)
),
);
return new MaterialApp(
home:
new Scaffold(
appBar: new AppBar(
title: new Text('Flutter Demo'),
elevation: 0.0,
backgroundColor: Colors.transparent,
//Something to pin the appbar
),
body : Container(
decoration: new BoxDecoration(
image: new DecorationImage(
image: new AssetImage("assets/tmp/birds.jpg"),
fit: BoxFit.fill,
),
),
child: new Stack(
children: <Widget>[
Container(
padding: EdgeInsets.only(left: 40.0, right: 40.0),
child: ListView(
shrinkWrap: true,
children: <Widget>[
SizedBox(height: 58.0),
fullname,
inputboarder,
SizedBox(height: 28.0),
username,
inputboarder,
SizedBox(height: 28.0),
password,
inputboarder,
SizedBox(height: 28.0),
repassword,
inputboarder,
SizedBox(height: 28.0),
mobilenumber,
inputboarder,
SizedBox(height: 28.0),
genderDropDown,
inputboarder,
SizedBox(height: 28.0),
registerButton
],
)
),
],
),
),
)
);
}
}
Hoping this helps you,