Cant select radio buttons inside the form in flutter - flutter

It won't allow me to change the radio button inside the form, the value also does not change no matter what is selected. I have tried the code outside the form and it works fine but when i put it inside the form then it stops working for reasons I do not know.
FloatingActionButton(
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(
title: Text('New User'),
content: Stack(
children: <Widget>[
Positioned(
right: -40.0,
top: -40.0,
child: InkResponse(
onTap: () {
Navigator.of(context).pop();
},
child: CircleAvatar(
child: Icon(Icons.close),
backgroundColor: Colors.blue,
),
),
),
Form(
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Padding(
padding: EdgeInsets.all(8.0),
child: TextFormField(
controller: nameController,
decoration: InputDecoration(
labelText: 'Name',
),
),
),
Padding(
padding: EdgeInsets.all(8.0),
child: TextFormField(
controller: surnameController,
decoration: InputDecoration(
labelText: 'Surname',
),
),
),
Padding(
padding: EdgeInsets.all(8.0),
child: TextFormField(
controller: userController,
decoration: InputDecoration(
labelText: 'Username',
),
),
),
Padding(
padding: EdgeInsets.all(8.0),
child: TextFormField(
controller: passController,
decoration: InputDecoration(
labelText: 'Password',
),
),
),
Padding(
padding: EdgeInsets.all(8.0),
child: TextFormField(
controller: mobileController,
decoration: InputDecoration(
labelText: 'Mobile num',
),
),
),
Padding(
padding: EdgeInsets.all(8.0),
child: TextFormField(
controller: emailController,
decoration: InputDecoration(
labelText: 'Email',
),
),
),
//radioButtons
Container(
padding: EdgeInsets.all(20),
child: Column(
children: [
Text(
"What is your gender?",
style: TextStyle(fontSize: 18),
),
Divider(),
RadioListTile(
title: Text("Male"),
value: "male",
groupValue: gender,
onChanged: (value) {
setState(() {
gender = value.toString();
});
},
),
RadioListTile(
title: Text("Female"),
value: "female",
groupValue: gender,
onChanged: (value) {
setState(() {
gender = value.toString();
});
},
),
RadioListTile(
title: Text("Other"),
value: "other",
groupValue: gender,
onChanged: (value) {
setState(() {
gender = value.toString();
});
},
)
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: FloatingActionButton(
child: Text("Submit"),
onPressed: () {
//createUser();
print(gender);
Navigator.pop(context);
},
),
)
],
),
),
),
],
),
);
});
},
child: Icon(Icons.person),
backgroundColor: Colors.blue,
),
it has a few text fields and then the radio buttons, the gender variable is declared as a string.

It's Because you are assigned a value in the dialog. Just Wrap Your Alert Dialog Widget with statfulBuilder and then stateState.
example
FloatingActionButton(
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return StatefulBuilder(
builder: (BuildContext context, StateSetter setState) {
return AlertDialog(
title: const Text('New User'),
content: Stack(
children: <Widget>[
Positioned(
right: -40,
top: -40,
child: InkResponse(
onTap: () {
Navigator.of(context).pop();
},
child: const CircleAvatar(
backgroundColor: Colors.blue,
child: Icon(Icons.close),
),
),
),
Form(
child: SingleChildScrollView(
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8),
child: TextFormField(
controller: nameController,
decoration: const InputDecoration(
labelText: 'Name',
),
),
),
Padding(
padding: const EdgeInsets.all(8),
child: TextFormField(
controller: surnameController,
decoration: const InputDecoration(
labelText: 'Surname',
),
),
),
Padding(
padding: const EdgeInsets.all(8),
child: TextFormField(
controller: userController,
decoration: const InputDecoration(
labelText: 'Username',
),
),
),
Padding(
padding: const EdgeInsets.all(8),
child: TextFormField(
controller: passController,
decoration: const InputDecoration(
labelText: 'Password',
),
),
),
Padding(
padding: const EdgeInsets.all(8),
child: TextFormField(
controller: mobileController,
decoration: const InputDecoration(
labelText: 'Mobile num',
),
),
),
Padding(
padding: const EdgeInsets.all(8),
child: TextFormField(
controller: emailController,
decoration: const InputDecoration(
labelText: 'Email',
),
),
),
//radioButtons
Container(
padding: const EdgeInsets.all(20),
child: Column(
children: [
const Text(
'What is your gender?',
style: TextStyle(fontSize: 18),
),
const Divider(),
RadioListTile(
title: const Text('Male'),
value: 'male',
groupValue: gender,
onChanged: (value) {
setState(() {
gender = value.toString();
});
},
),
RadioListTile(
title: const Text('Female'),
value: 'female',
groupValue: gender,
onChanged: (value) {
setState(() {
gender = value.toString();
});
},
),
RadioListTile(
title: const Text('Other'),
value: 'other',
groupValue: gender,
onChanged: (value) {
setState(() {
gender = value.toString();
});
},
)
],
),
),
Padding(
padding: const EdgeInsets.all(8),
child: FloatingActionButton(
child: const Text('Submit'),
onPressed: () {
//createUser();
print(gender);
Navigator.pop(context);
},
),
)
],
),
),
),
],
),
);
},
);
},
);
},
backgroundColor: Colors.blue,
child: Icon(Icons.person),
);

