Home > OS >  why flutter datepicker isn't working (no popup comes while clicking the button)
why flutter datepicker isn't working (no popup comes while clicking the button)

Time:01-22

 import 'package:flutter/material.dart';
 import 'package:intl/intl.dart';
 class Picker extends StatefulWidget {
 const Picker({super.key});
 @override
 State<Picker> createState() => _PickerState();
}
  class _PickerState extends State<Picker> {
  void _showdatepicker() {
showDatePicker(
    context: context,
    initialDate: DateTime.now(),
    firstDate: DateTime(2002),
    lastDate: DateTime(2022));
   }
  @override
  Widget build(BuildContext context) {
    return Scaffold(
    //   backgroundColor: Colors.pinkAccent,
    body: Center(
   child: MaterialButton(
    onPressed: _showdatepicker,
    child: const Padding(
      padding: EdgeInsets.all(20),
      child: Text(
        'Choose Date',
        style: TextStyle(
          color: Colors.white,
          fontSize: 25,
        ),
      ),
    ),
    color: Colors.blue,
    ),
         ));
 }
 }

This code shows no errors but when running the application when the show date button is clicked.

It does nothing. I followed a lot of youtube tutorials, but I got the same error, what's wrong, or is it showing error due to new Flutter version?

CodePudding user response:

Try the following code:

showDatePicker(context: context, initialDate: DateTime.now(), firstDate: DateTime(2002), lastDate: DateTime.now());
  • Related