title: StartDate and EndDate is resetting back Flutter
body: <p>Im trying to make changes in the existing code where in Firstpage it take the name of the trip and StartDate and Endate and other details. When the user click on upload image and comeback to main page I'm able to save the other field data in void savedata() but I'm stuck with how to store the data of startdate and enddate what the user has chosen before he going to second page. <a href="https://i.stack.imgur.com/w4Rut.png" rel="nofollow noreferrer">enter image description here</a> - I have attached the screenshot how it looks when he choose the date and after coming back to firstpage from secondpage it shows like second picture. <a href="https://i.stack.imgur.com/UMsFl.png" rel="nofollow noreferrer">enter image description here</a> my requirement here is how other field are storing the date I want startdate and enddate also store.</p>
  <pre><code>class _MyHomePageState extends State&lt;DataInfoPage&gt; {
    _DataInfoPageState createState() =&gt; _DataInfoPageState();
    String date = &quot;&quot;;
  
    final FirebaseAuth _auth = FirebaseAuth.instance;
    User? user;
    var name = '';
  
    @override
    void initState() {
      super.initState();
      initUser();
      savedata();
    }
  
    initUser() async {
      user = (_auth.currentUser!);
      name = user!.displayName!;
      setState(() {});
    }
  
    void savedata() {
      final absavedata = context.read&lt;AddTripBloc&gt;();
      if (absavedata.tripname != null) {
        tripname.text = absavedata.tripname!;
        //_selectedDateRange!.start = absavedata.sdate;
        //_selectedDateRange!.end;
        noofdays.text = absavedata.noofdays!;
        noofnights.text = absavedata.noofnights!;
        slotavail.text = absavedata.slotavail!;
        priceperpers.text = absavedata.priceperpers!;
      }
    }
  
    final GlobalKey&lt;FormState&gt; _formKey = GlobalKey&lt;FormState&gt;();
  
    // DateTime selectedDate = DateTime.now();
    //DateTime startDate = DateTime();
    TextEditingController tripname = new TextEditingController();
    TextEditingController noofdays = new TextEditingController();
    TextEditingController noofnights = new TextEditingController();
    TextEditingController slotavail = new TextEditingController();
    TextEditingController priceperpers = new TextEditingController();
    DateTimeRange? startdate;
    DateTimeRange? enddate;
  
    DateTimeRange? _selectedDateRange;
  
    String _displayText(String begin, DateTime? date) {
      if (date != null) {
        return '$begin Date: ${date.toString().split(' ')[0]}';
      } else {
        return 'Press the button to show the picker';
      }
    }
  
    @override
    Widget build(BuildContext context) {
      return Scaffold(
          resizeToAvoidBottomInset: false,
          body: SingleChildScrollView(
            child: Form(
              key: _formKey,
              child: Column(
                children: &lt;Widget&gt;[
                  SizedBox(
                    height: 20,
                  ),
                  Text(
                    &quot;Please enter trip details &quot;,
                    style: const TextStyle(
                        fontWeight: FontWeight.bold,
                        fontSize: 25,
                        color: Colors.black),
                  ),
                  SizedBox(
                    height: 20,
                  ),
                  Padding(
                      padding: EdgeInsets.fromLTRB(10, 10, 10, 0),
                      child: Column(
                        crossAxisAlignment: CrossAxisAlignment.stretch,
                        children: &lt;Widget&gt;[
                          customfields(
                              hintValue: ' Enter Trip Name',
                              labeltxt: 'Trip Name *',
                              keyboardtype: TextInputType.text,
                              text: tripname),
                          SizedBox(
                            height: 20,
                          ),
                          Row(
                            mainAxisAlignment: MainAxisAlignment.spaceBetween,
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              FloatingActionButton(
                                  onPressed: _show,
                                  child: const Icon(Icons.date_range_rounded),
                                  shape: BeveledRectangleBorder(
                                      borderRadius: BorderRadius.circular(5))),
                              Column(
                                children: [
                                  Text(
                                    _displayText(
                                        'Start', _selectedDateRange?.start),
                                    style: const TextStyle(
                                        fontWeight: FontWeight.bold,
                                        fontSize: 15,
                                        color: Colors.black),
                                  ),
                                  SizedBox(
                                    height: 20,
                                  ),
                                  Text(
                                      _displayText(
                                          'End', _selectedDateRange?.end),
                                      style: const TextStyle(
                                          fontWeight: FontWeight.bold,
                                          fontSize: 15,
                                          color: Colors.black))
                                ],
                              ),
                              SizedBox(
                                height: 20,
                              ),
                            ],
                          ),
                          SizedBox(
                            height: 20,
                          ),
                          customfields(
                              hintValue: ' No.of Days *',
                              labeltxt: 'No.of Days *',
                              keyboardtype: TextInputType.number,
                              text: noofdays),
  
                          SizedBox(
                            height: 20,
                          ),
  
                          customfields(
                              hintValue: 'No.of Nights*',
                              labeltxt: 'No.of Nights*',
                              keyboardtype: TextInputType.number,
                              text: noofnights),
                          SizedBox(
                            height: 20,
                          ),
                          customfields(
                            hintValue: 'Slots Available: *',
                            labeltxt: 'Slots Available: *',
                            keyboardtype: TextInputType.number,
                            text: slotavail,
                          ),
                          SizedBox(
                            height: 20,
                          ),
                          TextFormField(
                            style: TextStyle(
                                fontSize: 15, fontWeight: FontWeight.bold),
                            decoration: InputDecoration(
                              hintText: 'Price Per Person: *',
                              labelText: 'Price Per Person: *',
                              suffixIcon: Icon(
                                Icons.currency_rupee,
                                color: Colors.black,
                                size: 15,
                              ),
                            ),
                            controller: priceperpers,
                            keyboardType: TextInputType.number,
                            validator: (value) {
                              if (value!.isEmpty) {
                                return &quot;This Field Can't be empty.&quot;;
                              }
                              return null;
                            },
                          ),
  
                          // customfields(
                          //   hintValue: 'Price Per Person: *',
                          //   labeltxt: 'Price Per Person: *',
                          //   keyboardtype: TextInputType.number,
                          //   text: priceperpers,
                          // ),
  
                          //Text(&quot;Slots Available&quot;),
                          SizedBox(
                            height: 20,
                          ),
                          ElevatedButton(
                            onPressed: () async {
                              final ab = context.read&lt;AddTripBloc&gt;();
                              ab.setpageonedata(
                                  tripname.text,
                                  _selectedDateRange!.start,
                                  _selectedDateRange!.end,
                                  noofdays.text,
                                  noofnights.text,
                                  slotavail.text,
                                  priceperpers.text);
  
                              await Navigator.of(context).push(MaterialPageRoute(
                                  builder: (context) =&gt; CameraWidget()));
                              // Navigator.push(
                              //     context,
                              //     MaterialPageRoute(
                              //         builder: (context) =&gt; CameraWidget()));
                            },
                            child: const Text(&quot;Upload Images of Trip *&quot;),
                          ),
                          SizedBox(
                            height: 35,
                          ),
                          ElevatedButton(
                            onPressed: () async {
                              if (_formKey.currentState!.validate()) {
                                final ab = context.read&lt;AddTripBloc&gt;();
                                ab.setpageonedata(
                                    tripname.text,
                                    _selectedDateRange!.start,
                                    _selectedDateRange!.end,
                                    noofdays.text,
                                    noofnights.text,
                                    slotavail.text,
                                    priceperpers.text);
                                //ab.savetripdata(user!);
                                Navigator.push(
                                    context,
                                    MaterialPageRoute(
                                        builder: (context) =&gt; PageTwo()));
                              }
                              setState(() {
                                _formKey.currentState?.save();
                              });
                            },
                            child: const Text(&quot;Save and Continue&quot;),
                          )
                        ],
                      )),
                ],
              ),
            ),
          ));
    }
  
    void _show() async {
      final DateTimeRange? result = await showDateRangePicker(
        context: context,
        firstDate: DateTime(2022, 1, 1),
        lastDate: DateTime(2030, 12, 31),
        currentDate: DateTime.now(),
        saveText: 'Done.',
      );
  
      if (result != null) {
        // Rebuild the UI
        String startdate = result.start.toString();
        String enddate = result.end.toString();
        // print(startdate);
        //print(enddate);
        //print(result.start.toString());
        //print(result.end.toString());
        setState(() {
          startdate = result.start.toString();
          enddate = result.end.toString();
          _selectedDateRange = result;
        });
      }
    }
  }
  </code></pre>