selected dropdown height overflow - flutter

so i have this dropdown and the DropdownMenuItem i have ListTile, below is the option result
after i select it the result become like this
Here is my script
Visibility(
visible: _signalEmiten != null,
child: Container(
height: 150.w,
child: FutureBuilder<List<Mt5Model>>(
future: getData(),
builder: (BuildContext context, AsyncSnapshot snapshot) {
if (snapshot.hasError) {
return Text("ERROR PLEASE RE OPEN SCREEN");
}
return snapshot.hasData
? Container(
child: DropdownButtonFormField(
itemHeight: 150.w,
decoration: InputDecoration(
labelText: 'Choose Account',
),
items: snapshot.data
.map<DropdownMenuItem>((Mt5Model item) {
return DropdownMenuItem(
value: item.mt5Id,
child: Container(
padding:
EdgeInsets.symmetric(vertical: 5.w),
width: MediaQuery.of(context).size.width *
.80,
child: ListTile(
dense: true,
//leading: Text(item.mt5Id.toString()),
title: Text("123456"),
subtitle: Column(
mainAxisAlignment:
MainAxisAlignment.start,
crossAxisAlignment:
CrossAxisAlignment.start,
children: [
Text("Account Type : " + "Type 1"),
Text("Equity : \$ " + "XXXX"),
],
),
),
),
);
}).toList(),
onChanged: (value) {
setState(() {
dropDownValue = value;
populateAccount();
});
},
),
)
: Container(
child: Center(
child: Text('Loading...'),
),
);
},
),
),
),
i already trying to increate the height of my container and DropdownButtonFormField height, but still no help. So, how can i fix it ?

Here I tried to solve the issue, you need to wrap the ListTile subtitle with SingleChildScrollView and enable isThreeLine.you can check with the example below.
void main() => runApp( const MyApp());
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return const MaterialApp(
home: DropDownExample(),
);
}
}
class DropDownExample extends StatefulWidget {
const DropDownExample({Key? key}) : super(key: key);
#override
_DropDownExampleState createState() => _DropDownExampleState();
}
class _DropDownExampleState extends State<DropDownExample> {
String dropDownValue = "rohit";
#override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: DropdownButtonFormField(
itemHeight: 100,
decoration: const InputDecoration(
labelText: 'Choose Account',
contentPadding: EdgeInsets.symmetric(vertical: 30)),//Fit the content on dropdown selected value
menuMaxHeight: 300,
value: dropDownValue,
isExpanded: true,
isDense: true,
iconSize: 30,
items: ["rohit", "manish"].map<DropdownMenuItem>((item) {
return DropdownMenuItem(
value: item,
child: Container(
width: MediaQuery.of(context).size.width * .80,
child: ListTile(
dense: false,
//leading: Text(item.mt5Id.toString()),
isThreeLine: true, //getting extra height for ListTile
title: Text("123456"),
subtitle: Container(
color: Colors.yellow,
child: SingleChildScrollView( //to solve over flow issues
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text("Equity : \$ " + item),
Text("Account Type : " + "Type 1"),
],
),
),
),
),
),
);
}).toList(),
onChanged: _te,
)),
);
}
void _te(value) {
setState(() {
dropDownValue = value.toString();
// populateAccount();
});
}
}

I think you need to remove first container
height: 150.w,

Related

Flutter multiple ExpansionTile's collapses simultaneously

