【发布时间】:2020-12-26 19:28:00
【问题描述】:
尝试从提供者那里获取值,它工作正常,但我收到以下错误。我在这里做错了什么?
@override
Widget build(BuildContext context) {
String route = Provider.of<User>(context) == null ? Router.LOGIN : Router.HOME;
Future.delayed(const Duration(seconds: 2), () => Navigator.pushReplacementNamed(context, route));
return Scaffold(........
错误
E/flutter (23058): [ERROR:flutter/shell/common/shell.cc(209)] Dart Error: Unhandled exception:
E/flutter (23058): Looking up a deactivated widget's ancestor is unsafe.
E/flutter (23058): At this point the state of the widget's element tree is no longer stable.
E/flutter (23058): 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.
【问题讨论】: