使用Cupertino UI的物料Datepicker [英] Material Datepicker with Cupertino UI

查看:175
本文介绍了使用Cupertino UI的物料Datepicker的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有使用Cupertino UI组件的Flutter应用程序.我想显示Material设计的date_picker而不是IOS样式的日期选择器.有什么办法可以做到吗?

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?

简而言之,我想为Android和IOS应用程序保留相同的Material Style日期选择器.但是,每当我在Cupertino下使用日期选择器时,它都会引发异常"找不到材料祖先的特定小部件".

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".

谢谢您的时间

推荐答案

根据此

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.

这篇关于使用Cupertino UI的物料Datepicker的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