虽然PreInit了,还是有可能会导致set值的时候sharedPreferences为空啊?
来源:3-11 统一缓存管理框架hi_cache设计

慕函数3078794
2021-03-29
如果PreInit要花很长时间,虽然提前了init,set不是还是有可能会为空吗
写回答
1回答
-
是的,课程后面会用FutureBuilderl来等HiCache.preInit()初始化完成后在进行下一步操作:
class _BiliAppState extends State<BiliApp> { BiliRouteDelegate _routeDelegate = BiliRouteDelegate(); @override Widget build(BuildContext context) { return FutureBuilder<HiCache>( //进行初始化 future: HiCache.preInit(), builder: (BuildContext context, AsyncSnapshot<HiCache> snapshot) { //定义route var widget = snapshot.connectionState == ConnectionState.done ? Router(routerDelegate: _routeDelegate) : Scaffold( body: Center(child: CircularProgressIndicator()), ); return MaterialApp( home: widget, theme: ThemeData(primarySwatch: white), ); }); } }
032021-04-03
相似问题