I have previously posted about this problem I am still facing Which is to return data from a Stateful widget back to a Stateless Widget
The Widget I am using is DateTimePickerFormField widget and I am using it as a child in a stateful widget
So I have looked at https://flutter.io/docs/cookbook/navigation/returning-data#complete-example
For returning data from a widget. However, the widget that is returning the data is a stateless widget ...Which in my case isn't
So The code goes as follows
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Add a Reminder'),
),
body:
new Container(
padding: new EdgeInsets.all(20.0),
child: new Form(
child: new ListView(
children: <Widget>[
new TextFormField(
keyboardType: TextInputType.text,
// Use email input type for emails.
decoration: new InputDecoration(
hintText: 'Title of reminder',
),
),
dateAndTimeWidget(context),
RaisedButton(
child: Text('Save'),
onPressed: () {
Navigator.pop(context);
},
)
],
),)
,
)
,
);
}
That Widget is calling the method: dateAndTimeWidget, Which is supposed to return the dateTime stateful widget and save the outcoming data in a variable :
dateAndTimeWidget(BuildContext context) async {
final result = await Navigator.push(
context,
MaterialPageRoute(builder: (context)=> dateTime()),
);
}
Then This is the dateTime Statful widget
class dateTime extends StatefulWidget{
@override
dateTimeState createState() => dateTimeState();
}
class dateTimeState extends State<dateTime>{
static DateTime dateT;
InputType inputType = InputType.both;
final formats = {
InputType.both: DateFormat("EEEE, MMMM d, yyyy 'at' h:mma"),
InputType.date: DateFormat('yyyy-MM-dd'),
InputType.time: DateFormat("HH:mm"),
};
Widget build(BuildContext context) => Container(
child: DateTimePickerFormField(
inputType: InputType.both,
editable: true,
format: formats[inputType],
decoration: InputDecoration(
labelText: 'Date/Time', hasFloatingPlaceholder: false),
onChanged: (dt) {
setState(() => dateT = dt);
Navigator.of(context).pop(dateT);
},
)
);
}
I am not using the value result yet Because the error is that I never get to the add reminder page and it says that the result push navigation method is pointing at null