I have a custom Card widget with ExpansionTile as a child which displays multiple Dropdownbuttons according to data fetched from an API.
But when I use ListView.builder to build N amount of said custom widgets they all behave simultaneously, for example when I collapse the ExpansionTile all open ExpansionTiles collapse simultaneously and reset the data inside Dropdownbuttons (resetting the data expected outcome when ExpansionTile collapsed but only the collapsed ExpansionTile should reset its children Dropdownbuttons, not all open ExpansionTiles children).
Here is my builder.
var items = ["Apartment 1", "Apartment 2", "Apartment 3", "Apartment 4"];
class MapPage extends StatelessWidget {
const MapPage({super.key});
#override
Widget build(BuildContext context) {
return Scaffold(
body: ListView.builder(
key: ValueKey(items),
scrollDirection: Axis.vertical,
itemCount: items.length,
padding: const EdgeInsets.only(top: 8),
itemBuilder: (context, index) {
return MapCard(
building: items[index],
floor: 4,
key: Key(items[index].toString()),
);
}),
);
}
}
and my CustomCard
class MapCard extends StatefulWidget {
final String building;
final int floor;
const MapCard({super.key, required this.building, required this.floor});
#override
State<MapCard> createState() => _MapCardState();
}
class _MapCardState extends State<MapCard> {
#override
Widget build(BuildContext context) {
PageStorageKey key = PageStorageKey('${widget.key}');
return Center(
child: Consumer<MapCardViewModel>(
builder: (context, mapCardViewModel, child) => Card(
color: Colors.white,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
child: SizedBox(
width: MediaQuery.of(context).size.width * 0.9,
child: Padding(
padding: const EdgeInsets.only(bottom: 12),
child: ExpansionTile(
key: key,
onExpansionChanged: (changed) {
if (!changed) {
mapCardViewModel.setAreaVisibility(false);
mapCardViewModel.setButtonVisibility(false);
mapCardViewModel.setIsFloorChosen(false);
mapCardViewModel.setAreaVisibility(false);
mapCardViewModel.area = mapCardViewModel.areas[0];
mapCardViewModel.floorNumber = mapCardViewModel.floors[0];
}
},
title: Row(
children: [
Container(
padding:
const EdgeInsets.only(top: 8, bottom: 8, right: 8),
child: Image.asset(
"assets/images/example.png",
height: 80,
width: 80,
)),
Flexible(
child: Container(
padding: const EdgeInsets.fromLTRB(0, 8, 8, 8),
child: Column(
children: [
Text("${widget.building} Apartment \n"
"Floor Count ${widget.floor} ")
],
),
),
)
],
),
children: [
const Text("Choose Floor"),
Padding(
padding: const EdgeInsets.only(right: 24, left: 24),
child: DropdownButton(
isExpanded: true,
value: mapCardViewModel.isFloorChosen == false
? mapCardViewModel.floors[0]
: mapCardViewModel.floorNumber,
items: mapCardViewModel.floors
.map<DropdownMenuItem<int>>((int i) {
return DropdownMenuItem<int>(
value: i,
child: Text(i.toString()),
);
}).toList(),
onChanged: (int? value) {
mapCardViewModel.setFloorNumber(value!);
mapCardViewModel.setIsFloorChosen(true);
mapCardViewModel.setAreaVisibility(true);
}),
),
Visibility(
visible: mapCardViewModel.isAreaVisible,
child: Column(
children: [
const Text("Choose an Area to map"),
Padding(
padding: const EdgeInsets.only(right: 24, left: 24),
child: DropdownButton(
isExpanded: true,
value: mapCardViewModel.isAreaChosen == false
? mapCardViewModel.areas[0]
: mapCardViewModel.area,
items: mapCardViewModel.areas
.map<DropdownMenuItem<String>>(
(String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
onChanged: (String? value) {
mapCardViewModel.setArea(value!);
mapCardViewModel.setIsAreaChosen(true);
mapCardViewModel.setButtonVisibility(true);
}),
),
],
),
),
Visibility(
visible: mapCardViewModel.isButtonsVisible,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
TextButton(
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return CustomDialog(
title: "Mapping Status",
content:
"This area hasn't been mapped yet",
page: Container(),
buttonColor: MainColors().mainBlue);
});
},
child: const Text("Show Area Map")),
ElevatedButton(
onPressed: () {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => const MappedPage(),
),
);
},
style: ElevatedButton.styleFrom(
backgroundColor: MainColors().mainBlue),
child: const Text(
"Map The Area",
style: TextStyle(color: Colors.white),
))
],
),
)
],
),
)),
),
));
}
}
I tried to assign keys to each ExpansionTile and custom MapCard widgets with StatefulWidget but I couldn't solve my problem.
I remove all 3rd dependency and try to adjust your solution of MapCard widget.
var items = ["Apartment 1", "Apartment 2", "Apartment 3", "Apartment 4"];
final floors = ['Floor 1', 'Floor 2'];
final areas = ['Area 1', 'Area 2'];
class MapCard extends StatefulWidget {
final String building;
final int floor;
const MapCard({Key? key, required this.building, required this.floor}): super(key: key);
#override
State<MapCard> createState() => _MapCardState();
}
class _MapCardState extends State<MapCard> {
#override
Widget build(BuildContext context) {
PageStorageKey key = PageStorageKey('${widget.key}');
return Center(
child: Card(
color: Colors.white,
shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(12)),
child: SizedBox(
width: MediaQuery.of(context).size.width * 0.9,
child: Padding(
padding: const EdgeInsets.only(bottom: 12),
child: ExpansionTile(
key: key,
onExpansionChanged: (changed) {
if (!changed) {
print('!changed');
}
},
title: Row(
children: [
Container(
padding:
const EdgeInsets.only(top: 8, bottom: 8, right: 8),
child: Placeholder(
fallbackHeight: 80,
fallbackWidth: 80,
)),
Flexible(
child: Container(
padding: const EdgeInsets.fromLTRB(0, 8, 8, 8),
child: Column(
children: [
Text("${widget.building} Apartment \n"
"Floor Count ${widget.floor} ")
],
),
),
)
],
),
children: [
const Text("Choose Floor"),
Padding(
padding: const EdgeInsets.only(right: 24, left: 24),
child: DropdownButton(
isExpanded: true,
value: floors.first,
items: floors
.map<DropdownMenuItem<String>>((String i) {
return DropdownMenuItem<String>(
value: i,
child: Text(i.toString()),
);
}).toList(),
onChanged: (String? value) {
// code here
}),
),
Visibility(
visible: true,
child: Column(
children: [
const Text("Choose an Area to map"),
Padding(
padding: const EdgeInsets.only(right: 24, left: 24),
child: DropdownButton(
isExpanded: true,
value: areas.first,
items: areas
.map<DropdownMenuItem<String>>(
(String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
onChanged: (String? value) {
// code here
}),
),
],
),
),
Visibility(
visible: true,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
TextButton(
onPressed: () {
showDialog(
context: context,
builder: (BuildContext context) {
return AlertDialog(content: Text('Alert dialog'),);
});
},
child: const Text("Show Area Map")),
ElevatedButton(
onPressed: () {
print('navigate');
},
child: const Text(
"Map The Area",
style: TextStyle(color: Colors.white),
))
],
),
)
],
),
)),
),
);
}
}
But I suppose your problem in the line
Consumer<MapCardViewModel>
because every time when you change it this will apply to each created card. So you have to put it above your ListView.builder and pass it as a parameter to your cards

