How to put padding top in singlechildscrollview on keyboard appears - ios

I using this library keyboard_actions to display Done button on above keyboard when on click on textfield. Now the issue is keyboard displays but done portion is overlapping/ Above on textfield although textfield is inside SingleChildScrollView. I want to put padding when keyboard appear so that i can see textfield. I have an attached screenshot so that you can understand.
TestPage.dart
class TestPage extends StatefulWidget {
const TestPage({Key? key}) : super(key: key);
#override
_TestPageState createState() => _TestPageState();
}
class _TestPageState extends State<TestPage> {
final TextEditingController mobileNumber = TextEditingController();
final _formKey = GlobalKey<FormState>();
final FocusNode _nodeText1 = FocusNode();
late bool _passwordVisible;
final TextEditingController firstName = TextEditingController();
final TextEditingController lastName = TextEditingController();
final TextEditingController password = TextEditingController();
final TextEditingController confirmPassword = TextEditingController();
String pWord = "";
List gender = ["Male", "Female"];
late String genderChoose;
KeyboardActionsConfig _buildConfig(BuildContext context) {
return KeyboardActionsConfig(
keyboardActionsPlatform: KeyboardActionsPlatform.IOS,
keyboardBarColor: Colors.grey[200],
nextFocus: false,
actions: [
KeyboardActionsItem(
focusNode: _nodeText1,
),
],
);
}
_TestPageState();
#override
void initState() {
genderChoose = gender[0];
_passwordVisible = false;
super.initState();
}
#override
Widget build(BuildContext context) {
var height = MediaQuery.of(context).size.height;
var width = MediaQuery.of(context).size.width;
var box = GetStorage();
var lang = translator.activeLanguageCode;
return MediaQuery(
data: MediaQueryData.fromWindow(WidgetsBinding.instance!.window)
.copyWith(boldText: false, textScaleFactor: 1.0),
child: Scaffold(
backgroundColor: Colors.red,
appBar: AppBar(
backgroundColor: Colors.red,
elevation: 0,
),
body: KeyboardActions(
config: _buildConfig(context),
child: Stack(
children: [
Padding(
padding:
const EdgeInsets.only(top: 10.0, left: 10.0, right: 10.0),
child: Center(
child: SingleChildScrollView(
child: Form(
key: _formKey,
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(
left: 90.0, right: 90.0, top: 25.0),
child: Image.asset(
'images/aa.png',
color: Colors.white,
),
),
Padding(
padding: const EdgeInsets.only(
left: 15.0, right: 15.0, top: 20.0),
child: Card(
color: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(20),
),
child: Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 30.0),
child: Text(
'SIGN UP',
style: TextStyle(
color: Colors.red, fontSize: 24.0),
),
),
Padding(
padding: const EdgeInsets.only(
left: 20.0, right: 20.0, top: 15.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text('First name'),
Row(
children: const [],
)
],
),
),
Padding(
padding: const EdgeInsets.only(
left: 20.0, right: 20.0, top: 10.0),
child: Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(6),
border:
Border.all(color: Colors.grey)),
child: Padding(
padding: const EdgeInsets.only(
left: 5.0,
right: 5.0,
top: 12.0,
bottom: 12.0),
child: TextFormField(
keyboardType: TextInputType.text,
controller: firstName,
),
),
),
),
Padding(
padding: const EdgeInsets.only(
left: 20.0, right: 20.0, top: 15.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text('Last name'),
Row(
children: const [],
)
],
),
),
Padding(
padding: const EdgeInsets.only(
left: 20.0, right: 20.0, top: 10.0),
child: Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(6),
border:
Border.all(color: Colors.grey)),
child: Padding(
padding: const EdgeInsets.only(
left: 5.0,
right: 5.0,
top: 12.0,
bottom: 12.0),
child: TextFormField(
keyboardType: TextInputType.text,
controller: lastName),
),
),
),
Padding(
padding: const EdgeInsets.only(
left: 20.0, right: 20.0, top: 15.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text('Mobile Number'),
Row(
children: const [],
)
],
),
),
Padding(
padding: const EdgeInsets.only(
left: 20.0, right: 20.0, top: 10.0),
child: Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(6),
border:
Border.all(color: Colors.grey)),
child: Padding(
padding: const EdgeInsets.only(
left: 5.0,
right: 5.0,
top: 12.0,
bottom: 12.0),
child: TextFormField(
inputFormatters: <TextInputFormatter>[
FilteringTextInputFormatter.allow(
RegExp("[0-9]")),
],
keyboardType: TextInputType.number,
focusNode: _nodeText1,
controller: mobileNumber,
decoration: InputDecoration.collapsed(
fillColor: Colors.white,
hintText: "5xxxxxxxx",
hintStyle: TextStyle(
color:
TuxedoColor.bodyColor)),
),
),
),
),
Padding(
padding: const EdgeInsets.only(
left: 20.0, right: 20.0, top: 20.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text('Gender'),
Row(
children: const [],
)
],
),
),
Padding(
padding: const EdgeInsets.only(
left: 20.0, right: 20.0, top: 10.0),
child: Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(6),
border:
Border.all(color: Colors.grey)),
child: Padding(
padding: const EdgeInsets.only(
left: 5.0,
right: 5.0,
),
child: DropdownButton(
hint: const Text('Select Gender'),
value: genderChoose,
isExpanded: true,
underline: const SizedBox(),
icon:
const Icon(Icons.arrow_drop_down),
onChanged: (newValue) {
setState(() {
genderChoose = newValue as String;
});
},
items: gender.map((valueItem) {
return DropdownMenuItem(
value: valueItem,
child: Text(valueItem));
}).toList(),
),
),
),
),
Padding(
padding: const EdgeInsets.only(
left: 20.0, right: 20.0, top: 20.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text('Password'),
Row(
children: const [],
)
],
),
),
Padding(
padding: const EdgeInsets.only(
left: 20.0, right: 20.0, top: 10.0),
child: Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(6),
border:
Border.all(color: Colors.grey)),
child: Padding(
padding: const EdgeInsets.only(
left: 5.0,
right: 5.0,
top: 12.0,
bottom: 12.0),
child: Stack(
children: [
TextFormField(
keyboardType:
TextInputType.visiblePassword,
controller: password,
obscureText: !_passwordVisible,
decoration:
InputDecoration.collapsed(
fillColor: Colors.white,
hintText: "*******",
hintStyle: TextStyle(
color: TuxedoColor
.bodyColor)),
),
Positioned(
right: 0,
top: -10,
bottom: 0,
child: IconButton(
icon: Icon(
_passwordVisible
? Icons.visibility
: Icons.visibility_off,
),
onPressed: () {
setState(() {
_passwordVisible =
!_passwordVisible;
});
},
),
)
],
),
),
),
),
Padding(
padding: const EdgeInsets.only(
left: 20.0, right: 20.0, top: 20.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: [
Text('Confirm Password'),
Row(
children: const [],
)
],
),
),
Padding(
padding: const EdgeInsets.only(
left: 15.0, right: 15.0, top: 10.0),
child: Container(
decoration: BoxDecoration(
borderRadius:
BorderRadius.circular(6),
border:
Border.all(color: Colors.grey)),
child: Padding(
padding: const EdgeInsets.only(
left: 5.0,
right: 5.0,
top: 12.0,
bottom: 12.0),
child: Stack(
children: [
TextFormField(
keyboardType:
TextInputType.visiblePassword,
validator: (value) {
if (value!.trim().isEmpty) {
return "This Field is required";
}
if (value != pWord) {
return "Confirmation password does not match with the entered password";
}
return null;
},
controller: confirmPassword,
obscureText: !_passwordVisible,
decoration:
InputDecoration.collapsed(
fillColor: Colors.white,
hintText:
"Confirm Password",
hintStyle: TextStyle(
color: Colors.grey)),
),
Positioned(
right: 0,
top: -10,
bottom: 0,
child: IconButton(
icon: Icon(
_passwordVisible
? Icons.visibility
: Icons.visibility_off,
),
onPressed: () {
setState(() {
_passwordVisible =
!_passwordVisible;
});
},
),
)
],
),
),
),
),
Padding(
padding: const EdgeInsets.only(
left: 20.0,
right: 20.0,
top: 20.0,
bottom: 30.0),
child: ConstrainedBox(
constraints: BoxConstraints.tightFor(
height: height * 0.060, width: width),
child: ElevatedButton(
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(
Colors.red),
),
onPressed: () {},
child: Text(
'SIGN UP ',
style: TextStyle(
fontSize: 16.0,
color: Colors.white),
),
),
),
),
Padding(
padding:
const EdgeInsets.only(bottom: 30.0),
child: Row(
mainAxisAlignment:
MainAxisAlignment.center,
children: [
Text(
'Already have account? ',
style: TextStyle(),
),
GestureDetector(
onTap: () {
Navigator.pop(context);
},
child: Text(
'Sign in',
style: TextStyle(
color: Colors.red,
decoration:
TextDecoration.underline,
),
),
)
],
),
)
],
),
),
),
],
),
),
),
),
),
],
),
),
),
);
}
}

