flutter dropdownbutton that loads info from the dropdown to a data grid - flutter

as i have on my profile before, multiple posts of question about data grid. i need to get the grid by a dropdown button/menu that has all the driver's names and looks up all the data by that name/ driver number.
below is the snip of the body for that dropdown class.
body: TabBarView(
children: [
Center(
child: SingleChildScrollView(
child: isLoading
? Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
new CircularProgressIndicator(),
new Text(" please wait for data to load... ")
],
)
: new Column(
//crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(height: 0),
Center(
child: Text(
" drivers name "
, style: TextStyle(fontSize: 25,),
),
),
Container(
height: 75,
width: 400,
decoration: BoxDecoration(
color: Colors.blue.withOpacity(0.70), // border color
borderRadius: BorderRadius.all(Radius.circular(20))
),
child: Center(
child: DropdownButtonHideUnderline(
child: DropdownButton(
hint: Text("press here",
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold
),),
alignment: AlignmentDirectional.topCenter,
menuMaxHeight: 300,
dropdownColor: Colors.grey.shade300,
borderRadius: BorderRadius.all(Radius.circular(15.0)),
items: DriversName.map((item) {
return DropdownMenuItem(
child: Center(
child: Text(
item['DriverName'].toString().trim(), //Names that the api dropdown contains
style: const TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold
),
textAlign : TextAlign.end,
),
),
value: item['DriverNo'].toString().trim() //Id that has to be passed that the dropdown has.....
//e.g India (Name) and its ID (55fgf5f6frf56f) somethimg like that....
);
}).toList(),
onChanged: (String? newVal) {
setState(() {
driverName = newVal.toString();
driverName1 = driverName?.trim();
print(driverName1.toString());
});
},
value: driverName, //pasing the default id that has to be viewed... //i havnt used something ... //you can place some (id)
),
),
),
),
SizedBox(height: 5,),
// Operations Types Api List New
Container(
height: 75,
width: 250,
margin: EdgeInsets.all(15),
child: TextField(
style: TextStyle(fontSize: 25),
keyboardType: TextInputType.number,
controller: driverNoController,
textAlign: TextAlign.center,
decoration: InputDecoration(
alignLabelWithHint: true,
//labelText: 'Qty',
hintText: 'enter drivers name',
hintStyle: TextStyle(),
border: OutlineInputBorder(
borderSide: BorderSide(color: Colors.red, width: 20),
borderRadius: BorderRadius.all(Radius.circular(15.0)),
//borderRadius: BorderRadius.circular(15),
),
),
obscureText: false,
//controller: myController,
),
),
Container(
height: 50,
width: 150,
child: ElevatedButton(
//style: ElevatedButton.styleFrom(side: BorderSide(width: 1,style: BorderStyle.solid),
style: ButtonStyle(
backgroundColor:
MaterialStateProperty.all(Colors.lightBlueAccent),
shape: MaterialStateProperty.all<RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50.0),
side: BorderSide(color: Colors.white)))),
//style: ButtonStyle(shape: OutlinedBorder()),
child: Center(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Icon(Icons.local_shipping_outlined),
SizedBox(
width: 25,
),
Text(
'GO ',
style: TextStyle(color: Colors.white, fontSize: 20),
),
],
)),
onPressed: () {
//fetchOpTypesData();
int driverNo = int.parse(driverNoController.text);
if (driverNo.isNaN || driverName1 == '') {
print('empty data');
return;
}
else {
upload();
searchDetailsByDriverNoFromJson(driverNo).then(
(value) {
Navigator.push(
context,
new MaterialPageRoute(
//builder: (context) => BalanceScreen(),
builder: (context) => transData(),
),
);
// print(value.driverNo);
saveDriverNoPrefs(driverNo);
}
).onError((error, stackTrace) {
CoolAlert.show(
context: context,
type: CoolAlertType.error,
text: "please check data",
);
});
};
} ),
),
],),
)
)

Related

How to make textformfield and dropdownmenu close?