Dependent drop down that display data from real time database using flutter but I got error

In first drop down I display exam keys(spring and fall). In second drop semesters are shown according to user selected value of exam for example if user select fall from first drop down it display semester 1,3,5,7. Then if user select semester than relative courses are shown on another drop down
here is my database structure
I write code for this scenario. But it works only for first time if I change exam drop down value it gives me error
import 'package:flutter/material.dart';
import 'package:firebase_database/firebase_database.dart';
class homepg extends StatelessWidget {
const homepg({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("home"),
),
body: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
#override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
var ref = FirebaseDatabase.instance.ref();
var _selectedexam;
var _selectedsemester;
var _selectedcourse;
#override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.all(15),
child: Center(
child: Column(
children: <Widget>[
Row(
children: [
const Align(
alignment: Alignment.centerLeft,
child: Text(
"Exam ",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
),
),
const SizedBox(
width: 40,
),
Container(
width: 400,
child: FutureBuilder(
future: ref.child("/Exam").get(),
builder:
(context, AsyncSnapshot<DataSnapshot> asyncSnapshot) {
if (asyncSnapshot.hasError)
return Text("Error: ${asyncSnapshot.error}");
if (!asyncSnapshot.hasData)
return const CircularProgressIndicator();
return DropdownButton<String>(
isExpanded: true,
items: asyncSnapshot.data!.children
.map((snap) => DropdownMenuItem(
value: snap.key,
child: Text(snap.key.toString())))
.toList(),
value: _selectedexam,
onChanged: (String? newValue) {
setState(() {
_selectedexam = newValue!;
print(_selectedexam);
});
},
);
}),
),
],
),
const SizedBox(
height: 100,
),
Row(
children: [
const Align(
alignment: Alignment.centerLeft,
child: Text(
"Semester",
style:
TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
)),
const SizedBox(
width: 20,
),
Container(
width: 400,
child: FutureBuilder(
future: ref.child("/Exam/$_selectedexam").get(),
builder:
(context, AsyncSnapshot<DataSnapshot> asyncSnapshot) {
if (asyncSnapshot.hasError)
return Text("Error: ${asyncSnapshot.error}");
if (!asyncSnapshot.hasData)
return const CircularProgressIndicator();
return DropdownButton<String>(
isExpanded: true,
items: asyncSnapshot.data!.children
.map((snap) => DropdownMenuItem(
value: snap.key,
child: Text(snap.key.toString())))
.toList(),
value: _selectedsemester,
onChanged: (String? newValue) {
setState(() {
//_selectedexam = null;
_selectedsemester = newValue!;
print(_selectedsemester);
});
},
);
}),
),
],
),
const SizedBox(
height: 100,
),
Row(
children: [
const Align(
alignment: Alignment.centerLeft,
child: Text(
"Course",
style:
TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
)),
const SizedBox(
width: 40,
),
Container(
width: 400,
child: FutureBuilder(
future: ref
.child("/Exam/$_selectedexam/$_selectedsemester")
.get(),
builder:
(context, AsyncSnapshot<DataSnapshot> asyncSnapshot) {
if (asyncSnapshot.hasError)
return Text("Error: ${asyncSnapshot.error}");
if (!asyncSnapshot.hasData)
return const CircularProgressIndicator();
return DropdownButton<String>(
isExpanded: true,
items: asyncSnapshot.data!.children
.map((snap) => DropdownMenuItem(
value: snap.key,
child: Text(snap.key.toString())))
.toList(),
value: _selectedcourse,
onChanged: (String? newValue) {
setState(() {
_selectedcourse = newValue!;
print(_selectedcourse);
});
},
);
}),
),
],
),
],
),
),
);
below is my error message details. when I run it first time it works well but if I change value from fall to spring it gives me error
error display on output screen
error display on debug console

I got an error while displaying data in dependent drop down in real time database using flutter

import 'package:flutter/material.dart';
import 'package:firebase_database/firebase_database.dart';
class homepg extends StatelessWidget {
const homepg({Key? key}) : super(key: key);
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("home"),
),
body: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key}) : super(key: key);
#override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
var ref = FirebaseDatabase.instance.ref();
var _selectedexam;
var _selectedsemester;
var _selectedcourse;
#override
Widget build(BuildContext context) {
return Container(
margin: EdgeInsets.all(15),
child: Center(
child: Column(
children: <Widget>[
Row(
children: [
const Align(
alignment: Alignment.centerLeft,
child: Text(
"Exam ",
style: TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
),
),
const SizedBox(
width: 40,
),
Container(
width: 400,
child: FutureBuilder(
future: ref.child("/Exam").get(),
builder:
(context, AsyncSnapshot<DataSnapshot> asyncSnapshot) {
if (asyncSnapshot.hasError)
return Text("Error: ${asyncSnapshot.error}");
if (!asyncSnapshot.hasData)
return const CircularProgressIndicator();
return DropdownButton<String>(
isExpanded: true,
items: asyncSnapshot.data!.children
.map((snap) => DropdownMenuItem(
value: snap.key,
child: Text(snap.key.toString())))
.toList(),
value: _selectedexam,
onChanged: (String? newValue) {
setState(() {
_selectedexam = newValue!;
print(_selectedexam);
});
},
);
}),
),
],
),
const SizedBox(
height: 100,
),
Row(
children: [
const Align(
alignment: Alignment.centerLeft,
child: Text(
"Semester",
style:
TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
)),
const SizedBox(
width: 20,
),
Container(
width: 400,
child: FutureBuilder(
future: ref.child("/Exam/$_selectedexam").get(),
builder:
(context, AsyncSnapshot<DataSnapshot> asyncSnapshot) {
if (asyncSnapshot.hasError)
return Text("Error: ${asyncSnapshot.error}");
if (!asyncSnapshot.hasData)
return const CircularProgressIndicator();
return DropdownButton<String>(
isExpanded: true,
items: asyncSnapshot.data!.children
.map((snap) => DropdownMenuItem(
value: snap.key,
child: Text(snap.key.toString())))
.toList(),
value: _selectedsemester,
onChanged: (String? newValue) {
setState(() {
//_selectedexam = null;
_selectedsemester = newValue!;
print(_selectedsemester);
});
},
);
}),
),
],
),
const SizedBox(
height: 100,
),
Row(
children: [
const Align(
alignment: Alignment.centerLeft,
child: Text(
"Course",
style:
TextStyle(fontWeight: FontWeight.bold, fontSize: 18),
)),
const SizedBox(
width: 40,
),
Container(
width: 400,
child: FutureBuilder(
future: ref
.child("/Exam/$_selectedexam/$_selectedsemester")
.get(),
builder:
(context, AsyncSnapshot<DataSnapshot> asyncSnapshot) {
if (asyncSnapshot.hasError)
return Text("Error: ${asyncSnapshot.error}");
if (!asyncSnapshot.hasData)
return const CircularProgressIndicator();
return DropdownButton<String>(
isExpanded: true,
items: asyncSnapshot.data!.children
.map((snap) => DropdownMenuItem(
value: snap.key,
child: Text(snap.key.toString())))
.toList(),
value: _selectedcourse,
onChanged: (String? newValue) {
setState(() {
_selectedcourse = newValue!;
print(_selectedcourse);
});
},
);
}),
),
],
),
],
),
),
);
}
}
Here is the complete code. I want to display data in a dependent dropdown but I got error kindly tell me how to solve it. In first drop down I display exam(spring and fall) if user clicks on spring it displays related semesters in another drop down. It works fine for first time but when I change drop down value error shown Thanks
drop downs structure
error image after changing first drop down value
From what i see is when you have selected the first dropdown and based on that you have selected the second dropdown. And now you change the first dropdown the second dropdown will give error. for that you have to do the following thing in the code.
FutureBuilder (
future: ref.child("/Exam/$_selectedexam").get(),
builder: (context, AsyncSnapshot<DataSnapshot> asyncSnapshot) {
if (asyncSnapshot.hasError)
return Text("Error: ${asyncSnapshot.error}");
if (!asyncSnapshot.hasData)
return const CircularProgressIndicator();
return DropdownButton<String> (
items: asyncSnapshot.data!.children
.map((snap) => DropdownMenuItem(
value: snap.key, child: Text(snap.key.toString())))
.toList(),
value: _selectedsemester,
onChanged: (String? newValue) {
setState(() {
_selectedexam = null;/*or you can check this as well _selectedexam = ''; */ // make it null for empty
_selectedsemester = newValue!;
print(_selectedsemester);
});
},
);
}),
you can check this and let me know if it works for you.
End Solution:
Main cause is when the item is changed the dependent dropdown should be bought to initial state.