Related

how can i make my code organised well and put some text after the sign in page or sign up

[enter image description here][1] [![enter image description here][1]][1] import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:ionicons/ionicons.dart';
void main() {
runApp(const MyApp((), key:,));
}
class MyApp extends StatelessWidget {
const MyApp(Type myApp, {required Key key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(primarySwatch: Colors.blue),
home: const SinginPage(key:,),
);
}
}
class SinginPage extends StatefulWidget {
const SinginPage({required Key key}) : super(key: key);
#override
_SinginPageState createState() => _SinginPageState();
}
class _SinginPageState extends State<SinginPage> {
bool obscureText = false;
final TextEditingController _email = TextEditingController();
final TextEditingController _password = TextEditingController();
final emailGlobalKey = GlobalKey<FormState>();
final passwordGlobalKey = GlobalKey<FormState>();
#override
Widget build(BuildContext context) {
var currentWidth = MediaQuery.of(context).size.width;
var small = currentWidth > 1201;
var extraSmall = currentWidth > 1025;
var Validators;
return Scaffold(
backgroundColor: Colors.white,
body: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: extraSmall ? MediaQuery.of(context).size.height : 0.0,
width: small
? MediaQuery.of(context).size.width * 0.72
: extraSmall
? MediaQuery.of(context).size.width - 500
: 0.0,
color: Colors.indigo[200],
child: Image.network(
'https://cdn.pixabay.com/photo/2021/10/11/13/12/website-6700615_960_720.png',
fit: BoxFit.cover,
),
),
Stack(
alignment: Alignment.topRight,
children: [
Container(
height: MediaQuery.of(context).size.height,
width: small ? MediaQuery.of(context).size.width * 0.28 : 500,
alignment: Alignment.center,
color: Colors.white,
child: Container(
padding: const EdgeInsets.all(60.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(height: 45.0),
Container(
alignment: Alignment.topLeft,
child: const Text(
'WELCOME BACK :)',
style: TextStyle(
color: Colors.black,
fontSize: 40.0,
fontWeight: FontWeight.bold),
),
),
const SizedBox(height: 65.0),
Container(
alignment: Alignment.topLeft,
child: const Text('Email'),
),
Form(
key: emailGlobalKey,
child: TextFormField(
onChanged: (value) {
setState(() {
_email.text = value;
});
},
decoration: const InputDecoration(
prefixIcon: Padding(
padding:
EdgeInsets.only(right: 20.0, bottom: 1.0),
child: Icon(Icons.email_outlined,
color: Colors.black45, size: 24.0),
),
contentPadding: EdgeInsets.only(top: 15.0, left: 0),
hintStyle: TextStyle(
fontWeight: FontWeight.normal,
color: Colors.grey),
hintText: 'Email',
focusedBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Colors.indigo, width: 2.0),
),
),
validator: Validators.required('Email is required!'),
),
),
const SizedBox(height: 25.0),
Container(
alignment: Alignment.topLeft,
child: const Text('Password'),
),
Form(
key: passwordGlobalKey,
child: TextFormField(
obscureText: obscureText,
onChanged: (value) {
setState(() {
_password.text = value;
});
},
decoration: InputDecoration(
suffixIcon: obscureText
? InkWell(
onTap: () {
setState(() {
obscureText = false;
});
},
child: const Icon(Ionicons.eye,
color: Colors.black54, size: 25.0),
)
: InkWell(
onTap: () {
setState(() {
obscureText = true;
});
},
child: const Icon(Ionicons.eye_off,
color: Colors.black54, size: 25.0),
),
prefixIcon: const Padding(
padding:
EdgeInsets.only(right: 20.0, bottom: 1.0),
child: Icon(Icons.lock_outline,
color: Colors.black45, size: 25.0),
),
contentPadding:
const EdgeInsets.only(top: 15.0, left: 0),
hintStyle: const TextStyle(
fontWeight: FontWeight.normal,
color: Colors.grey),
hintText: 'Password',
focusedBorder: const UnderlineInputBorder(
borderSide:
BorderSide(color: Colors.indigo, width: 2.0),
),
),
validator:
Validators.required('Password is required!'),
),
),
const SizedBox(height: 10.0),
Container(
alignment: Alignment.topRight,
child: TextButton(
style: TextButton.styleFrom(
padding: const EdgeInsets.all(0.0)),
onPressed: () {},
child: const Text('Forgot Password'),
)),
const SizedBox(
height: 50.0,
),
SizedBox(
height: 45.0,
width: MediaQuery.of(context).size.width,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: _password.text != ''
? _password.text != ''
? Colors.indigo
: Colors.indigo[300]
: Colors.indigo[300],
elevation: 0.0,
shadowColor: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50.0)),
padding: const EdgeInsets.only(
left: 30.0,
top: 0.0,
right: 30.0,
bottom: 0.0)),
onPressed: () {
emailGlobalKey.currentState?.validate();
passwordGlobalKey.currentState?.validate();
},
child: const Text('LOGIN',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold)),
),
),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 30.0, vertical: 30.0),
child: const Text('OR'),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
InkWell(
onTap: () {},
child: Padding(
padding: const EdgeInsets.only(right: 8.0),
child: Material(
color: Colors.indigo,
borderRadius: BorderRadius.circular(50.0),
child: const Padding(
padding: EdgeInsets.all(10.0),
child: Icon(
Ionicons.logo_facebook,
color: Colors.white,
size: 30.0,
),
),
),
),
),
InkWell(
onTap: () {},
child: Padding(
padding:
const EdgeInsets.only(left: 8.0, right: 8.0),
child: Material(
color: Colors.red,
borderRadius: BorderRadius.circular(50.0),
child: const Padding(
padding: EdgeInsets.all(10.0),
child: Icon(
Ionicons.logo_google,
color: Colors.white,
size: 30.0,
),
)),
),
),
InkWell(
onTap: () {},
child: Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Material(
color: Colors.blue,
borderRadius: BorderRadius.circular(50.0),
child: const Padding(
padding: EdgeInsets.all(10.0),
child: Icon(
Ionicons.logo_twitter,
color: Colors.white,
size: 30.0,
),
),
),
),
),
],
),
SizedBox(height: small ? 100.0 : 60.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text("I don't have an account?"),
TextButton(
onPressed: () {},
child: const Text(
"Sign up",
style: TextStyle(color: Colors.blue),
),
)
],
),
],
),
),
),
Container(
padding: const EdgeInsets.only(top: 30.0, right: 50),
child: Icon(Ionicons.settings_outline,
color: Colors.black12.withOpacity(0.03), size: 80.0),
),
],
),
],
),
);
}
}
** how can I make my code organized well and put some text after the sign in page or sign up as u see I have some errors here idk how will I organize my code to make it perfect so please anyone can help fixing the errors and let me do a text or a table like a market adds and let the code neatly and nice so I can understand where I can write a text or do a new cons and type what I want
well see now i have got an running issue problem I didn't get what u want to say**
You have a problem with they key
Try this:
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp((), key: UniqueKey(),));
}
class MyApp extends StatelessWidget {
const MyApp(Type myApp, {required Key key}) : super(key: key);
#override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(primarySwatch: Colors.blue),
home: SinginPage(key: UniqueKey()),
);
}
}
class SinginPage extends StatefulWidget {
const SinginPage({required Key key}) : super(key: key);
#override
_SinginPageState createState() => _SinginPageState();
}
class _SinginPageState extends State<SinginPage> {
bool obscureText = false;
final TextEditingController _email = TextEditingController();
final TextEditingController _password = TextEditingController();
final emailGlobalKey = GlobalKey<FormState>();
final passwordGlobalKey = GlobalKey<FormState>();
#override
Widget build(BuildContext context) {
var currentWidth = MediaQuery.of(context).size.width;
var small = currentWidth > 1201;
var extraSmall = currentWidth > 1025;
var Validators;
return Scaffold(
backgroundColor: Colors.white,
body: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Container(
height: extraSmall ? MediaQuery.of(context).size.height : 0.0,
width: small
? MediaQuery.of(context).size.width * 0.72
: extraSmall
? MediaQuery.of(context).size.width - 500
: 0.0,
color: Colors.indigo[200],
child: Image.network(
'https://cdn.pixabay.com/photo/2021/10/11/13/12/website-6700615_960_720.png',
fit: BoxFit.cover,
),
),
Stack(
alignment: Alignment.topRight,
children: [
Container(
height: MediaQuery.of(context).size.height,
width: small ? MediaQuery.of(context).size.width * 0.28 : 500,
alignment: Alignment.center,
color: Colors.white,
child: Container(
padding: const EdgeInsets.all(60.0),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const SizedBox(height: 45.0),
Container(
alignment: Alignment.topLeft,
child: const Text(
'WELCOME BACK :)',
style: TextStyle(
color: Colors.black,
fontSize: 40.0,
fontWeight: FontWeight.bold),
),
),
const SizedBox(height: 65.0),
Container(
alignment: Alignment.topLeft,
child: const Text('Email'),
),
Form(
key: emailGlobalKey,
child: TextFormField(
onChanged: (value) {
setState(() {
_email.text = value;
});
},
decoration: const InputDecoration(
prefixIcon: Padding(
padding:
EdgeInsets.only(right: 20.0, bottom: 1.0),
child: Icon(Icons.email_outlined,
color: Colors.black45, size: 24.0),
),
contentPadding: EdgeInsets.only(top: 15.0, left: 0),
hintStyle: TextStyle(
fontWeight: FontWeight.normal,
color: Colors.grey),
hintText: 'Email',
focusedBorder: UnderlineInputBorder(
borderSide:
BorderSide(color: Colors.indigo, width: 2.0),
),
),
validator: Validators.required('Email is required!'),
),
),
const SizedBox(height: 25.0),
Container(
alignment: Alignment.topLeft,
child: const Text('Password'),
),
Form(
key: passwordGlobalKey,
child: TextFormField(
obscureText: obscureText,
onChanged: (value) {
setState(() {
_password.text = value;
});
},
decoration: InputDecoration(
suffixIcon: obscureText
? InkWell(
onTap: () {
setState(() {
obscureText = false;
});
},
child: const Icon(Ionicons.eye,
color: Colors.black54, size: 25.0),
)
: InkWell(
onTap: () {
setState(() {
obscureText = true;
});
},
child: const Icon(Ionicons.eye_off,
color: Colors.black54, size: 25.0),
),
prefixIcon: const Padding(
padding:
EdgeInsets.only(right: 20.0, bottom: 1.0),
child: Icon(Icons.lock_outline,
color: Colors.black45, size: 25.0),
),
contentPadding:
const EdgeInsets.only(top: 15.0, left: 0),
hintStyle: const TextStyle(
fontWeight: FontWeight.normal,
color: Colors.grey),
hintText: 'Password',
focusedBorder: const UnderlineInputBorder(
borderSide:
BorderSide(color: Colors.indigo, width: 2.0),
),
),
validator:
Validators.required('Password is required!'),
),
),
const SizedBox(height: 10.0),
Container(
alignment: Alignment.topRight,
child: TextButton(
style: TextButton.styleFrom(
padding: const EdgeInsets.all(0.0)),
onPressed: () {},
child: const Text('Forgot Password'),
)),
const SizedBox(
height: 50.0,
),
SizedBox(
height: 45.0,
width: MediaQuery.of(context).size.width,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
primary: _password.text != ''
? _password.text != ''
? Colors.indigo
: Colors.indigo[300]
: Colors.indigo[300],
elevation: 0.0,
shadowColor: Colors.transparent,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50.0)),
padding: const EdgeInsets.only(
left: 30.0,
top: 0.0,
right: 30.0,
bottom: 0.0)),
onPressed: () {
emailGlobalKey.currentState?.validate();
passwordGlobalKey.currentState?.validate();
},
child: const Text('LOGIN',
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold)),
),
),
Container(
padding: const EdgeInsets.symmetric(
horizontal: 30.0, vertical: 30.0),
child: const Text('OR'),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
InkWell(
onTap: () {},
child: Padding(
padding: const EdgeInsets.only(right: 8.0),
child: Material(
color: Colors.indigo,
borderRadius: BorderRadius.circular(50.0),
child: const Padding(
padding: EdgeInsets.all(10.0),
child: Icon(
Ionicons.logo_facebook,
color: Colors.white,
size: 30.0,
),
),
),
),
),
InkWell(
onTap: () {},
child: Padding(
padding:
const EdgeInsets.only(left: 8.0, right: 8.0),
child: Material(
color: Colors.red,
borderRadius: BorderRadius.circular(50.0),
child: const Padding(
padding: EdgeInsets.all(10.0),
child: Icon(
Ionicons.logo_google,
color: Colors.white,
size: 30.0,
),
)),
),
),
InkWell(
onTap: () {},
child: Padding(
padding: const EdgeInsets.only(left: 8.0),
child: Material(
color: Colors.blue,
borderRadius: BorderRadius.circular(50.0),
child: const Padding(
padding: EdgeInsets.all(10.0),
child: Icon(
Ionicons.logo_twitter,
color: Colors.white,
size: 30.0,
),
),
),
),
),
],
),
SizedBox(height: small ? 100.0 : 60.0),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
const Text("I don't have an account?"),
TextButton(
onPressed: () {},
child: const Text(
"Sign up",
style: TextStyle(color: Colors.blue),
),
)
],
),
],
),
),
),
Container(
padding: const EdgeInsets.only(top: 30.0, right: 50),
child: Icon(
Ionicons.settings_outline,
color: Colors.black12.withOpacity(0.03),
size: 80.0,
),
),
],
),
],
),
);
}
}