This is the design I want:
This is my current design:
How to make textfromfield and dropdownmenu close like in the design I showed. And another thing is how to make the circlebox have the same distance as in the design. I have tried but without success. Please guide. I am new to using flutter.
This is my code:
Container(
padding: const EdgeInsets.symmetric(horizontal: 150),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(height: 35),
Container(
width: double.infinity,
margin: EdgeInsets.fromLTRB(30, 0, 10, 20),
padding: EdgeInsets.all(30),
decoration: BoxDecoration(
border: Border.all(
color: Colors.transparent,
width: 1.0,
),
),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
Row(
mainAxisAlignment: MainAxisAlignment.end,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Expanded(
child: Wrap(
direction: Axis.horizontal,
alignment: WrapAlignment.end,
crossAxisAlignment: WrapCrossAlignment.center,
children: [
Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.transparent,
width: 1.0,
),
),
child: Center(
child: FutureBuilder(
future: _getSignedURL(
widget.patientProfile.avatar),
builder: (BuildContext context,
AsyncSnapshot snapshot) {
if (snapshot.data == null) {
return Container(
color: Colors.white,
child: Container(
width: 200,
height: 200,
decoration: BoxDecoration(
color: Color.fromRGBO(
255, 255, 255, 0.3),
border: Border.all(
color: Colors.black12,
width: 1.0,
),
borderRadius:
BorderRadius.all(
Radius.circular(
200.0)),
),
),
);
} else {
return CircleAvatar(
radius: 100,
backgroundImage:
NetworkImage(snapshot.data),
);
}
},
),
),
),
new Positioned(
left: MediaQuery.of(context).size.width *
100,
top: MediaQuery.of(context).size.height *
200,
child: Container(
width: 200,
height: 50,
decoration: BoxDecoration(
border: Border.all(
color: Colors.transparent,
width: 1.0,
),
),
// ignore: deprecated_member_use
child: OutlinedButton(
style: OutlinedButton.styleFrom(
//primary: Colors.white,
//backgroundColor: Colors.white,
side: BorderSide(
color: Colors.blue, width: 1),
),
child: Text(
'Save Profile',
style:
TextStyle(color: Colors.blue),
),
onPressed: () =>
_updatePatientProfile(),
),
)),
Container(
width: double.infinity,
margin:
const EdgeInsets.symmetric(vertical: 0),
padding: const EdgeInsets.symmetric(
horizontal: 100),
decoration: BoxDecoration(
border: Border.all(
color: Colors.transparent,
width: 1.0,
),
),
child: Row(
children: [
Expanded(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
SizedBox(
height: 30,
child: Text(
'* MRN',
style: TextStyle(
fontWeight:
FontWeight.bold,
fontSize: 16),
),
),
SizedBox(
width: 300,
child: TextFormField(
style: const TextStyle(
color: Colors.black),
controller: mrn,
onSaved: (String? value) {
mrn.text = value!;
},
decoration:
const InputDecoration(
border:
OutlineInputBorder(),
hintText: 'MRN',
hintStyle: TextStyle(
color: Colors.black,
fontSize: 16),
),
),
)
],
),
),
Expanded(
child: Column(
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
SizedBox(
height: 30,
child: Text(
'* Salutation',
style: TextStyle(
fontWeight:
FontWeight.bold,
fontSize: 16),
),
),
SizedBox(
width: 10,
),
Container(
height: 55,
//width: 30,
padding: EdgeInsets.symmetric(
horizontal: 10,
vertical: 5),
decoration: BoxDecoration(
border: Border.all(
color: Colors.black12,
width: 1.0,
),
borderRadius:
BorderRadius.circular(
5)),
child: SizedBox(
width: 300,
child:
DropdownButton<String>(
underline: Container(
color: Colors
.transparent),
hint: _salutation == null
? Text(
'* Salutation',
style: TextStyle(
color: Colors
.red),
)
: Text(_salutation),
isExpanded: true,
value: _salutation,
items: <String>[
'Mr.',
'Mrs.',
'Ms.'
].map((String value) {
return new DropdownMenuItem<
String>(
value: value,
child:
new Text(value),
);
}).toList(),
onChanged: (value) {
setState(() {
_salutation = value!;
});
},
),
)),
Container()
],
),
)
],
),
)
],
),
)
],
)
],
),
),
],
),
),
Use dropdown_button2 package,
final List<String> _items = [
'item 1',
'item 2',
'item 3',
'item 4',
];
String _selectedValue; // use list of string for your dropdown children
// put these above of build function
.
.
Row(
children: [
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
MyDropdown(
selectedValue: _selectedValue,
dropdownItems: _items,
),
],
),
),
const SizedBox(width: 10),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
MyDropdown(
selectedValue: _selectedValue,
dropdownItems: _items,
),
],
),
),
const SizedBox(width: 10),
Expanded(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: const [
Text('*To be filled ........'),
],
),
),
],
);
and here is your Dropdown widget, i extract it to make clean code
class MyDropdown extends StatefulWidget {
List<String> dropdownItems;
String selectedValue;
MyDropdown({this.dropdownItems, this.selectedValue});
#override
State<MyDropdown> createState() => _MyDropdownState();
}
class _MyDropdownState extends State<MyDropdown> {
#override
Widget build(BuildContext context) {
return DropdownButtonFormField2(
decoration: InputDecoration(
isDense: true,
contentPadding: EdgeInsets.zero,
border: OutlineInputBorder(
borderRadius: BorderRadius.circular(5),
),
),
isExpanded: true,
hint: const Text(
'Select Your Gender',
style: TextStyle(fontSize: 14),
),
icon: const Icon(
Icons.arrow_drop_down,
color: Colors.black45,
),
iconSize: 30,
buttonHeight: 60,
buttonPadding: const EdgeInsets.only(left: 20, right: 10),
items: widget.dropdownItems
.map((item) => DropdownMenuItem<String>(
value: item,
child: Text(
item,
style: const TextStyle(
fontSize: 14,
),
),
))
.toList(),
validator: (value) {
// validate here
},
onChanged: (value) {
//Do something when changing the item if you want.
},
onSaved: (value) {
widget.selectedValue = value.toString();
},
);
}
}
play with values and add TextField in child of column to get result

flutter unexpected errors

i am no newbie to the whole thing of being in a circle of errors, bugs and problem solving.
what i have been facing for the last few weeks is the fact that the code works in another laptop, maybe at someone else's project but i get the errors like it doesn't work although i checked and have run the process successfully a few times before.
it had posted, and those errors didn't exist.
we do have a null checker:
child: SingleChildScrollView(
child: isLoading
? Column(
knowing that is Loading is false
and i run android studio.
ps some of the code below feels missing because it has valuable data , and or it would have been longer than what it already is
Widget build(BuildContext context) {
return DefaultTabController(
length: 1,
child: MaterialApp(
theme: ThemeData(fontFamily: 'Harmattan',),
home: Scaffold(
key: _scaffoldKey,
appBar: AppBar(
actions: [
IconButton(onPressed: (){
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => MaintenanceDataTypesByDriver()));
}, icon: Icon(Icons.view_headline_sharp,size: 40,),)
],
title: Center(child: Text(
'enter',
style: TextStyle(fontSize: 25, color: Colors.white),
),),
leading: Builder(
builder: (BuildContext context) {
return IconButton(
icon: const Icon(
Icons.arrow_back_rounded,
size: 40,
color: Colors.white,
),
onPressed: () {
//Navigator.pushNamed(context, mainScreen.id);
Navigator.push(
context,
new MaterialPageRoute(
builder: (context) => maintenance_screen()));
},
);
},
),
),
body: TabBarView(
children: [
Center(
child: SingleChildScrollView(
child: isLoading
? Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
new CircularProgressIndicator(),
new Text(" اplease hold.. ")
],
)
: new Column(
//crossAxisAlignment: CrossAxisAlignment.stretch,
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
SizedBox(height: 0),
Center(
child: Text(
" choose an option",
style: TextStyle(fontSize: 25,),
),
),
SizedBox(height: 5,),
// Operations Types Api List New /
Container(
height: 75,
width: 400,
decoration: BoxDecoration(
color: Colors.blue.withOpacity(0.35), // border color
borderRadius: BorderRadius.all(Radius.circular(20))
),
child: Center(
child: DropdownButtonHideUnderline(
child: DropdownButton(
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold
),),
.........
}).toList(),
onChanged: (String? newVal) {
setState(() {
print(faultReportingName1.toString());
});
},
value: faultReportingName, //pasing the default id that has to be viewed... //i havnt used something ... //you can place some (id)
),
),
),
),
SizedBox(height: 5),
Center(
child: Text(
"press here",
style: TextStyle(fontSize: 25,),
),
),
SizedBox(height: 5,),
// Fault Locations Api List New
Container(
height: 75,
width: 400,
decoration: BoxDecoration(
color: Colors.blue.withOpacity(0.35), // border color
borderRadius: BorderRadius.all(Radius.circular(20))
),
child: Center(
child: DropdownButtonHideUnderline(
child: DropdownButton(
hint: Text("اpress here",
style: TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold
),),
.....
style: const TextStyle(
fontSize: 20.0,
fontWeight: FontWeight.bold
),
textAlign : TextAlign.end,
),
...........
},
value: faultLocationsName, //pasing the default id that has to be viewed... //i havnt used something ... //you can place some (id)
),
),
),
),
SizedBox(height: 10),
Center(
child: Text(
" date",
style: TextStyle(fontSize: 25),
),
),
//
Container(
width: 300,
height: 75,
child: TextField(
style: TextStyle(color: Colors.black, fontSize: 20),
onTap: () {
FocusScope.of(context).requestFocus(new FocusNode());
showDatePicker(context: context, initialDate: DateTime.now(), textAlign: TextAlign.center,
decoration: InputDecoration(
errorStyle: TextStyle(height: 0.1),
errorText: _validateStartingDateController ? 'date' : null,
alignLabelWithHint: true,
//labelText: 'Qty',
hintText: '$faultDate1' ,
hintStyle: TextStyle(),
border: OutlineInputBorder(
borderSide:
BorderSide(color: Colors.yellow,
/* 0xfffdbd2a*/width: 20),
borderRadius: BorderRadius.all(Radius.circular(15.0)),
//borderRadius: BorderRadius.circular(15),
),
),
obscureText: false,
//controller: myController,
),
),
//
Center(
child: Text(
"maintenance ",
style: TextStyle(fontSize: 25),
),
),
SizedBox(height: 0),
TextField(
style: TextStyle(fontSize: 20),
keyboardType: TextInputType.number,
//inputFormatters: [FilteringTextInputFormatter.digitsOnly],
controller: opCostController,
textAlign: TextAlign.end,
decoration: InputDecoration(
errorText: _valueValidate ? 'required' : null,
alignLabelWithHint: true,
//labelText: 'Qty',
hintText: 'IQD ',
hintStyle: TextStyle(),
border: OutlineInputBorder(
borderSide:
BorderSide(color: Color(0xfffdbd2a), width: 20),
borderRadius:
BorderRadius.all(Radius.circular(15.0)),
//borderRadius: BorderRadius.circular(15),
),
),
obscureText: false,
//controller: myController,
),
SizedBox(height: 0),
Center(
child: Text(
"notes",
style: TextStyle(fontSize: 25),
),
),
SizedBox(height: 0),
TextField(
style: TextStyle(fontSize: 20),
controller: notesController,
textAlign: TextAlign.end,
decoration: InputDecoration(
errorStyle: TextStyle(height: 1),
alignLabelWithHint: true, hintStyle: TextStyle(),
border: OutlineInputBorder(
borderSide:
BorderSide(color: Color(0xfffdbd2a), width: 20),
borderRadius:
BorderRadius.all(Radius.circular(15.0)),
//borderRadius: BorderRadius.circular(15),
),
),
obscureText: false,
//controller: myController,
),
SizedBox(height: 5),
Center(
child: _file == null ? Text('') :
Container(
height: 310,
margin: EdgeInsets.all(10),
decoration: BoxDecoration(
image: DecorationImage(
fit: BoxFit.fill,
image: FileImage(_file!),
),
borderRadius: BorderRadius.circular(10),
),
//child: Image.asset('images/Logistic.jpg'),
),
),
Container(
height: 50,
width: 200,
child: ElevatedButton(
//style: ElevatedButton.styleFrom(side: BorderSide(width: 1,style: BorderStyle.solid),
style: ButtonStyle(
shape: MaterialStateProperty.all<
RoundedRectangleBorder>(
RoundedRectangleBorder(
borderRadius: BorderRadius.circular(50.0),
side: BorderSide(color: Colors.white)))),
//style: ButtonStyle(shape: OutlinedBorder()),
child: Text(
'save',
style: TextStyle(color: Colors.white, fontSize: 20),
),
onPressed: () {
//if(isLoading)return;
setState(() {
double opCost = double.parse(opCostController.text.trim());
String date = faultDateController.text;
int faultLocID = int.parse(faultLocationsName1!.trim());
int faultRepID = int.parse(faultReportingName1!.trim());
String notes = notesController.text.trim();
if(opCost.isNaN || faultReportingName1=='' || faultLocationsName1=='' ||date =='')
{
print('empty');
return;
}
else{
upload();
I think the problem is coming from your data model class. some of your String values is Null.
Try to check it carefully.

I am not at all able to solve this Bottom overflow by 283 pixels

class Chest extends StatefulWidget {
const Chest({Key? key}) : super(key: key);
#override
_ChestState createState() => _ChestState();
}
class _ChestState extends State<Chest> {
//! Firebase SetUp
final _formKey = GlobalKey<FormState>();
FirebaseAuth auth = FirebaseAuth.instance;
final _firestore = FirebaseFirestore.instance;
late String _email;
late String _password;
#override
Widget build(BuildContext context) {
return Column(children: [
Padding(
padding: const EdgeInsets.only(top: 100.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'BMI CALCULATOR',
style: TextStyle(
fontSize: 35,
color: Colors.white,
fontWeight: FontWeight.normal),
),
Text(
"WELCOME Mr.Dheer",
style: TextStyle(fontSize: 18, color: Colors.white),
)
],
),
),
SizedBox(height: 100),
Expanded(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(60),
topRight: Radius.circular(60),
),
),
child: Padding(
padding: const EdgeInsets.only(top: 80.0, right: 50, left: 50),
child: Column(
children: [
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(10),
),
boxShadow: [
BoxShadow(
color: Color.fromRGBO(225, 95, 27, .3),
blurRadius: 20,
offset: Offset(0, 10),
),
],
),
child: Form(
key: _formKey,
child: Column(
children: [
TextFormField(
onChanged: (value) {
setState(() {
_email = value;
});
},
decoration: const InputDecoration(
border: UnderlineInputBorder(),
labelText: "Email or Phone Number"),
),
TextFormField(
keyboardType: TextInputType.text,
enabled: true,
onChanged: (value) {
setState(() {
_password = value;
});
},
decoration: const InputDecoration(
border: UnderlineInputBorder(),
labelText: "PassWord"),
),
],
),
),
),
SizedBox(
height: 40,
),
Text(
'FORGOT PASSWORD',
style: TextStyle(fontWeight: FontWeight.bold),
),
SizedBox(
height: 30,
),
Row(
// mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
ReuseButton(
OwnTextButton: TextButton(
//! LOGIN FUNCTIONALITY
onPressed: () {},
// Navigator.pushNamed(context, '/HomePage'),
child: Text(
'LOGIN',
style: TextStyle(
color: Colors.white,
),
),
),
OwnBoxColor: Colors.orange.shade700,
),
SizedBox(
width: 10,
),
ReuseButton(
OwnTextButton: TextButton(
// ! REGISTER FUNCTIONALITY
onPressed: () {
Navigator.pushNamed(context, '/SignUpPage');
},
child: Text(
'Register',
style: TextStyle(
color: Colors.white,
),
),
),
OwnBoxColor: Colors.orange.shade700,
)
],
),
SizedBox(
height: 110,
),
Text(
'Continue With Social Media',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 20),
Row(
children: [
ReuseButton(
OwnBoxColor: Colors.blue,
OwnTextButton: TextButton(
onPressed: () {},
child: Text(
'Facebook',
style: TextStyle(
color: Colors.white,
),
),
),
),
SizedBox(
width: 10,
),
ReuseButton(
OwnBoxColor: Colors.black,
OwnTextButton: TextButton(
onPressed: () {},
child: Text(
'Gmail',
style: TextStyle(
color: Colors.white,
),
),
),
)
],
)
],
),
),
),
),
]);
}
}
class ReuseButton extends StatelessWidget {
const ReuseButton({required this.OwnBoxColor, required this.OwnTextButton});
final Color OwnBoxColor;
final TextButton OwnTextButton;
#override
Widget build(BuildContext context) {
return Expanded(
child: Container(
decoration: BoxDecoration(
color: OwnBoxColor,
borderRadius: BorderRadius.all(
Radius.circular(10),
),
),
child: OwnTextButton,
),
);
}
}
Try below code hope its helpful to you. wrap your inside Expanded Widget Column with SingleChildScrollView(). Just chnage your widget with my Widget/Code.
Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 100.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'BMI CALCULATOR',
style: TextStyle(
fontSize: 35,
color: Colors.black,
fontWeight: FontWeight.normal,
),
),
Text(
"WELCOME Mr.Dheer",
style: TextStyle(
fontSize: 18,
color: Colors.black,
),
)
],
),
),
SizedBox(height: 100),
Expanded(
child: Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(
topLeft: Radius.circular(60),
topRight: Radius.circular(60),
),
),
child: Padding(
padding:
const EdgeInsets.only(top: 80.0, right: 50, left: 50),
child: SingleChildScrollView(
child: Column(
children: [
Container(
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.all(
Radius.circular(10),
),
boxShadow: [
BoxShadow(
color: Color.fromRGBO(225, 95, 27, .3),
blurRadius: 20,
offset: Offset(0, 10),
),
],
),
child: Form(
child: Column(
children: [
TextFormField(
onChanged: (value) {
setState(() {});
},
decoration: const InputDecoration(
border: UnderlineInputBorder(),
labelText: "Email or Phone Number",
),
),
TextFormField(
keyboardType: TextInputType.text,
enabled: true,
onChanged: (value) {
setState(() {});
},
decoration: const InputDecoration(
border: UnderlineInputBorder(),
labelText: "PassWord",
),
),
],
),
),
),
SizedBox(
height: 40,
),
Text(
'FORGOT PASSWORD',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
SizedBox(
height: 30,
),
Row(
children: [
Text(
'LOGIN',
style: TextStyle(
color: Colors.red,
),
),
SizedBox(
width: 10,
),
Text(
'Register',
style: TextStyle(
color: Colors.red,
),
),
],
),
SizedBox(
height: 110,
),
Text(
'Continue With Social Media',
style: TextStyle(
fontWeight: FontWeight.bold,
),
),
SizedBox(height: 20),
Row(
children: [
Text(
'Facebook',
style: TextStyle(
color: Colors.red,
),
),
SizedBox(
width: 10,
),
Text(
'Gmail',
style: TextStyle(
color: Colors.red,
),
),
],
)
],
),
),
),
),
),
],
),
Your result Scrren->
You can wrap your code in ListView or SingleChildScrollView instead of the column :
#override
Widget build(BuildContext context) {
return ListView(
children: [
// your code
],
);
}
Wrap your code in SingleChildScrollView like below:
#override
Widget build(BuildContext context) {
return SingleChildScrollView(
child: Column(
children: [
// your rest code here...
],
),
);
}