content vanish every time I restart the app

I created a page where I can add exercise for my classes and in this page students can create their custom training (it's a gym app), the only problem is that every time the user closes the app all the training is gone.
I leave below my code, I've done some researches and I kind of understood that there is something with SharPreferences but all the tutorial talk about a login page which is not my case.
can you please advise?? I leave my code below, thanks!
import 'package:flutter/material.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
class Custom extends StatefulWidget {
#override
_CustomState createState() => new _CustomState();
}
class _CustomState extends State<Custom> {
int _count = 0;
#override
Widget build(BuildContext context) {
List<Widget> _esercizi = List.generate(_count, (int i) => Esercizi());
bool visible = _count > 0;
return GestureDetector(
onTap: () {
FocusScope.of(context).requestFocus(FocusNode());
},
child: Scaffold(
appBar: AppBar(
title: Text('Scheda personalizzata'),
actions: [
Visibility(
visible: visible,
child: IconButton(
icon: Icon(Icons.remove_rounded),
onPressed: _removeNewEsercizi,
),
),
IconButton(icon: Icon(Icons.add), onPressed: _addNewEsercizi),
],
backgroundColor: Colors.blueGrey,
),
body: LayoutBuilder(builder: (context, constraint) {
return Padding(
padding: const EdgeInsets.all(10.0),
child: SingleChildScrollView(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
Container(
height: 700,
child: ListView(
scrollDirection: Axis.vertical,
children: _esercizi,
),
),
//new ContactRow()
],
),
),
);
}),
),
);
}
void _addNewEsercizi() {
setState(() {
_count = _count + 1;
});
}
void _removeNewEsercizi() {
setState(() {
_count = _count - 1;
});
}
}
class Esercizi extends StatefulWidget {
#override
State<StatefulWidget> createState() => _Esercizi();
}
class _Esercizi extends State<Esercizi> {
String dropdownValue = 'Seleziona esercizio';
#override
Widget build(BuildContext context) {
Size size = MediaQuery.of(context).size;
return Padding(
padding: const EdgeInsets.all(2.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: [
DropdownButton<String>(
value: dropdownValue,
style: TextStyle(color: Colors.blueGrey),
onChanged: (String newValue) {
setState(() {
dropdownValue = newValue;
});
},
items: <String>['Seleziona esercizio', 'One', 'Two', 'Three', 'Fo'
'ur', 'Five', 'Six']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
),
Container(
height: 50,
width: 90,
child: Center(
child: Padding(
padding: const EdgeInsets.all(8.0),
child: TextField(
cursorColor: Colors.white,
decoration: InputDecoration(
hintText: 'Time/Reps',
hintStyle: TextStyle(color: Colors.blueGrey),
),
keyboardType: TextInputType.number,
),
),
),
),
],
),
);
}
}