Related

How to center align widget in Flutter form on web

I am building a flutter project on both app and web. I am having a couple of issues with the login page. First my column widget fills the whole width on Flutter web but I want it to be more central. Secondly I am trying to center align the Don't have an account? Sign up button which has found itself aligning to the left. Please may someone assist. Here's my code and a couple of screenshots
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.black,
body: Center(
child: Card(
child: Form(
key: _formKey,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
validator: (value) =>
value!.isEmpty ? 'Email cannot be empty' : null,
onSaved: (value) => _email = value!,
decoration: const InputDecoration(
filled: true,
fillColor: Colors.white,
labelText: 'Email',
hintText: 'Email',
border: OutlineInputBorder(),
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
validator: (value) =>
value!.isEmpty ? 'Password cannot be empty' : null,
onSaved: (value) => _password = value!,
decoration: const InputDecoration(
filled: true,
fillColor: Colors.white,
labelText: 'Password',
hintText: 'Password',
border: OutlineInputBorder(),
),
obscureText: true,
),
),
Padding(
padding: const EdgeInsets.all(0),
child: TextButton(
onPressed: () {
Navigator.pushNamed(context, '/resetpassword');
},
child: const Text('Forgot Password?'),
style: TextButton.styleFrom(
primary: Colors.black,
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: ElevatedButton(
onPressed: validateAndSubmit,
child: const Text('Login'),
style: ElevatedButton.styleFrom(
primary: Colors.black,
onSurface: Colors.black,
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(15.0)),
),
),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
children: [
const Text('Dont have an account?'),
TextButton(
onPressed: () {
Navigator.pushNamed(context, '/signup');
},
child: const Text(
'Signup',
style: TextStyle(fontWeight: FontWeight.bold),
),
style: TextButton.styleFrom(
primary: Colors.black,
),
),
],
),
),
],
),
),
),
), // This trailing comma makes auto-formatting nicer for build methods.
);
To center the 'Dont have an account?' text and 'Signup' TextButton,
use mainAxisAlignment in Row.
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,//<-- this
children: [
const Text('Dont have an account?'),
TextButton(
onPressed: () {
Navigator.pushNamed(context, '/signup');
},
child: const Text(
'Signup',
style: TextStyle(fontWeight: FontWeight.bold),
),
style: TextButton.styleFrom(
primary: Colors.black,
),
),
],
),
),
To responsive web and app,
I use this method,
void main() async {
runApp(
const ResponsiveLayout(),
);
}
In my ResponsiveLayout const webScreenSize = 600;
Widget build(BuildContext context) {
return LayoutBuilder(
builder: (context, constraints) {
if (constraints.maxWidth > webScreenSize) {
//webscreen
return widget.webScreenLayout; // <-- send user Web screen
} else {
//mobile screen
return widget.mobileScreenLayout; // <-- send user mobile screen
}
},
);
}
Read more about LayoutBuilder -
https://api.flutter.dev/flutter/widgets/LayoutBuilder-class.html

Flutter Bottom Sheet and DropDownMenu Problem

