title: How to display the date in custom format in Flutter
body: <p>I want to pick the date and print it in the custom format( DD-MM-YYYY). Am able to do that using the following code. However when I pick the date from date picker still the current date is displaying not the picked date. There is a problem in my setState it seems. But am unable to trace it.</p>
  <pre><code>import 'package:checkboxtest/report.dart';
  import 'package:flutter/material.dart';
  
  
  class Date extends StatelessWidget {
    @override
    Widget build(BuildContext context) {
      return MaterialApp(
        title: 'Flutter Demo',
        theme: ThemeData(
            primarySwatch: Colors.blue,
            textTheme: TextTheme(body1: TextStyle(fontSize: 21))),
        home: Home(),
      );
    }
  }
  
  class Home extends StatefulWidget {
    @override
    _HomeState createState() =&gt; _HomeState();
  }
  
  class _HomeState extends State&lt;Home&gt; {
    DateTime _date = DateTime.now();
    static var date1 = DateTime.now();
    var customDate = &quot;${date1.day}-${date1.month}-${date1.year}&quot;;
      
    @override
    Widget build(BuildContext context) {
      return Scaffold(
        body: Center(
          child: Column(
            mainAxisAlignment: MainAxisAlignment.center,
            children: &lt;Widget&gt;[
              Text(_date == null
                  ? 'Today'
                  : &quot;${date1.day.toString().padLeft(2, '0')}-${date1.month.toString().padLeft(2, '0')}-${date1.year.toString()}&quot;),
              RaisedButton.icon(
                color: Colors.teal,
                icon: Icon(Icons.calendar_today),
                label: Text('Pick Date'),
  
                onPressed: () {
                  
                  showDatePicker(
                          context: context,
                          initialDate: _date == null ? DateTime.now() : _date,
                          firstDate: DateTime(2001),
                          lastDate: DateTime(2021))
                      .then((date) {
                    setState(() {
                      
                     customDate =
                     &quot;${date.day.toString().padLeft(2, '0')}-${date.month.toString().padLeft(2, '0')}-${date.year.toString()}&quot;;
                    });
                  });
                },
              ),
             ],
          ),
        ),
      );
    }
  }
  </code></pre>