Passing stateless widget from one screen to another screen in Flutter

I am trying to create a form builder, In one screen I want have small container with icon and text with gesture detector, when I tap on the container it should contruct a new DatePicker Widget. I know how to do it in the same screen, but onTap I want construct the Datepicker in another screen.
This is Form Component Class.
class FormComponents extends StatefulWidget {
#override
_FormComponentsState createState() => _FormComponentsState();
}
class _FormComponentsState extends State<FormComponents> {
final GlobalKey<FormBuilderState> _fbKey = GlobalKey<FormBuilderState>();
int _count = 0;
final formData = FormWidgetData(widget: DatePicker());
#override
Widget build(BuildContext context) {
List<Widget> datePicker = List.generate(_count, (index) => DatePicker());
return Scaffold(
appBar: AppBar(
title: Text('Form Components'),
),
body: Container(
margin: EdgeInsets.all(8.0),
child: Column(
children: <Widget>[
FormBuilder(
key: _fbKey,
initialValue: {
'date': DateTime.now(),
'accept_terms': false,
},
autovalidate: true,
child: Column(
children: <Widget>[
Builder(
builder: (BuildContext context) {
return GestureDetector(
onTap: () {
setState(() {
_count = _count + 1;
});
Scaffold.of(context).showSnackBar(
SnackBar(
content: Text('Date Picker'),
duration: Duration(seconds: 2),
),
);
},
child: Container(
margin: EdgeInsets.all(16.0),
padding: EdgeInsets.all(8.0),
height: 100.0,
width: 120.0,
color: Colors.black,
child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
children: <Widget>[
Icon(
Icons.date_range,
color: Colors.white,
),
Text(
'Date Picker',
style: TextStyle(
color: Colors.white, fontSize: 18.0),
),
],
),
),
);
},
),
Container(
height: 200.0,
margin: EdgeInsets.all(8.0),
child: Expanded(
child: ListView(
children: datePicker,
),
),
),
],
),
),
],
),
),
);
}
}
This is my Date Picker Class
class DatePicker extends StatelessWidget {
#override
Widget build(BuildContext context) {
return Container(
child: FormBuilderDateTimePicker(
attribute: 'date',
inputType: InputType.date,
format: DateFormat('yyyy-MM-dd'),
decoration: InputDecoration(labelText: 'AppointmentTime'),
),
);
}
}
This is my Form Builder Class, How to do I Construct the above Date Picker class here.
class MyFormBuilder extends StatefulWidget {
final FormWidgetData data;
MyFormBuilder({this.data});
#override
_MyFormBuilderState createState() => _MyFormBuilderState();
}
class _MyFormBuilderState extends State<MyFormBuilder> {
#override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Form Builder'),
),
body: Container(
height: 300.0,
margin: EdgeInsets.all(8.0),
child: Expanded(
child: ListView(
children: <Widget>[],
),
),
),
);
}
}