Search
 
SCRIPT & CODE EXAMPLE
 

DART

show date picker flutter

import 'dart:async';

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  DateTime selectedDate = DateTime.now();

  Future<void> _selectDate(BuildContext context) async {
    final DateTime picked = await showDatePicker(
        context: context,
        initialDate: selectedDate,
        firstDate: DateTime(2015, 8),
        lastDate: DateTime(2101));
    if (picked != null && picked != selectedDate)
      setState(() {
        selectedDate = picked;
      });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: Center(
        child: Column(
          mainAxisSize: MainAxisSize.min,
          children: <Widget>[
            Text("${selectedDate.toLocal()}".split(' ')[0]),
            SizedBox(height: 20.0,),
            RaisedButton(
              onPressed: () => _selectDate(context),
              child: Text('Select date'),
            ),
          ],
        ),
      ),
    );
  }
}
Comment

flutter datetime picker

 $ flutter pub add syncfusion_flutter_datepicker
Comment

PREVIOUS NEXT
Code Example
Dart :: dart list sort by value 
Dart :: filterchip flutter 
Dart :: flutter how to create copy button 
Dart :: dart filter by attribute 
Dart :: snackbar flutter 
Dart :: flutter performance tips 
Dart :: flutter transform translate 
Dart :: dart promise all 
Dart :: app bar textStyle flutter 
Dart :: flutter pub upgrade and save pubspec 
Dart :: flutter persistent header 
Dart :: textbutton flutter 
Dart :: message yes or not in dart 
Dart :: how to refresh a listview in flutter 
Dart :: what is the use of substring in flutter 
Dart :: dart inheritance 
Dart :: flutter getx dialog 
Dart :: flutter counter app with block library 
Dart :: flutter run ios white screen 
Dart :: flutter portrate only 
Dart :: flutter crop captured image 
Dart :: inkwell splash color not working flutter 
Dart :: flutter getx state management 
Dart :: image not shoing when i use network image,flutter 
Dart :: Add glow or shadow to flutter widget 
Dart :: geturedetector flutter 
Dart :: Get Prime Number in dart 
Dart :: Cannot remove from an unmodifiable list dart 
Dart :: flutter display alert dialog after server error 
Swift :: swift change button text 
ADD CONTENT
Topic
Content
Source link
Name
9+1 =