I am creating a Firebase Flutter Application, in which the Bottom Sheet and DropDown Menu are conflicting
Since I wanted curved borders on the Bottom Sheet I added:
child: MaterialApp(
debugShowCheckedModeBanner: false,
theme: ThemeData(
canvasColor: Colors.transparent,
),
Then on my home page on clicking button, on pressed function is triggered:
onPressed: () {
return showModalBottomSheet(
context: context,
builder: (context) {
return Container(
color: Colors.transparent,
child: Container(
padding:
EdgeInsets.symmetric(vertical: 20.0, horizontal: 60.0),
decoration: BoxDecoration(
color: Colors.purple[200],
borderRadius: BorderRadius.only(
topLeft: Radius.circular(25.0),
topRight: Radius.circular(25.0),
)
),
child: bottomSheetPanel(),
)
);
}
);
But when an option is selected from drop down menu
How do I correct it?
Any help will be much appreciated:)
i m posting the code of bottom sheet by using firebase and also have dropdown menu so you can take help from this code.
Widget updatebottomSheet()
{
Size size = MediaQuery.of(context).size;
String _dropDownValue;
String starthoour;
String endhour;
String startminute;
String endminute;
showModalBottomSheet(
enableDrag: false,
isDismissible: false,
isScrollControlled: true,
context: context,
builder:(context)
{
return GestureDetector(
behavior: HitTestBehavior.opaque,
child: SingleChildScrollView(
child: Container(
padding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom+10),
// height: size.height*0.6,
decoration: BoxDecoration(
color: Colors.white,
),
child: Column(
children: [
Padding(
padding: const EdgeInsets.all(25.0),
child: Container(
decoration: BoxDecoration(
//color: Colors.red,
borderRadius: BorderRadius.circular(20),
),
height: size.height*0.6,
width: double.infinity,
child: Card(
elevation: 4,
child: Padding(
padding: const EdgeInsets.all(12.0),
child: Form(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
NameField(
controller: teacherid,
icon: Icons.person,
hintText: "Please enter Teacher id",
text: "you not enter name",
onchanged: (value)
{
Administrative.instance.addteacherId=value;
},
),
NameField(
controller:name ,
icon: Icons.meeting_room_outlined,
hintText: "Please enter room no",
text: "you not enter room no",
onchanged: (value)
{
Administrative.instance.room=value;
},
),
FirebaseFirestore.instance.collection("Section").where("collegeId",isEqualTo:cond).snapshots()==null?Container():StreamBuilder(
stream:FirebaseFirestore.instance.collection("Section").where("collegeId",isEqualTo:cond).snapshots(),
builder: (BuildContext context,AsyncSnapshot<QuerySnapshot>snapshot) {
var length = snapshot.data.docs.length;
// DocumentSnapshot ds = snapshot.data.docs[length];
return DropdownButton(
hint: _dropDownValue==null
? Text("Choose Section")
:Text(_dropDownValue,style: TextStyle(color: Colors.blue),),
isExpanded: true,
iconSize: 30,
items:snapshot.data.docs.map((DocumentSnapshot document)
{
return DropdownMenuItem<String>(
value: document.data()["SectionName"],
child: Text(document.data()["SectionName"]),
);
}
).toList(),
onChanged: (value){
setState(() {
_dropDownValue=value;
});
},
);
}
),
SizedBox(height: 10,),
Row(
children: [
Padding(
padding: const EdgeInsets.only(right:8.0),
child: Text("Lecture Start time:",style: TextStyle(color: Colors.black,fontWeight: FontWeight.bold),),
),
Padding(
padding: const EdgeInsets.only(right:20.0),
child: DropdownButton(
hint: starthoour == null
? Text('Choose')
: Text(
starthoour,
style: TextStyle(color: Colors.blue),
),
isExpanded: false,
iconSize: 40.0,
style: TextStyle(color: Colors.blue),
items: ['7 AM', '8 AM', '9 AM',"10 AM","11 AM","12 AM","1 PM","2 PM","3 PM","4 PM","5 PM","6 PM","7 PM","8 PM","9 PM","10 PM"].map(
(val) {
return DropdownMenuItem<String>(
value: val,
child: Text(val),
);
},
).toList(),
onChanged: (val) {
setState(
() {
starthoour = val;
},
);
},
),
),
DropdownButton(
hint: startminute == null
? Text('Choose')
: Text(
startminute,
style: TextStyle(color: Colors.blue),
),
isExpanded: false,
iconSize: 40.0,
style: TextStyle(color: Colors.blue),
items: ['10', '20', '30',"40","50","60"].map(
(val) {
return DropdownMenuItem<String>(
value: val,
child: Text(val),
);
},
).toList(),
onChanged: (val) {
setState(
() {
startminute = val;
},
);
},
),
],
),
SizedBox(height: 20,),
Row(
children: [
Padding(
padding: const EdgeInsets.only(right:8.0),
child: Text("Lecture End time:",style: TextStyle(color: Colors.black,fontWeight: FontWeight.bold),),
),
Padding(
padding: const EdgeInsets.only(right:20.0),
child: DropdownButton(
hint: endhour == null
? Text('Choose')
: Text(
endhour,
style: TextStyle(color: Colors.blue),
),
isExpanded: false,
iconSize: 40.0,
style: TextStyle(color: Colors.blue),
items: ['7 AM', '8 AM', '9 AM',"10 AM","11 AM","12 AM","1 PM","2 PM","3 PM","4 PM","5 PM","6 PM","7 PM","8 PM","9 PM","10 PM"].map(
(val) {
return DropdownMenuItem<String>(
value: val,
child: Text(val),
);
},
).toList(),
onChanged: (val) {
setState(
() {
endhour = val;
},
);
},
),
),
DropdownButton(
hint: endminute == null
? Text('Choose')
: Text(
endminute,
style: TextStyle(color: Colors.blue),
),
isExpanded: false,
iconSize: 40.0,
style: TextStyle(color: Colors.blue),
items: ['10', '20', '30',"40","50","60"].map(
(val) {
return DropdownMenuItem<String>(
value: val,
child: Text(val),
);
},
).toList(),
onChanged: (val) {
setState(
() {
endminute = val;
},
);
},
),
],
),
],
),
),
),
),
),
),
Padding(
padding: const EdgeInsets.only(left: 20.0,right: 20.0,top: 8.0,bottom: 8.0),
child: Container(
width: double.infinity,
height: 60,
child: FlatButton(
color: Colors.black,
onPressed: () {
if(!_formKey.currentState.validate()){
return;
}
else
{
if(_dropDownValue==null||endminute==null||endhour==null||startminute==null||starthoour==null)
{
Fluttertoast.showToast(
msg: "Please choose properly from DropDown",
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.CENTER,
timeInSecForIosWeb: 1,
backgroundColor: Colors.redAccent,
textColor: Colors.white,
fontSize: 16.0
);
}
else
{
_formKey.currentState.validate();
addslot(_dropDownValue,starthoour,startminute,endhour,endminute);
}
}
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: Text("Save",style: TextStyle(color: Colors.white,fontSize: 18,fontWeight: FontWeight.bold),),
),
),
),
Padding(
padding: const EdgeInsets.only(left: 20.0,right: 20.0,top: 8.0,bottom: 8.0),
child: Container(
width: double.infinity,
height: 60,
child: FlatButton(
color: Colors.black,
onPressed: (){
Navigator.pop(context);
},
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.circular(10.0),
),
child: Text("Cancel",style: TextStyle(color: Colors.white,fontSize: 18,fontWeight: FontWeight.bold),),
),
),
),
],
),
),
),
);
}
);
}

Flutter - Validator is not responding with the name is required text and the screen is not moving to next screen after the press

The validator is not showing the error message while I try to click the button without entering anything in the box and even after filling the box the bottom doesn't take me to the next screen.
return Scaffold(
appBar: AppBar(
title: Text("Feedback Form"),
),
body: Container(
child: Center(
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: EdgeInsets.symmetric(horizontal: 50, vertical: 40),
child: TextFormField(
validator: (String value) {
if (value.isEmpty) {
return "Name is required";
}
return null;
},
decoration: InputDecoration(
border: UnderlineInputBorder(),
labelText: 'Enter your Name'),
),
),
ButtonTheme(
child: ElevatedButton(
child: Text("Next"),
onPressed: () {
if (!_formKey.currentState.validate()) {
return;
}
Navigator.push(
context,
MaterialPageRoute(builder: (context) => SecondScreen()),
);
},
style: ElevatedButton.styleFrom(
padding:
EdgeInsets.symmetric(horizontal: 25, vertical: 15),
),
),
),
],
),
),
));
}
}
you forget the Form widget
return Scaffold(
appBar: AppBar(
title: Text("Feedback Form"),
),
body: Container(
child: Center(
child: Form( // add this
autovalidateMode: AutovalidateMode.onUserInteraction, // this to show error when user is in some textField
key: _formKey,
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: EdgeInsets.symmetric(horizontal: 50, vertical: 40),
child: TextFormField(
validator: (String value) {
if (value.isEmpty) {
return "Name is required";
}
return null;
},
decoration: InputDecoration(
border: UnderlineInputBorder(),
labelText: 'Enter your Name'),
),
),
ButtonTheme(
child: ElevatedButton(
child: Text("Next"),
onPressed: () {
if (_formKey.currentState.validate()) { // to check if the form is validate then navigate
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SecondScreen()),
);
}
},
style: ElevatedButton.styleFrom(
padding:
EdgeInsets.symmetric(horizontal: 25, vertical: 15),
),
),
),
],
),
),
)));
Add Form as the child of the Center Widget

