【问题标题】:Flutter riverpod: 'Bad State No ProvderScope found' after using navigatorFlutter Riverpod:使用导航器后的“Bad State No ProvderScope found”
【发布时间】:2022-10-13 23:22:43
【问题描述】:

我有以下扫描:我在整个应用程序中使用 Riverpod 状态管理,一切正常,但是当我尝试在使用 Navigator 到达的屏幕中使用时,出现以下错误:

错误状态:未找到 ProviderScope

事件:

ListTile(
  leading: Icon(Icons.currency_exchange),
  title: Text('Currency'),
  onTap: () => Navigator.of(context).push(
    MaterialPageRoute(builder: (context) => const CurrencyScreen()),
  ),
),

我的 Riverpod 范围:

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter',
      theme: ThemeData(
        brightness: Brightness.light,
        /* light theme settings */
      ),
      darkTheme: ThemeData(
          brightness: Brightness.dark,
          /* dark theme settings */
          ),
      themeMode: ThemeMode.dark,
      /* ThemeMode.system to follow system theme, 
         ThemeMode.light for light theme, 
         ThemeMode.dark for dark theme
      */
      home: const ProviderScope(child: SafeArea(child: AuthHandlerScreen())),
    );
  }

【问题讨论】:

    标签: flutter riverpod


    【解决方案1】:

    您必须使用 ProviderScope 包装整个应用程序

    void main() {
      runApp(
        // Enabled Riverpod for the entire application
        ProviderScope(
          child: MyApp(),
        ),
      );
    }
    

    【讨论】:

      猜你喜欢
      • 2021-02-02
      • 2020-10-17
      • 2020-04-14
      • 1970-01-01
      • 2020-10-12
      • 2020-12-10
      • 2021-05-03
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多