抛出了另一个例外:处置后使用了一个应用程序。

发布于 2025-01-23 23:54:21 字数 1879 浏览 0 评论 0原文

我是新来的扑朔迷离。我在运行我的项目“糟糕的问题上错误。 ()在应用程序上,不再使用它。”

@override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
        designSize: Size(360, 640),
        builder: () => ChangeNotifierProvider<AppNotifier?>(
              create: (_) => widget.appLanguage,
              child: Consumer<AppNotifier>(
                builder: (context, value, _) => MaterialApp(
                  navigatorKey: GlobalVariable.navState,
                  debugShowCheckedModeBanner: false,
                  locale: value.appLocal,
                  title: 'MyApp',
                  routes: <String, WidgetBuilder>{
                    'HomeScreen': (BuildContext context) => HomeScreen(),
                  },
                  theme: value.getTheme(),
                  supportedLocales: [
                    Locale('en', 'US'),
                    ],
                  localizationsDelegates: [
                    AppLocalizations.delegate,
                    GlobalMaterialLocalizations.delegate,
                    GlobalWidgetsLocalizations.delegate,
                    GlobalCupertinoLocalizations.delegate,
                    CountryLocalizations.delegate,
                  ],
                  home: Builder(
                    builder: (context) {
                      return FutureBuilder(
                          future: DeeplinkConfig().initUniLinks(context),
                          builder: (_, snapshot) {
                            if (snapshot.connectionState ==
                                ConnectionState.waiting) {
                              return Container();
                            }
                            return snapshot.data as Widget;
                          });
                    },
                  ),
                ),
              ),
            ));
  }

I am new to Flutter. Im getting the following error messages after run my project "oops something wents wrong. please refresh the app or contact the administrator/developer" And i refresh the app after showing this error "A AppNotifier was used after being disposed. once you have called dispose() on a AppNotifier, it can no longer be used."

@override
  Widget build(BuildContext context) {
    return ScreenUtilInit(
        designSize: Size(360, 640),
        builder: () => ChangeNotifierProvider<AppNotifier?>(
              create: (_) => widget.appLanguage,
              child: Consumer<AppNotifier>(
                builder: (context, value, _) => MaterialApp(
                  navigatorKey: GlobalVariable.navState,
                  debugShowCheckedModeBanner: false,
                  locale: value.appLocal,
                  title: 'MyApp',
                  routes: <String, WidgetBuilder>{
                    'HomeScreen': (BuildContext context) => HomeScreen(),
                  },
                  theme: value.getTheme(),
                  supportedLocales: [
                    Locale('en', 'US'),
                    ],
                  localizationsDelegates: [
                    AppLocalizations.delegate,
                    GlobalMaterialLocalizations.delegate,
                    GlobalWidgetsLocalizations.delegate,
                    GlobalCupertinoLocalizations.delegate,
                    CountryLocalizations.delegate,
                  ],
                  home: Builder(
                    builder: (context) {
                      return FutureBuilder(
                          future: DeeplinkConfig().initUniLinks(context),
                          builder: (_, snapshot) {
                            if (snapshot.connectionState ==
                                ConnectionState.waiting) {
                              return Container();
                            }
                            return snapshot.data as Widget;
                          });
                    },
                  ),
                ),
              ),
            ));
  }

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

眉目亦如画i 2025-01-30 23:54:21

此错误告诉您处置后您正在使用AppNotifier。

这是一个临时解决方案:

  1. 删除:
appNotifier().dispose();
  1. 或类似的东西:
@override
void dispose(){
  AppNotifier().dispose(); //Remove This Code

  super.dispose();
}

This error tells that you are using AppNotifier after disposal.

this is a temporary solution:

  1. remove:
appNotifier().dispose();
  1. or something like this:
@override
void dispose(){
  AppNotifier().dispose(); //Remove This Code

  super.dispose();
}
盗琴音 2025-01-30 23:54:21

您不是在ChangeNotifierProvider的创建中创建新对象。您已经通过那里已经计算出的值。因此,当ChangeNotifierProvider的处置在内部称为时,它将被处置。

您需要做2件事。

  1. 使用changeNotifierProvider.value传递widget.applanguage
  2. 您将必须手动在widget.applanguage中手动处理通过的值。也许您可以在将其初始化的同一小部件​​处置。

谢谢。

You are not creating new object in ChangeNotifierProvider's create. You are passing already calculated value there. Hence it will be disposed when ChangeNotifierProvider's dispose is called internally.

You need to do 2 things.

  1. Use ChangeNotifierProvider.value to pass widget.appLanguage.
  2. You will have to manually dispose the value passed in widget.appLanguage. Maybe you can do it in the dispose of same widget where it's been initialised.

Thanks.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文