Flutter Drawer is not visible and the page gives error

Hi I'm routing menu with Drawer. It works fine for 2 pages but there is one page gives error.
The menu works correctly when I first press it, then when I go to another page and come back it gives this error
Also I tryed routing with routes on mainApp buut this way seemed easier to me
My drawer
class MyDrawer extends StatefulWidget {
#override
State<StatefulWidget> createState() => _MyDrawerState();
}
class _MyDrawerState extends State {
#override
Widget build(BuildContext context) {
return Drawer(
child: ListView(
children: <Widget>[
DrawerHeader(
child: Align(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
"Test",
style: TextStyle(color: Colors.white, fontSize: 25.0),
),
],
),
),
decoration: BoxDecoration(
color: Colors.blue,
),
),
ListTile(
leading: Icon(Icons.home),
title: Text('Main'),
trailing: Icon(Icons.arrow_right),
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => Main(),
));
},
),
ListTile(
leading: Icon(Icons.perm_device_information),
title: Text('How'),
trailing: Icon(Icons.arrow_right),
onTap: () {
//Navigator.pushNamed(context, "/how");
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => HowItWorks(),
));
},
),
ListTile(
leading: Icon(Icons.keyboard),
title: Text('Contact'),
trailing: Icon(Icons.arrow_right),
onTap: () {
//Navigator.pushNamed(context, "/contact");
Navigator.push(
context,
MaterialPageRoute(
builder: (context) => SendMail(),
));
},
),
],
),
);
}
}
this is the page it gives error on second route and drawer is not visible
final _formKey2 = GlobalKey<FormState>();
class SendMail extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Scaffold(
drawer: MyDrawer(),
body: Center(
child: Form(
key: _formKey2,
child: Padding(
padding: const EdgeInsets.all(18.0),
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(48.0),
child: Text(
'İletişim',
style: TextStyle(fontWeight: FontWeight.bold),
),
),
Text('Contact Me'),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
keyboardType: TextInputType.text,
validator: (value) {
if (value.isEmpty) {
return 'Can not be empty';
}
return null;
},
decoration: InputDecoration(
filled: true,
hintText: 'Name',
border: InputBorder.none),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
keyboardType: TextInputType.emailAddress,
decoration: InputDecoration(
filled: true,
hintText: 'Email',
border: InputBorder.none),
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: TextFormField(
maxLines: 7,
validator: (value) {
if (value.isEmpty) {
return 'Can not be empty';
}
return null;
},
decoration: InputDecoration(
filled: true,
hintText: 'Message',
border: InputBorder.none),
),
),
],
),
)
],
),
Detailed error

How to implement dropdown inside popup menu in flutter

