You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何解决Flutter升级SDK后出现的Material.maybeOf成员找不到错误?

错误截图1
错误截图2

升级Flutter SDK后出现错误:Error: Member not found: 'Material.maybeOf',涉及代码为bool isMaterial = Material.maybeOf(context) != null;,使用的flutter_date_pickers包版本为^0.4.2(已确认是该包最新版本)。

解决方法

方法一:修改依赖包源码(临时修复)

  • 找到flutter_date_pickers包的本地安装路径:可通过项目根目录的pubspec.lock文件定位,或在Flutter的.pub-cache目录中搜索该包。
  • 找到源码中调用Material.maybeOf(context)的代码,替换为:
    bool isMaterial = context.findAncestorWidgetOfExactType<Material>() != null;
    
  • 保存修改后重新运行项目。

方法二:使用修复后的Fork版本

  • 前往GitHub Fork flutter_date_pickers仓库到自己账号下,修改上述代码。
  • 在项目pubspec.yaml中替换依赖为自己的Fork仓库,示例:
    flutter_date_pickers:
      git:
        url: https://github.com/你的用户名/flutter_date_pickers.git
        ref: main # 对应你修改后的分支名
    

方法三:更换活跃维护的替代包

flutter_date_pickers版本^0.4.2发布已久,长期未维护无法适配新版Flutter,推荐更换以下包:

  • 官方showDatePicker:无需额外依赖,直接调用即可实现基础日期选择。
  • date_picker_timeline:支持时间线样式的日期选择组件。
  • flutter_datetime_picker:支持日期、时间组合选择的多功能组件。

内容的提问来源于stack exchange,提问作者John Reaper

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.20 09:27:41