RenderCustomMultiChildLayoutBox object was given an infinite size during layout error

I keep getting the error as mentioned when I try to load LessonPage. What is happening is that I have a RootPage which checks if a user is signed in, if he is the RootPage will show the LessonPage but if he is not, it will show the LoginScreen which when the user logs in, will invoke a callback function to RootPage _onLoggedIn()so as to switch pages to the LessonPage.
Update: I found out that the error is also logged when I load the app (i.e. the app opens to a LoginScreen), however I see my login screen instead of a blank screen. I've appended my LoginScreen code below for reference
Root Page:
class RootPage extends StatefulWidget {
RootPage({this.auth});
final BaseAuth auth;
#override
State<StatefulWidget> createState() => new _RootPageState();
}
enum AuthStatus {
NOT_DETERMINED,
NOT_LOGGED_IN,
LOGGED_IN,
}
class _RootPageState extends State<RootPage> {
AuthStatus authStatus = AuthStatus.NOT_DETERMINED;
String _userId = "";
#override
void initState() {
super.initState();
widget.auth.getCurrentUser().then((user) {
setState(() {
if (user != null) {
_userId = user?.uid;
}
authStatus =
user?.uid == null ? AuthStatus.NOT_LOGGED_IN : AuthStatus.LOGGED_IN;
});
});
}
void _onLoggedIn() {
widget.auth.getCurrentUser().then((user){
setState(() {
_userId = user.uid.toString();
});
});
setState(() {
authStatus = AuthStatus.LOGGED_IN;
});
}
void _onSignedOut() {
setState(() {
authStatus = AuthStatus.NOT_LOGGED_IN;
_userId = "";
});
}
Widget _buildWaitingScreen() {
return Scaffold(
body: Container(
alignment: Alignment.center,
child:
ColorLoader5(
dotOneColor: Colors.blueGrey[600],
dotTwoColor: Colors.blueGrey[700],
dotThreeColor: Colors.blueGrey[800],
dotType: DotType.circle,
dotIcon: Icon(Icons.adjust),
duration: Duration(seconds: 1),
),
),
);
}
#override
Widget build(BuildContext context) {
switch (authStatus) {
case AuthStatus.NOT_DETERMINED:
return _buildWaitingScreen();
break;
case AuthStatus.NOT_LOGGED_IN:
return new LoginScreen(
auth: widget.auth,
onSignedIn: _onLoggedIn,
);
break;
case AuthStatus.LOGGED_IN:
if (_userId.length > 0 && _userId != null) {
return new Container(child: SingleChildScrollView(child: LessonPage(
title: LESSON_PAGE_TITLE,
userId: _userId,
auth: widget.auth,
onSignedOut: _onSignedOut,
)));
} else return _buildWaitingScreen();
break;
default:
return _buildWaitingScreen();
}
}
}
Lesson Page:
class LessonPage extends StatefulWidget {
LessonPage({Key key, this.auth, this.userId, this.onSignedOut, this.title}) : super(key: key);
final String title;
final BaseAuth auth;
final VoidCallback onSignedOut;
final String userId;
#override
_LessonPageState createState() => _LessonPageState();
}
class _LessonPageState extends State<LessonPage> {
List lessons;
#override
void initState() {
lessons = StaticMethods.getLessons();
super.initState();
}
#override
Widget build(BuildContext context) {
ListTile makeListTile(Lesson lesson) => ListTile(
contentPadding:
EdgeInsets.symmetric(horizontal: 20.0, vertical: 10.0),
leading: Container(
padding: EdgeInsets.only(right: 12.0),
decoration: new BoxDecoration(
border: new Border(
right: new BorderSide(width: 1.0, color: Colors.white24))),
child: IconButton(
icon: Icon(Icons.file_download, color: Colors.white),
onPressed: (){},
),
),
title: Text(
lesson.title,
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
),
subtitle: Row(
children: <Widget>[
Expanded(
flex: 1,
child: Container(
child: LinearProgressIndicator(
backgroundColor: Color.fromRGBO(209, 224, 224, 0.2),
value: lesson.indicatorValue,
valueColor: AlwaysStoppedAnimation(Colors.green)),
)),
Expanded(
flex: 4,
child: Padding(
padding: EdgeInsets.only(left: 10.0),
child: Text(lesson.level,
style: TextStyle(color: Colors.white))),
)
],
),
trailing:
Icon(Icons.keyboard_arrow_right, color: Colors.white, size: 30.0),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => DetailPage(lesson: lesson)));
},
);
Card makeCard(Lesson lesson) => Card(
elevation: 8.0,
margin: new EdgeInsets.symmetric(horizontal: 10.0, vertical: 6.0),
child: Container(
decoration: BoxDecoration(color: Color.fromRGBO(64, 75, 96, .9)),
child: makeListTile(lesson),
),
);
final makeBody = Container(
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: lessons.length,
itemBuilder: (BuildContext context, int index) {
return makeCard(lessons[index]);
},
),
);
final makeBottom = Container(
height: 55.0,
child: BottomAppBar(
color: Color.fromRGBO(58, 66, 86, 1.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
IconButton(
icon: Icon(Icons.school, color: Colors.white),
onPressed: () => StaticMethods.goToWidget(context, new LessonPage(title: LESSON_PAGE_TITLE)),
),
IconButton(
icon: Icon(Icons.flight_takeoff, color: Colors.white),
onPressed: () {},
),
IconButton(
icon: Icon(Icons.account_box, color: Colors.white),
onPressed: () {},
)
],
),
),
);
final topAppBar = AppBar(
elevation: 0.1,
backgroundColor: Color.fromRGBO(58, 66, 86, 1.0),
title: Text(widget.title),
automaticallyImplyLeading: false,
);
return Scaffold(
backgroundColor: Color.fromRGBO(58, 66, 86, 1.0),
appBar: topAppBar,
body: makeBody,
bottomNavigationBar: makeBottom,
);
}
}
LoginScreen Containers:
Widget OptionPage() {
return new Container(
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
color: Color.fromRGBO(58, 66, 86, 1.0),
image: DecorationImage(
colorFilter: new ColorFilter.mode(
Colors.black.withOpacity(0.1), BlendMode.dstATop),
image: AssetImage('assets/images/drones.jpg'),
fit: BoxFit.cover,
),
),
child: new Column(
children: <Widget>[
Container(
padding: EdgeInsets.only(top: 250.0),
child: Center(
child: Icon(
Icons.school,
color: Colors.white,
size: 40.0,
),
),
),
Container(
padding: EdgeInsets.only(top: 20.0),
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
LOGIN_SCREEN_TITLE,
style: TextStyle(
color: Colors.white,
fontSize: 20.0,
),
),
],
),
),
new Container(
width: MediaQuery.of(context).size.width,
margin: const EdgeInsets.only(left: 30.0, right: 30.0, top: 150.0),
alignment: Alignment.center,
child: new Row(
children: <Widget>[
new Expanded(
child: new OutlineButton(
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0)),
color: Color.fromRGBO(58, 66, 86, 1.0),
highlightedBorderColor: Colors.white,
onPressed: () => gotoSignup(),
child: new Container(
padding: const EdgeInsets.symmetric(
vertical: 20.0,
horizontal: 20.0,
),
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Expanded(
child: Text(
LOGIN_SCREEN_SIGN_UP,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
),
),
],
),
),
),
),
],
),
),
new Container(
width: MediaQuery.of(context).size.width,
margin: const EdgeInsets.only(left: 30.0, right: 30.0, top: 30.0),
alignment: Alignment.center,
child: new Row(
children: <Widget>[
new Expanded(
child: new FlatButton(
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0)),
color: Colors.white,
onPressed: () => gotoLogin(),
child: new Container(
padding: const EdgeInsets.symmetric(
vertical: 20.0,
horizontal: 20.0,
),
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Expanded(
child: Text(
LOGIN_SCREEN_LOGIN,
textAlign: TextAlign.center,
style: TextStyle(
color: Color.fromRGBO(58, 66, 86, 1.0),
fontWeight: FontWeight.bold),
),
),
],
),
),
),
),
],
),
),
],
),
);
}
Widget LoginPage() {
return new Container(
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
color: Colors.white,
image: DecorationImage(
colorFilter: new ColorFilter.mode(
Colors.black.withOpacity(0.05), BlendMode.dstATop),
image: AssetImage('assets/images/drones.jpg'),
fit: BoxFit.cover,
),
),
child: new Column(
children: <Widget>[
Container(
padding: EdgeInsets.all(120.0),
child: Center(
child: Icon(
Icons.school,
color: Color.fromRGBO(58, 66, 86, 1.0),
size: 50.0,
),
),
),
new Row(
children: <Widget>[
new Expanded(
child: new Padding(
padding: const EdgeInsets.only(left: 40.0),
child: new Text(
LOGIN_SCREEN_EMAIL,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Color.fromRGBO(58, 66, 86, 1.0),
fontSize: 15.0,
),
),
),
),
],
),
new Container(
width: MediaQuery.of(context).size.width,
margin: const EdgeInsets.only(left: 40.0, right: 40.0, top: 10.0),
alignment: Alignment.center,
padding: const EdgeInsets.only(left: 0.0, right: 10.0),
child: new Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
new Expanded(
child: TextFormField( // LOGIN SCREEN EMAIL
maxLines: 1,
keyboardType: TextInputType.emailAddress,
autofocus: false,
textAlign: TextAlign.left,
decoration: InputDecoration(
icon: Icon(Icons.alternate_email),
hintText: LOGIN_SCREEN_EMAIL_HINT,
hintStyle: TextStyle(color: Colors.grey),
),
validator: (value) => value.isEmpty ? LOGIN_SCREEN_EMAIL_WARNING : null,
onSaved: (value) => _email = value,
),
),
],
),
),
Divider(
height: 24.0,
color: Color(0x00000000),
),
new Row(
children: <Widget>[
new Expanded(
child: new Padding(
padding: const EdgeInsets.only(left: 40.0),
child: new Text(
LOGIN_SCREEN_PASSWORD,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Color.fromRGBO(58, 66, 86, 1.0),
fontSize: 15.0,
),
),
),
),
],
),
new Container(
width: MediaQuery.of(context).size.width,
margin: const EdgeInsets.only(left: 40.0, right: 40.0, top: 10.0),
alignment: Alignment.center,
padding: const EdgeInsets.only(left: 0.0, right: 10.0),
child: new Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
new Expanded(
child: TextFormField( // LOGIN SCREEN PASSWORD
obscureText: true,
keyboardType: TextInputType.emailAddress,
maxLines: 1,
autofocus: false,
textAlign: TextAlign.left,
decoration: InputDecoration(
icon: Icon(Icons.lock_outline),
hintText: LOGIN_SCREEN_PASSWORD_HINT,
hintStyle: TextStyle(color: Colors.grey),
),
validator: (value) => value.isEmpty ? LOGIN_SCREEN_PASSWORD_WARNING : null,
onSaved: (value) => _password = value,
),
),
],
),
),
Divider(
height: 24.0,
color: Color(0x00000000),
),
new Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 20.0),
child: new FlatButton(
child: new Text(
LOGIN_SCREEN_FORGOT_PASSWORD,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Color.fromRGBO(58, 66, 86, 1.0),
fontSize: 15.0,
),
textAlign: TextAlign.end,
),
onPressed: () => StaticMethods.locked(context),
),
),
],
),
new Container(
width: MediaQuery.of(context).size.width,
margin: const EdgeInsets.only(left: 30.0, right: 30.0, top: 20.0),
alignment: Alignment.center,
child: new Row(
children: <Widget>[
new Expanded(
child: new FlatButton( // LOGIN SCREEN LOGIN BUTTON
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0),
),
color: Color.fromRGBO(58, 66, 86, 1.0),
onPressed: () => _validateAndSubmit(),
child: new Container(
padding: const EdgeInsets.symmetric(
vertical: 20.0,
horizontal: 20.0,
),
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Expanded(
child: Text(
LOGIN_SCREEN_LOGIN,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
),
),
],
),
),
),
),
],
),
),
Divider(
height: 25.0,
color: Color(0x00000000),
),
_showErrorMessage(),
Divider(
height: 25.0,
color: Color(0x00000000),
),
_showLoading(),
],
),
);
}
Widget SignupPage() {
return new Container(
height: MediaQuery.of(context).size.height,
decoration: BoxDecoration(
color: Colors.white,
image: DecorationImage(
colorFilter: new ColorFilter.mode(
Colors.black.withOpacity(0.05), BlendMode.dstATop),
image: AssetImage('assets/images/drones.jpg'),
fit: BoxFit.cover,
),
),
child: new Column(
children: <Widget>[
Container(
padding: EdgeInsets.all(100.0),
child: Center(
child: Icon(
Icons.school,
color: Color.fromRGBO(58, 66, 86, 1.0),
size: 50.0,
),
),
),
new Row(
children: <Widget>[
new Expanded(
child: new Padding(
padding: const EdgeInsets.only(left: 40.0),
child: new Text(
LOGIN_SCREEN_EMAIL,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Color.fromRGBO(58, 66, 86, 1.0),
fontSize: 15.0,
),
),
),
),
],
),
new Container(
width: MediaQuery.of(context).size.width,
margin: const EdgeInsets.only(left: 40.0, right: 40.0, top: 10.0),
alignment: Alignment.center,
padding: const EdgeInsets.only(left: 0.0, right: 10.0),
child: new Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
new Expanded(
child: TextField( //SIGNUP SCREEN EMAIL
obscureText: true,
textAlign: TextAlign.left,
decoration: InputDecoration(
hintText: LOGIN_SCREEN_EMAIL_HINT,
hintStyle: TextStyle(color: Colors.grey),
),
),
),
],
),
),
Divider(
height: 24.0,
color: Color(0x00000000),
),
new Row(
children: <Widget>[
new Expanded(
child: new Padding(
padding: const EdgeInsets.only(left: 40.0),
child: new Text(
LOGIN_SCREEN_PASSWORD,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Color.fromRGBO(58, 66, 86, 1.0),
fontSize: 15.0,
),
),
),
),
],
),
new Container(
width: MediaQuery.of(context).size.width,
margin: const EdgeInsets.only(left: 40.0, right: 40.0, top: 10.0),
alignment: Alignment.center,
padding: const EdgeInsets.only(left: 0.0, right: 10.0),
child: new Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
new Expanded(
child: TextField( // SIGNUP SCREEN PASSWORD
obscureText: true,
textAlign: TextAlign.left,
decoration: InputDecoration(
hintText: LOGIN_SCREEN_PASSWORD_HINT,
hintStyle: TextStyle(color: Colors.grey),
),
),
),
],
),
),
Divider(
height: 24.0,
color: Color(0x00000000),
),
new Row(
children: <Widget>[
new Expanded(
child: new Padding(
padding: const EdgeInsets.only(left: 40.0),
child: new Text( // SIGNUP SCREEN CONFIRM PASSWORD
LOGIN_SCREEN_CONFIRM_PASSWORD,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Color.fromRGBO(58, 66, 86, 1.0),
fontSize: 15.0,
),
),
),
),
],
),
new Container(
width: MediaQuery.of(context).size.width,
margin: const EdgeInsets.only(left: 40.0, right: 40.0, top: 10.0),
alignment: Alignment.center,
padding: const EdgeInsets.only(left: 0.0, right: 10.0),
child: new Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
new Expanded(
child: TextField(
obscureText: true,
textAlign: TextAlign.left,
decoration: InputDecoration(
hintText: LOGIN_SCREEN_PASSWORD_HINT,
hintStyle: TextStyle(color: Colors.grey),
),
),
),
],
),
),
Divider(
height: 24.0,
color: Color(0x00000000),
),
new Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Padding(
padding: const EdgeInsets.only(right: 20.0),
child: new FlatButton(
child: new Text(
LOGIN_SCREEN_HAVE_ACCOUNT,
style: TextStyle(
fontWeight: FontWeight.bold,
color: Color.fromRGBO(58, 66, 86, 1.0),
fontSize: 15.0,
),
textAlign: TextAlign.end,
),
onPressed: () => StaticMethods.locked(context),
),
),
],
),
new Container(
width: MediaQuery.of(context).size.width,
margin: const EdgeInsets.only(left: 30.0, right: 30.0, top: 50.0),
alignment: Alignment.center,
child: new Row(
children: <Widget>[
new Expanded(
child: new FlatButton( // SIGNUP SCREEN SIGN UP BUTTON
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(30.0),
),
color: Color.fromRGBO(58, 66, 86, 1.0),
onPressed: () => StaticMethods.locked(context),
child: new Container(
padding: const EdgeInsets.symmetric(
vertical: 20.0,
horizontal: 20.0,
),
child: new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Expanded(
child: Text(
LOGIN_SCREEN_SIGN_UP,
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontWeight: FontWeight.bold),
),
),
],
),
),
),
),
],
),
),
],
),
);
}
PageController _controller = new PageController(initialPage: 1, viewportFraction: 1.0);
#override
Widget build(BuildContext context) {
_isIos = Theme.of(context).platform == TargetPlatform.iOS;
return Container(
height: MediaQuery.of(context).size.height,
width: MediaQuery.of(context).size.width,
child: new Form (
key: _formKey,
child: PageView(
controller: _controller,
physics: new AlwaysScrollableScrollPhysics(),
children: <Widget>[LoginPage(), OptionPage(), SignupPage()],
scrollDirection: Axis.horizontal,
onPageChanged: (num){
switch (num) {
case 0:
setState(() {
_formKey.currentState.reset();
_errorMessage = "";
_formMode = FormMode.LOGIN;
});
break;
case 1:
setState(() {
_formKey.currentState.reset();
_errorMessage = "";
_formMode = FormMode.OPTIONS;
});
break;
case 2:
setState(() {
_formKey.currentState.reset();
_errorMessage = "";
_formMode = FormMode.SIGNUP;
});
break;
}
},
),
),
);
}
Error:
I/flutter (18510): The following assertion was thrown during performLayout():
I/flutter (18510): RenderCustomMultiChildLayoutBox object was given an infinite size during layout.
.....
In the error, it shows just a blank page instead of lesson page, and checking firebase I can see that a user logs in so I think it is some layout issue.
What I've tried:
RootPage (I still saw a blank screen):
return new LessonPage(
title: LESSON_PAGE_TITLE,
userId: _userId,
auth: widget.auth,
onSignedOut: _onSignedOut,
);
I tried to return a normal page instead of lesson page which just shows a loading animation which is already tested and works but still I see a blank page:
return _buildWaitingScreen();
LessonPage (still see blank page):
Widget makeBody(BuildContext context) => Container(
height: MediaQuery.of(context).size.height / 1.5,
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: lessons.length,
itemBuilder: (BuildContext context, int index) {
return makeCard(lessons[index]);
},
),
);
return Scaffold(
backgroundColor: Color.fromRGBO(58, 66, 86, 1.0),
appBar: topAppBar,
body: makeBody(context),
bottomNavigationBar: makeBottom,
);
You dont need Container and SingleChildScrollView in below snippet:
return LessonPage(
title: LESSON_PAGE_TITLE,
userId: _userId,
auth: widget.auth,
onSignedOut: _onSignedOut,
);
If that didn't fix,
RenderCustomMultiChildLayoutBox object was given an infinite size during layout. means that you have used ListView or ScrollView or any other widget that has infinite size. In order to prevent this issue, wrap your makeBody list view with fixed size. If it is working you can use MediaQuery.of(context).size.height(gives device screen width) and adjest the size you want.
Ex:
Widget makeBody(BuildContext context) => Container(
height: MediaQuery.of(context).size.height / 1.5,
child: ListView.builder(
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemCount: lessons.length,
itemBuilder: (BuildContext context, int index) {
return makeCard(lessons[index]);
},
),
);
and call the method: body: makeBody(context),
Fix in RootPage:
return new Container(
height: MediaQuery.of(context).size.height,
child: LessonPage(
title: LESSON_PAGE_TITLE,
userId: _userId,
auth: widget.auth,
onSignedOut: _onSignedOut,
)
);