I need a popup menu or any other way to implement layout like this in flutter. I have tried to implememnt it in popup view but I wasn't successful. Please help me with this problem.
Here is the code I have tried, implementing it using any other method also will be fine. This code gives error no material widget found, if it can be fixed it'll also be helpful for me.
void showFilter() {
showGeneralDialog(
barrierLabel: "Barrier",
barrierDismissible: true,
barrierColor: Colors.black.withOpacity(0.5),
transitionDuration: Duration(milliseconds: 700),
context: context,
pageBuilder: (_, __, ___) {
return Align(
alignment: Alignment.center,
child: Container(
height: 300,
child: SizedBox.expand(
child:Column(
children: <Widget>[
Container(
padding: EdgeInsets.only( top: SizeConfig.blockSizeHorizontal*2, left: SizeConfig.blockSizeHorizontal*6),
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Text("Monthly Summary", style: TextStyle(fontSize: SizeConfig.blockSizeHorizontal*6, color: Colors.black87,decoration: TextDecoration.none,),),
],
)
),
Container(
padding: EdgeInsets.only(top:SizeConfig.blockSizeHorizontal*2, left: SizeConfig.blockSizeHorizontal*3, right: SizeConfig.blockSizeHorizontal*3),
child: Divider(
color: Colors.black87,thickness: 2.0,
),
),
Container(
padding: EdgeInsets.only(left: SizeConfig.blockSizeHorizontal*6, top: SizeConfig.blockSizeHorizontal*4),
child: Row(
children: <Widget>[
Container(
child: Row(
children: <Widget>[
Text("Year - ", style: TextStyle(fontSize: SizeConfig.blockSizeHorizontal*4.5, color: Colors.black87,decoration: TextDecoration.none,),)
],
),
),
Container(
child: Row(
children: <Widget>[
Container(
child: DropdownButton(
value: _dpdValue,
underline: Container(),
isExpanded: true,
iconSize: 30.0,
items: _dropdownValues.map((val) {
return new DropdownMenuItem<String>(
value: val,
child: new Text(val),
);
}).toList(),
onChanged: (val) {
if (!mounted) return;
setState(
() {
_dpdValue = val;
},
);
},
),
)
],
),
)
],
)
)
],
)
),
margin: EdgeInsets.only(top: SizeConfig.blockSizeHorizontal*15, left: SizeConfig.blockSizeHorizontal*3, right: SizeConfig.blockSizeHorizontal*3),
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.circular(SizeConfig.blockSizeHorizontal*6),
),
),
);
},
transitionBuilder: (_, anim, __, child) {
return SlideTransition(
position: Tween(begin: Offset(0, 1), end: Offset(0, 0)).animate(anim),
child: child,
);
},
);
}
I have used an Alertdialog for this,, hope it offers insight to solving your problem,
int year = 1990;
List<String> months = ['January', 'February', 'March'];
List<String> years = [];
String option, month;
#override
void initState() {
super.initState();
for (int i = year; i < 2020; i++) {
years.add(i.toString());
}
}
Future<bool> errorDialog(context) async {
Size size = MediaQuery.of(context).size;
return showDialog(
context: context,
barrierDismissible: false,
builder: (BuildContext context) {
return StatefulBuilder(builder: (context, setState) {
return AlertDialog(
backgroundColor: Colors.white,
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(20.0))),
content: Padding(
padding: const EdgeInsets.all(8.0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: Text("Monthly Summary"),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('Year-'),
Container(
width: size.width * 0.5,
decoration: BoxDecoration(
border: Border.all(
color:Colors.amber),
borderRadius:
BorderRadius.all(Radius.circular(5))),
child: DropdownButtonFormField<String>(
decoration: InputDecoration(
contentPadding:
EdgeInsets.fromLTRB(10, 0, 10, 0),
filled: true,
fillColor: Colors.white,
hintText: 'Select Year',
hintStyle:
TextStyle(fontWeight: FontWeight.normal)),
value: option,
icon: Icon(Icons.arrow_drop_down),
iconSize: 24,
elevation: 16,
style: TextStyle(color: Colors.black),
onChanged: (String newValue) {
setState(() {
option = newValue;
});
},
validator: (value) {
if (value == null) {
return "Select Year";
}
return null;
},
items: years
.map<DropdownMenuItem<String>>((String option) {
return DropdownMenuItem<String>(
value: option,
child: Text(option),
);
}).toList(),
),
),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text('Month-'),
Container(
decoration: BoxDecoration(
border: Border.all(
color:Colors.amber),
borderRadius:
BorderRadius.all(Radius.circular(5))),
width: size.width * 0.5,
child: DropdownButtonFormField<String>(
decoration: InputDecoration(
contentPadding:
EdgeInsets.fromLTRB(10, 0, 10, 0),
filled: true,
fillColor: Colors.white,
hintText: 'Select Month',
hintStyle:
TextStyle(fontWeight: FontWeight.normal)),
value: month,
icon: Icon(Icons.arrow_drop_down),
iconSize: 24,
elevation: 16,
style: TextStyle(color: Colors.black),
onChanged: (String newValue) {
setState(() {
month = newValue;
});
},
validator: (value) {
if (value == null) {
return "Select Month";
}
return null;
},
items: months
.map<DropdownMenuItem<String>>((String option) {
return DropdownMenuItem<String>(
value: option,
child: Text(option),
);
}).toList(),
),
),
],
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Padding(
padding: const EdgeInsets.all(8.0),
child: RaisedButton(
color: Colors.amber,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(2.0))),
child: Text(
"CANCEL",
style: TextStyle(color: Colors.black),
),
onPressed: () {
Navigator.of(context).pop();
},
),
),
Padding(
padding: const EdgeInsets.all(8.0),
child: RaisedButton(
color: Colors.amber,
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.all(Radius.circular(2.0))),
child: Text(
"SEARCH",
style: TextStyle(color: Colors.black),
),
onPressed: () {
Navigator.of(context).pop();
},
),
),
],
),
),
],
),
),
);
});
});
}