Dialog is not work properly with singlechildscrollview and soft keyboard in flutter

Dialog is not working properly with singlechildscrollview and soft keyboard in flutter.
Problems:
Dialog design is gone under the soft keyboard
Scroll is not properly working when open soft keyboard
My dialog is here:-
Future<void> ShowMessageDetail(
BuildContext context, String name, String message, String date, int id) async {
txtController.text = message;
edit = false;
return showDialog(
context: context,
builder: (context) {
return StatefulBuilder(
builder: (BuildContext context, void Function(void Function()) setState) {
return AlertDialog(
contentPadding: EdgeInsets.only(left: 25, right: 25),
content: Wrap(
children: [
Column(
children: [
Container(
height: 50,
width: double.infinity,
color: Colors.blue,
child: Center(
child: Text(
"Detail",
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold, fontSize: 20),
)),
),
Column(
children: [
Padding(
padding: const EdgeInsets.only(top: 10, bottom: 10),
child: Row(
children: [
Text(
"Name : ",
style: TextStyle(
color: Colors.blue,
),
),
Text(name)
],
),
),
Divider(
color: Colors.grey,
),
Padding(
padding: const EdgeInsets.only(top: 10, bottom: 8),
child: Row(
children: [
Text(
"Date : ",
style: TextStyle(
color: Colors.blue,
),
),
Text(date.substring(0, 10))
],
),
),
Divider(
color: Colors.grey,
),
Padding(
padding: const EdgeInsets.only(top: 8, bottom: 8),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Align(
alignment: Alignment.centerLeft,
child: Text(
"Message : ",
style: TextStyle(
color: Colors.blue,
),
),
),
Row(
children: [
Container(
decoration: BoxDecoration(
color: edit ? Colors.blue : Colors.white,
borderRadius: BorderRadius.circular(30),
border: Border.all(color: Colors.blue, width: 2),
),
child: IconButton(
onPressed: () {
setState(() {
edit ? edit = false : edit = true;
});
},
icon: Icon(
Icons.edit_outlined,
color: edit ? Colors.white : Colors.blue,
)),
),
Container(
width: 15,
),
Container(
decoration: BoxDecoration(
color: Colors.blue,
borderRadius: BorderRadius.circular(30),
),
child: IconButton(
onPressed: () {
copy(message);
},
icon: Icon(
Icons.copy,
color: Colors.white,
)),
)
],
),
],
),
ConstrainedBox(
constraints: BoxConstraints(
maxHeight: 300,
),
child: SingleChildScrollView(
scrollDirection: Axis.vertical,
child: Padding(
padding: const EdgeInsets.only(top: 10),
child: Container(
child: TextFormField(
controller: txtController,
textAlign: TextAlign.justify,
focusNode: contentFocus,
decoration: InputDecoration.collapsed(
hintText: 'Start typing...',
hintStyle: TextStyle(
color: Colors.grey.shade400,
fontSize: 16,
fontWeight: FontWeight.w500,
),
border: InputBorder.none,
),
enabled: edit ? true : false,
maxLines: null,
keyboardType: TextInputType.multiline,
style: TextStyle(
fontSize: 15,
height: 1.2,
),
),
),
),
),
)
],
),
),
Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Visibility(
visible: edit ? true : false,
child: MaterialButton(
onPressed: () {
updateMessage(name, txtController.text.toString(), id);
},
color: Colors.blue,
child: Text(
"Update",
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
),
),
),
Container(
width: 15,
),
MaterialButton(
onPressed: () {
Navigator.pop(context);
},
color: Colors.blue,
child: Text(
"Cancel",
style: TextStyle(color: Colors.white, fontWeight: FontWeight.bold),
),
),
],
)
],
),
],
),
],
),
);
},
);
});
}
I use scrollController for scrolling but this does not work.
Please help me to solve my dialog design problem.
wrap your Alert Dialog with SingleChildScrollview
SingleChildScrollView(
child: AlertDialog());

