Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter Date and Time Picker not showing up

I don’t have that much experience with Flutter,the showDatePicker and the showTimePicker don’t show up when i hit the onTap button.I don’t know it’s about the Android Studio and the Emulator or about the codes. Please help me if possible,thank you.

Row(
            mainAxisAlignment: MainAxisAlignment.spaceBetween,
            children: [
              DateTimeWidget(titleText: 'Date',
                  valueText: dateProv.toString(),
                  iconSection: CupertinoIcons.calendar,
                onTap: () async {
                final DateTime? getValue = await showDatePicker(context: context, initialDate: DateTime.now(),
                    firstDate: DateTime(2021),lastDate: DateTime(2030));
                if(getValue != null) {
                  final format = DateFormat.yMd();
                  ref.read(dateProvider.notifier).update((state) => format.format(getValue));
                }
                },
          ),
              const Gap(22),
              DateTimeWidget(titleText: 'Time',
                valueText: ref.watch(timeProvider),
                iconSection: CupertinoIcons.clock,
                onTap: () async{
                final TimeOfDay getTime = showTimePicker(context: context, initialTime: TimeOfDay.now()) as TimeOfDay;

                if(getTime != null) {
                  ref.read(timeProvider.notifier).update((state) => getTime.format(context));
                }
                },
              ),
            ],
          ),

And this is the DateTimeWidget codes

class DateTimeWidget extends StatelessWidget {
  const DateTimeWidget({
    super.key,
    required this.titleText,
    required this.valueText,
    required this.iconSection,
    required this.onTap,
  });

  final String titleText;
  final String valueText;
  final IconData iconSection;
  final VoidCallback onTap;

  @override
  Widget build(BuildContext context) {
    return Expanded(
      child:Column(
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Text(titleText,style: AppStyle.headingOne,
          ),
          const Gap(6),
          Material(
            child: Ink(
              decoration: BoxDecoration(color: Colors.grey.shade200,
              borderRadius: BorderRadius.circular(10),
              ),
              child: InkWell(

                splashColor: Colors.amber,
                borderRadius: BorderRadius.circular(10),
                onTap: () =>onTap,
                child: Container(
                  padding: const EdgeInsets.symmetric(horizontal: 12,vertical:12 ),
                  decoration: BoxDecoration(color: Colors.transparent,
                    borderRadius:  BorderRadius.circular(8),
                  ),
                  child: Row(children: [
                    Icon(iconSection),
                    const Gap(6),
                    Text(valueText),
                  ]),
                ),
              ),
            ),
          ),
        ],),
    );
  }
}

I’ve tried to change Ink and Inkwell classes but it doesn’t work.

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You just forgot to add brackets "()" inside InkWell’s onTap callback. So your function is never called and performed. Just add brackets behind onTap and everything will be working fine.

onTap: () => onTap(),

instead of:

onTap: () => onTap,
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading