flutter flutter_screenutil Looking up a deactivated widget's ancestor is unsafe.
2021/9/13 6:05:10
本文主要是介绍flutter flutter_screenutil Looking up a deactivated widget's ancestor is unsafe.,对大家解决编程问题具有一定的参考价值,需要的程序猿们随着小编来一起学习吧!
先强调一下,很多问题可以使用reStart更新试一下下!!!!!
使用flutter_screenutil 报错 Looking up a deactivated widget's ancestor is unsafe.
The following assertion was thrown while dispatching notifications for SwiperController:
Looking up a deactivated widget's ancestor is unsafe.
At this point the state of the widget's element tree is no longer stable.
To safely refer to a widget's ancestor in its dispose() method, save a reference to the ancestor
by
calling dependOnInheritedWidgetOfExactType() in the widget's didChangeDependencies() method.
为SwipController发送通知时引发了以下断言:
查找停用小部件的祖先是不安全的。
此时,小部件元素树的状态不再稳定。
要在dispose()方法中安全地引用小部件的祖先,请保存对祖先的引用
通过
在小部件的didChangeDependencies()方法中调用dependOnInheritedWidgetOfExactType()。
初始代码,这个组件引用到了ListView里,开始报错
经过仔细阅读使用文档,核对版本号
新版本代码如下
首先要在lib/main.dart注册一下
import 'package:flutter/material.dart'; import 'pages/tabs/Tabs.dart'; // import 'routers/router.dart'; import 'pages/tabs/Tabs.dart'; import 'pages/test/Search.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; void main() { runApp(MyApp()); } // 输入stf 有状态组件 // stss 无状态组件 class MyApp extends StatefulWidget { const MyApp({Key? key}) : super(key: key); @override _MyAppState createState() => _MyAppState(); } class _MyAppState extends State<MyApp> { final Map<String, WidgetBuilder> routes = { '/': (context) => Tabs(), '/search': (context) => SearchPage(), }; Route<dynamic> _onGenerateRoute(RouteSettings settings) { // return MaterialPageRoute(builder: (context) { // 如果访问的路由页需要登录,但当前未登录,则直接返回登录页路由, // 引导用户登录;其它情况则正常打开路由。 // 统一处理 // }) final String? name = settings.name; final Function pageContentBuilder = routes[name] as Function; print('到1'); if (settings.arguments != null) { print('到2'); final Route route = MaterialPageRoute( builder: (context) => pageContentBuilder(context, arguments: settings.arguments)); return route; } else { print('到3'); final Route route = MaterialPageRoute(builder: (context) => pageContentBuilder(context)); return route; } } @override Widget build(BuildContext context) { // return MaterialApp( // // home: Tabs() // initialRoute: '/', // onGenerateRoute: _onGenerateRoute, // ); return ScreenUtilInit( designSize: Size(360, 690), builder: () => MaterialApp( // home: Tabs() initialRoute: '/', onGenerateRoute: _onGenerateRoute, ), ); } }
使用案例
Widget _titleWidget(value) { return Container( height: 32.h, margin: EdgeInsets.only(left: 20.w), padding: EdgeInsets.only(left: 20.w), decoration: BoxDecoration( border: Border(left: BorderSide(color: Colors.red, width: 10.w))), child: Text(value, style: TextStyle(color: Colors.pink)), ); }
最需要注意的一点点!!!!使用reStart更新试一下下!!!!!
大功告成
这篇关于flutter flutter_screenutil Looking up a deactivated widget's ancestor is unsafe.的文章就介绍到这儿,希望我们推荐的文章对大家有所帮助,也希望大家多多支持为之网!
- 2025-01-08CCPM如何缩短项目周期并降低风险?
- 2025-01-08Omnivore 替代品 Readeck 安装与使用教程
- 2025-01-07Cursor 收费太贵?3分钟教你接入超低价 DeepSeek-V3,代码质量逼近 Claude 3.5
- 2025-01-06PingCAP 连续两年入选 Gartner 云数据库管理系统魔力象限“荣誉提及”
- 2025-01-05Easysearch 可搜索快照功能,看这篇就够了
- 2025-01-04BOT+EPC模式在基础设施项目中的应用与优势
- 2025-01-03用LangChain构建会检索和搜索的智能聊天机器人指南
- 2025-01-03图像文字理解,OCR、大模型还是多模态模型?PalliGema2在QLoRA技术上的微调与应用
- 2025-01-03混合搜索:用LanceDB实现语义和关键词结合的搜索技术(应用于实际项目)
- 2025-01-03停止思考数据管道,开始构建数据平台:介绍Analytics Engineering Framework