Huge space between list view and other widgets

I have a container contains a column of containers and listviews .. in this way: 1. container 2. listview 3. container 4. listview ... I did it this way:
Container(
color: Colors.white,
child: Stack(
overflow: Overflow.visible,
children: <Widget>[
new Column(
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Container(
child: Padding(
padding: EdgeInsets.only(
right: 20.0, left: 20.0, top: 5.0, bottom: 5.0),
child: new Text(
"header1",
),
),
color: Color(0xfff8f8f8),
),
Expanded(
child: ListView.builder(
itemCount: titles.length,
itemBuilder: (BuildContext context, int index) {
return new Padding(
padding: EdgeInsets.only(
left: 20.0, right: 20.0, top: 15.0),
child: .......
);
},
),
),
Container(
child: Padding(
padding: EdgeInsets.only(
right: 20.0, left: 20.0, top: 5.0, bottom: 5.0),
child: new Text(
"header2",
),
),
color: Color(0xfff8f8f8),
),
Expanded(
child: ListView.builder(
itemCount: titles.length,
itemBuilder: (BuildContext context, int index) {
return new Padding(
padding: EdgeInsets.only(
left: 0.0, right: 0.0, top: 0.0),
child: .....
);
},
),
),
],
),
],
),
),
i can't remove Expanded from the listview .. if i did the list view will not appear inside the column ..
Also, I tried to use Flexible but the same problem is there ..
this does what i need .. but there's a huge space between the first listview and the second container .. how to remove this empty space and make the listview height wrap depending on the height of the content?
Try this code
ListView(
shrinkWrap: true,
children: <Widget>[
Container(
child: Padding(
padding: EdgeInsets.only(
right: 20.0, left: 20.0, top: 5.0, bottom: 5.0),
child: new Text(
"header1",
),
),
color: Color(0xfff8f8f8),
),
ListView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: titles.length,
itemBuilder: (BuildContext context, int index) {
return new Padding(
padding: EdgeInsets.only(
left: 20.0, right: 20.0, top: 15.0),
child: ListTile(title: Text(titles[index]),)
);
},
),
Container(
child: Padding(
padding: EdgeInsets.only(
right: 20.0, left: 20.0, top: 5.0, bottom: 5.0),
child: new Text(
"header2",
),
),
color: Color(0xfff8f8f8),
),
ListView.builder(
physics: NeverScrollableScrollPhysics(),
shrinkWrap: true,
itemCount: titles.length,
itemBuilder: (BuildContext context, int index) {
return new Padding(
padding: EdgeInsets.only(
left: 0.0, right: 0.0, top: 0.0),
child: ListTile(title: Text(titles[index]),)
);
},
),
],
),

How to display data under padding in flutter?

Map item;
List data;
Future getdata() async{
http.Response response= await http.get(Uri.encodeFull("https://talaikis.com/api/quotes/"));
item=json.decode(response.body);
setState(() {
data=item["quotes"];
});
debugPrint(data.toString());
}
I want to display this request in stateful widget which is like this
#override
Widget build(BuildContext context) {
return new Scaffold(
drawer: drawerLeft(),
appBar: AppBar(
title: Text(
"IN TIME",
style: TextStyle(color: Colors.black, fontWeight: FontWeight.w700),
),
backgroundColor: clr,
elevation: 0.0,
leading: MaterialButton(
child: Icon(
Icons.view_headline,
color: Colors.black,
),
onPressed: () {
scaffoldKey.currentState.openDrawer();
},
)),
key: scaffoldKey,
body: AnimatedContainer(
padding: EdgeInsets.only(top: 50.0),
duration: Duration(milliseconds: 1000),
curve: Curves.ease,
color: clr,
child: PageView.builder(
itemCount: 7, //7days
onPageChanged: (int page) {
this.setState(() {
Random rnd;
rnd = new Random();
int r = 0 + rnd.nextInt(_colors.length - 0);
clr = _colors[r];
});
},
controller: pageViewController,
itemBuilder: (BuildContext context, int index) {
return Padding(
padding: const EdgeInsets.only(left: 10.0),
child: Stack(
children: <Widget>[
Container(
decoration: new BoxDecoration(
borderRadius: BorderRadius.circular(20.0),
color: Colors.white,
),
height:
MediaQuery.of(scaffoldKey.currentContext).size.height -
150.0,
width:
MediaQuery.of(scaffoldKey.currentContext).size.width -
20.0,
child: Stack(
children: <Widget>[
Positioned(
width: MediaQuery.of(scaffoldKey.currentContext)
.size
.width -
100.0,
left: index != currentPage
? getMappedValue(20.0, 100.0, 160.0, 20.0, pos)
: getMappedValue(20.0, 100.0, 20.0, -120.0, pos),
top: 20.0,
child: Opacity(
opacity: index != currentPage
? getMappedValue(20.0, 100.0, 0.0, 01.0, pos)
: getMappedValue(20.0, 100.0, 01.0, 00.0, pos),
child: Column(
children: <Widget>[
Row(
mainAxisAlignment:
MainAxisAlignment.spaceBetween,
children: <Widget>[
Text(
_days[index],
maxLines: 1,
softWrap: true,
style: TextStyle(
color: Colors.deepOrange,
fontSize: 22.0,
fontWeight: FontWeight.w600),
),
],
),
Padding(
padding: const EdgeInsets.only(top: 15.0),
child: Text(
'Quote for the day',
softWrap: true,
style: TextStyle(
fontSize: 30.0,
fontWeight: FontWeight.w300),
),
),
],
),
),
),
],
),
),
],
),
);
},
),
),
);
}
}
*Please help me out *
If I understand, you want to display the quotes under some padding that are being retrieved to your List which I'll assume to be an inferenced List<String>. If so, you could just use a ListView within your widget tree to display every fetched item in that list, like so:
(...)
data != null
? Padding(
padding: const EdgeInsets.only(top: 15.0),
child: ListView.builder(
itemCount: data.length,
itemBuilder: (BuildContext context, int index) {
return ListTile(
title: Text(data[index]),
);
},
),
)
: Container(),
(...)

How to set the text value dynamically from the json in flutter

Hi friends how to set the text value dynamically I am using the JSON to get the data but when I refresh the data is populating and I am calling the JSON at initstate to per load before the page of the app starts sorry friends I don't know much about the flutter so please help me out about it please find the code below
String name, userimage, birth, c_id, email, mobile_number;
class Profile extends StatefulWidget {
#override
State<StatefulWidget> createState() {
Profile_Customer profile_customer() => Profile_Customer();
return profile_customer();
}
}
class Profile_Customer extends State<Profile> {
#override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text('Profile'),
backgroundColor: primarycolor,
leading: new IconButton(
icon: new Icon(Icons.arrow_back),
onPressed: () {
Navigator.pushReplacement(
context,
new MaterialPageRoute(
builder: (context) => new HomeScreen()));
}),
),
body: new Builder(builder: (BuildContext context) {
return new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Container(
child: new Image.asset('assets/rural_post_logo.png',
fit: BoxFit.cover),
margin: EdgeInsets.only(bottom: 15.0),
),
new Container(
child: new CircleAvatar(
child: new Image.network(userimage,
width: 100.0, height: 100.0, fit: BoxFit.cover),
),
margin: EdgeInsets.only(top: 10.0),
alignment: Alignment(0.0, 0.0),
),
new Container(
child: new Text(name),
margin: EdgeInsets.only(top: 10.0),
),
new Container(
child: new Divider(
height: 2.0,
color: primarycolor,
),
margin: EdgeInsets.only(right: 10.0, left: 10.0, top: 10.0),
),
new Container(
child: new Text(
'Birth Date',
style: new TextStyle(
fontWeight: FontWeight.bold, fontSize: 16.0),
),
alignment: Alignment(-1.0, 0.0),
margin: EdgeInsets.only(top: 10.0, left: 10.0),
),
new Container(
child: new Text(birth),
alignment: Alignment(-1.0, 0.0),
margin: EdgeInsets.only(top: 10.0, left: 10.0),
),
new Container(
child: new Divider(
height: 2.0,
color: primarycolor,
),
margin: EdgeInsets.only(right: 10.0, left: 10.0, top: 10.0),
),
new Container(
child: new Text(
'Customer ID',
style: new TextStyle(
fontWeight: FontWeight.bold, fontSize: 16.0),
),
alignment: Alignment(-1.0, 0.0),
margin: EdgeInsets.only(top: 10.0, left: 10.0),
),
new Container(
child: new Text(c_id),
alignment: Alignment(-1.0, 0.0),
margin: EdgeInsets.only(top: 10.0, left: 10.0),
),
new Container(
child: new Divider(
height: 2.0,
color: primarycolor,
),
margin: EdgeInsets.only(right: 10.0, left: 10.0, top: 10.0),
),
new Container(
child: new Text(
'Email',
style: new TextStyle(
fontWeight: FontWeight.bold, fontSize: 16.0),
),
alignment: Alignment(-1.0, 0.0),
margin: EdgeInsets.only(top: 10.0, left: 10.0),
),
new Container(
child: new Text(email),
alignment: Alignment(-1.0, 0.0),
margin: EdgeInsets.only(top: 10.0, left: 10.0),
),
new Container(
child: new Divider(
height: 2.0,
color: primarycolor,
),
margin: EdgeInsets.only(right: 10.0, left: 10.0, top: 10.0),
),
new Container(
child: new Text(
'Mobile number',
style: new TextStyle(
fontWeight: FontWeight.bold, fontSize: 16.0),
),
alignment: Alignment(-1.0, 0.0),
margin: EdgeInsets.only(top: 10.0, left: 10.0),
),
new Container(
child: new Text(mobile_number),
alignment: Alignment(-1.0, 0.0),
margin: EdgeInsets.only(top: 10.0, left: 10.0),
),
new Container(
child: new RaisedButton(
onPressed: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => new HomeScreen()));
},
color: secondarycolor,
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(5.0)),
child: new Text('Update Profile',
style: new TextStyle(color: Colors.white)),
),
width: 300.0,
height: 40.0,
margin: EdgeInsets.only(top: 10.0),
)
],
);
}),
),
);
}
#override
void initState() {
super.initState();
profilejson();
}
}
void profilejson() async {
SharedPreferences pref = await SharedPreferences.getInstance();
var profile_url = url + "view_profile&userid=" + pref.getString('userid');
print(profile_url);
http.Response profileresponse = await http.get(profile_url);
var profile_response_json = json.decode(profileresponse.body);
name = profile_response_json['username'];
userimage = profile_response_json['image'];
birth = profile_response_json['dob'];
c_id = profile_response_json['customerid'];
email = profile_response_json['email'];
mobile_number = profile_response_json['phone'];
}
You can accomplish that with a StatefulWidget and setState to make the layout change on the go. As you already have the widget in your code you should simply call setState were you set your variables. Also the profilejson() should we within the state:
...
profilejson() async {
SharedPreferences pref = await SharedPreferences.getInstance();
var profile_url = url + "view_profile&userid=" + pref.getString('userid');
print(profile_url);
http.Response profileresponse = await http.get(profile_url);
var profile_response_json = json.decode(profileresponse.body);
// the variables you want the layout to be updated with
setState(() {
name = profile_response_json['username'];
userimage = profile_response_json['image'];
birth = profile_response_json['dob'];
c_id = profile_response_json['customerid'];
email = profile_response_json['email'];
mobile_number = profile_response_json['phone'];
})
}
#override
void initState() {
super.initState();
profilejson();
}
...
Full code:
String name, userimage, birth, c_id, email, mobile_number;
class Profile extends StatefulWidget {
#override
State<StatefulWidget> createState() {
Profile_Customer profile_customer() => Profile_Customer();
return profile_customer();
}
}
class Profile_Customer extends State<Profile> {
#override
Widget build(BuildContext context) {
return new MaterialApp(
home: new Scaffold(
appBar: new AppBar(
title: new Text('Profile'),
backgroundColor: primarycolor,
leading: new IconButton(
icon: new Icon(Icons.arrow_back),
onPressed: () {
Navigator.pushReplacement(
context,
new MaterialPageRoute(
builder: (context) => new HomeScreen()));
}),
),
body: email != null ? new Builder(builder: (BuildContext context) {
return new Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Container(
child: new Image.asset('assets/rural_post_logo.png',
fit: BoxFit.cover),
margin: EdgeInsets.only(bottom: 15.0),
),
new Container(
child: new CircleAvatar(
child: new Image.network(userimage,
width: 100.0, height: 100.0, fit: BoxFit.cover),
),
margin: EdgeInsets.only(top: 10.0),
alignment: Alignment(0.0, 0.0),
),
new Container(
child: new Text(name),
margin: EdgeInsets.only(top: 10.0),
),
new Container(
child: new Divider(
height: 2.0,
color: primarycolor,
),
margin: EdgeInsets.only(right: 10.0, left: 10.0, top: 10.0),
),
new Container(
child: new Text(
'Birth Date',
style: new TextStyle(
fontWeight: FontWeight.bold, fontSize: 16.0),
),
alignment: Alignment(-1.0, 0.0),
margin: EdgeInsets.only(top: 10.0, left: 10.0),
),
new Container(
child: new Text(birth),
alignment: Alignment(-1.0, 0.0),
margin: EdgeInsets.only(top: 10.0, left: 10.0),
),
new Container(
child: new Divider(
height: 2.0,
color: primarycolor,
),
margin: EdgeInsets.only(right: 10.0, left: 10.0, top: 10.0),
),
new Container(
child: new Text(
'Customer ID',
style: new TextStyle(
fontWeight: FontWeight.bold, fontSize: 16.0),
),
alignment: Alignment(-1.0, 0.0),
margin: EdgeInsets.only(top: 10.0, left: 10.0),
),
new Container(
child: new Text(c_id),
alignment: Alignment(-1.0, 0.0),
margin: EdgeInsets.only(top: 10.0, left: 10.0),
),
new Container(
child: new Divider(
height: 2.0,
color: primarycolor,
),
margin: EdgeInsets.only(right: 10.0, left: 10.0, top: 10.0),
),
new Container(
child: new Text(
'Email',
style: new TextStyle(
fontWeight: FontWeight.bold, fontSize: 16.0),
),
alignment: Alignment(-1.0, 0.0),
margin: EdgeInsets.only(top: 10.0, left: 10.0),
),
new Container(
child: new Text(email),
alignment: Alignment(-1.0, 0.0),
margin: EdgeInsets.only(top: 10.0, left: 10.0),
),
new Container(
child: new Divider(
height: 2.0,
color: primarycolor,
),
margin: EdgeInsets.only(right: 10.0, left: 10.0, top: 10.0),
),
new Container(
child: new Text(
'Mobile number',
style: new TextStyle(
fontWeight: FontWeight.bold, fontSize: 16.0),
),
alignment: Alignment(-1.0, 0.0),
margin: EdgeInsets.only(top: 10.0, left: 10.0),
),
new Container(
child: new Text(mobile_number),
alignment: Alignment(-1.0, 0.0),
margin: EdgeInsets.only(top: 10.0, left: 10.0),
),
new Container(
child: new RaisedButton(
onPressed: () {
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => new HomeScreen()));
},
color: secondarycolor,
shape: new RoundedRectangleBorder(
borderRadius: new BorderRadius.circular(5.0)),
child: new Text('Update Profile',
style: new TextStyle(color: Colors.white)),
),
width: 300.0,
height: 40.0,
margin: EdgeInsets.only(top: 10.0),
)
],
);
}) : new Center(child: new CircularProgressIndicator()),
),
);
}
profilejson() async {
SharedPreferences pref = await SharedPreferences.getInstance();
var profile_url = url + "view_profile&userid=" + pref.getString('userid');
print(profile_url);
http.Response profileresponse = await http.get(profile_url);
var profile_response_json = json.decode(profileresponse.body);
// the variables you want the layout to be updated with
setState(() {
name = profile_response_json['username'];
userimage = profile_response_json['image'];
birth = profile_response_json['dob'];
c_id = profile_response_json['customerid'];
email = profile_response_json['email'];
mobile_number = profile_response_json['phone'];
})
}
#override
void initState() {
super.initState();
profilejson();
}
}

Resources