Flutter 问题集合

4.MissingPluginException(No implementation found for method getAll on channel plugins.flutter.io/shared_preferences)


在使用shared_preferences之前(在模拟器上调试的场景),需要先

SharedPreferences.setMockInitialValues({});

比如:

save() async{
      //  模拟器测试的时候可以直接放在入口main()函数里面 
      SharedPreferences.setMockInitialValues({});  
      SharedPreferences prefs = await SharedPreferences.getInstance();
      prefs.setString(mUserName, _userNameController.value.text.toString());
    }

// 或者
void main() {
  SharedPreferences.setMockInitialValues({});
  runApp(MaterialApp(home: MyApp()));
}

如果是真机调试 则不需要加  可以正常使用

3.There are multiple heroes that share the same tag within a subtree异常

因为页面里用到了多个FloatingActionButton  需要给每个FloatingActionButton 设置一个 heroTag 属性;

2. Error: Not found: 'dart:ui'

运行flutter测试文件的时候 报如上错误,因为运行的测试文件方式不对

运行测试文件一定要选 flutter 图标的,下面是正常运行测试文件的界面,

注意一定是flutter 图标的, 如果是dart图标的 就点击Edit Config.... 进去把对应的记录删除,然后右键测试文件 ,按照上面的run的提示选择flutter 图标的进行测试即可。

1.  A package may not list itself as a dependency.

原因:当前的项目名称是不是和你引入的包名称一样,如果一样,更改你的项目名称

我遇到这个错误的原因就是 自己在学习json_serializable 包的时候 新建了一个项目,名称就是 json_serializable 所以在引入对应的包的时候就报错了

发布了87 篇原创文章 · 获赞 58 · 访问量 17万+

猜你喜欢

转载自blog.csdn.net/benpaodelulu_guajian/article/details/104317439