8

After I added the dependency of ProfileLogic to LocationLogic I get the following error when the app starts:

I/flutter (14674): A LocationLogic was used after being disposed.

I/flutter (14674): Once you have called dispose() on a LocationLogic, it can no longer be used.

These are my providers:

      providers: [
        ChangeNotifierProvider(builder: (_) => ConnectivityLogic()),
        ChangeNotifierProxyProvider<ConnectivityLogic, ProfileLogic>(
          builder: (context, connectivity, previousMessages) =>
              ProfileLogic(connectivity.isOnline),
          initialBuilder: (BuildContext context) => ProfileLogic(false),
        ),
        ChangeNotifierProxyProvider<ProfileLogic, LocationLogic>(
          builder: (context, profileLogic, previousMessages) =>
              LocationLogic(profileLogic.profile),
          initialBuilder: (BuildContext context) => LocationLogic(null),
        ),
        ChangeNotifierProvider(builder: (_) => SignUpModel()),
        ChangeNotifierProxyProvider<ConnectivityLogic, WorkLogic>(
          builder: (context, connectivity, previousMessages) =>
              WorkLogic(connectivity.isOnline),
          initialBuilder: (BuildContext context) => WorkLogic(false),
        ),
        ChangeNotifierProvider(builder: (_) => OrderLogic()),
      ]

The strange thing is that everything works properly, even with that error.

Community
  • 1
  • 1
Felipe Augusto
  • 7,733
  • 10
  • 39
  • 73

1 Answers1

4

I think you disposed of a widget that holds those providers. Try to move desired providers higher in the tree. So if you have:

        MaterialApp(
          home: MultiProvider(
            providers: [...],
            child: child,
            )
        )

Do something like:

        MultiProvider(
          providers: [...],
          child: MaterialApp(
            home: child,
          )
        )

If this won't help you need to provide more context. eg. Whats widget tree like.

Luke Urban
  • 121
  • 6
  • Good guess, though I don't remember how I solved, now I use to create an architecture more based on streams than on state (`notifyListeners()`), the call of this method after some dispose would be my second guess. – Felipe Augusto Sep 23 '20 at 14:37