微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Flutter 错误:提供程序无法访问导航中的路线

如何解决Flutter 错误:提供程序无法访问导航中的路线

当我运行这个时,我不断收到同样的错误,请帮忙。

 Future<void> main() async {
          WidgetsFlutterBinding.ensureInitialized();
          await Firebase.initializeApp();
          runApp(App());
        }
    
class App extends StatelessWidget {
  final Color primaryColor = Color(0xff18203d);

  @override
  Widget build(BuildContext context) {
    // ignore: todo
    // Todo: implement build
    return MultiProvider(
        providers: [
          Provider<AuthenticationService>(
            create: (_) => AuthenticationService(FirebaseAuth.instance),),StreamProvider(
            create: (_context) =>
                _context.read<AuthenticationService>().authStateChanges,initialData: null,],child: MaterialApp(
          title: 'Mboka Horticulture',theme: ThemeData(
            primaryColor: primaryColor,visualDensity: VisualDensity.adaptivePlatformDensity,home: AuthenticationWrapper(),));
  }
}

class AuthenticationWrapper extends StatelessWidget {
  const AuthenticationWrapper({
    Key? key,}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    // ignore: todo
    // Todo: implement build
    final firebaseuser = context.watch<User>();
    if (firebaseuser != null) {
      return Dashboard();
    }
    return Login();
  }
}

这是我不断收到的错误,我不明白。

**提供者是“有范围的”。因此,如果您将 provider 插入到一个 路线,然后 其他路由将无法访问该提供程序。

- You used a `BuildContext` that is an ancestor of the provider you are trying to read.

  Make sure that AuthenticationWrapper is under your MultiProvider/Provider<User>.
  This usually happens when you are creating a provider and trying to read it immediately.

  For example,instead of:**

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。