1

I have Flutter app that is using Cupertino UI components. I want to show the the Material design date_picker instead of IOS style date picker. Is there any way I can do this?

In short I want to keep the same Material style date picker for both Android and IOS app. But whenever I use the date picker under Cupertino it throws an exception "The specific widget that could not find a Material ancestor".

Thank you for your time

Sam
  • 2,972
  • 6
  • 34
  • 62

1 Answers1

3

According to this medium post you can create an abstract class extending a StatelessWidget and using the dart.io package to determine the platform type. In your case you can test whether the underlying platform is IOS and use the material date picker using this :

  if(Platform.isIOS) {
    return createAndroidWidget(context);
  }

you can find the full code in the aforementioned post and it'll be easy to follow it.

Mazin Ibrahim
  • 7,433
  • 2
  • 33
  • 40
  • I will try to implement it today. I have added more details to the question. Thank you for your time – Sam Mar 04 '19 at 13:35
  • Hi, I tried that but not working for me. Can you please put an example of how can we show Datepicker, dialog or even a showmodalbottomsheet under the Cuprtino? – Sam Mar 05 '19 at 13:54
  • Did you import the `material.dart` and called `showDatePicker()` function? – Mazin Ibrahim Mar 05 '19 at 14:01