Material Datepicker with Cupertino UI

2019-08-13 04:45发布

问题:

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

回答1:

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.