Different behaviours using `SingleChildScrollView` Flutter

I'm trying to make the whole OrderScreen slide up when the keyboard appears as I do in UserProfileScreen by wrapping the scaffold's container in a SingleChildScrollView, but doing so on this screen it throws various RenderBox was not laid out: _RenderScrollSemantics#abc84 relayoutBoundary=up4 NEEDS-PAINT errors, which are not thrown without SingleChildScrollView. I set up the two screen just the same apart from UserProfileScreen having a Column as a child of another Column. All column's children are wrapped in and Expanded widget with different flex values for layout purposes. Can you se why I do get these errors?
UserProfileScreen ( working ) :
child: Scaffold(
resizeToAvoidBottomInset: true,
body: SingleChildScrollView(
child: Container(
color: Colors.black54,
padding:
EdgeInsets.only(left: 100, right: 100, top: 30, bottom: 70),
child: Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
SizedBox(
height: 100,
),
Stack(
children: [
Container(
decoration: BoxDecoration(
border: Border.all(
color: Colors.grey[200],
width: 2,
),
borderRadius: BorderRadius.circular(100),
),
child: CircleAvatar(
radius: 50,
backgroundImage:
NetworkImage('${widget.user.shopLogoUrl}'),
),
),
],
),
SizedBox(
height: 35,
width: 30,
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
Expanded(
child: Text(
AppLocalizations.instance.text('Shop name'),
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white, fontSize: fontSize),
),
),
// SizedBox(width: 50),
Expanded(
flex: 2,
child: TextField(
controller: _nameController,
style: TextStyle(
color: Colors.black87,
fontSize: fontSize,
fontWeight: FontWeight.w500),
decoration: InputDecoration(
isDense: true,
contentPadding: EdgeInsets.all(5),
enabled: false,
hintText: AppLocalizations
.instance
.text(
'Shop name placeholder'),
//'nome',
hintStyle: TextStyle(
fontSize: fontSize,
color: Colors.grey[350]),
border: OutlineInputBorder(),
// focusColor: Colors.lightGreenAccent,
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.white,
width: 1,
),
),
fillColor: Colors.white,
filled: true),
cursorColor: Colors.black,
),
),
],
),
...
],
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisSize: MainAxisSize.max,
children: <Widget>[
// TODO cancel button
RaisedButton(
color: Colors.redAccent,
child: Text(
AppLocalizations.instance
.text('Cancel'),
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: fontSize),
),
onPressed: () {
BlocProvider.of<UserBloc>(context)
.add(LoadUser());
},
),
SizedBox(width: 20),
// TODO save button
RaisedButton(
color: Colors.green.shade400,
child: Text(
AppLocalizations.instance.text('Save'),
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white,
fontSize: fontSize),
),
onPressed: () {
BlocProvider.of<UserBloc>(context)
.add(SaveUser(
user: FixitUser(
shopName: widget.user.shopName,
email: widget.user.email,
phoneNumber:
_phoneNumberController.text,
uid: widget.user.uid,
shopLogoUrl:
widget.user.shopLogoUrl,
address: _addressController.text,
zipCode: _zipCodeController.text,
city: widget.cityUser,
region: widget.regionUser,
country: widget.countryUser,
vatNumber: _vatController.text,
homeLat: widget
.userLocation.latitude
.toString(),
homeLong: widget
.userLocation.longitude
.toString(),
lastLogin: DateTime.now()
.millisecondsSinceEpoch,
signUpDate: signUpDate ??
DateTime.now()
.millisecondsSinceEpoch),
));
showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return Dialog(
child: Container(
padding: EdgeInsets.all(50),
child: new Column(
mainAxisAlignment:
MainAxisAlignment
.spaceEvenly,
mainAxisSize:
MainAxisSize.min,
children: [
new CircularProgressIndicator(
valueColor:
AlwaysStoppedAnimation<
Color>(
Colors
.redAccent),
),
SizedBox(
height: 50,
),
new Text(
AppLocalizations
.instance
.text(
'Saving user profile'),
style: TextStyle(
fontSize: fontSize,
color:
Colors.black54),
),
],
),
),
);
});
}),
...
],
),
),
],
),
),
),
),
OrderScreen ( trowing error ) :
child: Scaffold(
resizeToAvoidBottomInset : true,
body: SingleChildScrollView(
child: Container(
color: Colors.black54,
padding:
const EdgeInsets.symmetric(vertical: 20, horizontal: 20),
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
SizedBox(height: 10,),
Expanded(
flex: 1,
child: Container(
padding: EdgeInsets.all(5),
decoration: BoxDecoration(
color: Colors.transparent,
borderRadius: BorderRadius.circular(5),
border: Border.all(
color: Colors.redAccent, width: 2),
),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Expanded(
flex: 9,
child: TextField(
controller: _customerNameController,
style: TextStyle(
color: Colors.black87,
fontSize: fontSize,
fontWeight: FontWeight.w500),
decoration: InputDecoration(
isDense: true,
enabled: true,
hintText: AppLocalizations.instance
.text('Customer name placeholder'), //'nome',
hintStyle: TextStyle(
fontSize: fontSize, color: Colors.grey[400]),
border: OutlineInputBorder(),
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(
color: Colors.white,
width: 1,
),
),
fillColor: Colors.white,
filled: true),
cursorColor: Colors.black,
onChanged: (value){
BlocProvider.of<OrderBloc>(context).add(LoadOrdersForCustomer(_customerNameController.text));
},
),
),
SizedBox(width: 20,),
Expanded(
flex: 2,
child: RaisedButton(
color: Colors.redAccent,
child: Text(
AppLocalizations.instance.text('Cancel'),
textAlign: TextAlign.center,
style: TextStyle(
color: Colors.white, fontSize: fontSize),
),
onPressed: () {
setState(() {
_customerNameController.text = '';
});
BlocProvider.of<OrderBloc>(context).add(LoadOrders(user: widget.user));
},
),
)
],
),
),
),
...
],
),
),
),
),
Progress
Adding height and width to the container got rid of the error, but the view doesn't slide up as UserProfileScreen instead does..with or without resizeToAvoidBottomInset: true, set in Scaffold.. the keyboard just covers up the screen..
child: Scaffold(
resizeToAvoidBottomInset: true,
body: SingleChildScrollView(
child: Container(
height: MediaQuery.of(context).size.height-50,
width: MediaQuery.of(context).size.width,
color: Colors.black54,
padding: const EdgeInsets.symmetric(vertical: 20, horizontal: 20),
child: Column(
So I have two different behaviours.
UserProfileScreen doesn't need Container's heigh and width and it slides up on keyboard appearing.
OrderScreen does need Container's height and width but doesn't slide up on keyboard appearing.