im using provider using mvvm im fetching api but the response it not changing after new users login its showing old users data i have deleted all data from local storage and local storage data is showing properly but the get api data after login changing its show old users data
Future<bool> logout(BuildContext context) async {
_logout = DataState.loading("");
notifyListeners();
try {
final result = await authRepository.logout();
_logout = DataState.completed(result);
isLoggedIn = false;
_user = null;
_logout = DataState.completed(true);
} catch (error, stackTrace) {
isLoggedIn = false;
_logout = DataState.error(error.toString());
Utils.instance.logError(error, stackTrace);
}
notifyListeners();
return _logout.data ?? false;
}`
and im showing main dart changenotifier code also here
Widget build(BuildContext context) {
MaterialTheme theme = getTheme(context);
final localViewModel = Provider.of<LocaleViewModel>(
context,
);
debugPaintSizeEnabled = false;
return MultiProvider(
providers: [
ChangeNotifierProvider<AuthViewModel>(
create: (_) => _authViewModel,
),
ChangeNotifierProvider<IntroViewModel>(
create: (_) => _introViewModel,
),
ChangeNotifierProvider<RegisterViewModel>(
create: (_) => _registerViewModel,
),
ChangeNotifierProvider<SettingsViewModel>(
create: (_) => _settingViewModel,
),
ChangeNotifierProvider<SearchViewModel>(
create: (_) => _searchViewModel,
),
ChangeNotifierProvider(
create: (_) => PlansViewModel(_plansListRepository),
),
ChangeNotifierProvider(create: (_) => ChatViewModel()),
ChangeNotifierProvider(create: (_) => ProfileViewModel()),
ChangeNotifierProvider(create: (_) => NotificationsViewModel()),
ChangeNotifierProvider(create: (_) => DashBoardViewModel()),
ChangeNotifierProvider(create: (_) => CommonShimmerViewModel()),
ChangeNotifierProvider(
create: (_) => BlockViewModel(),
),
ChangeNotifierProvider(
create: (_) => BranchViewModel(),
),
ChangeNotifierProvider(
create: (_) => ContactUsViewModel(),
)
],
child: Consumer<SettingsViewModel>(
builder: (settingContext, setting, child) {
return ScreenUtilInit(
designSize: const Size(390, 720),
child: MaterialApp.router(
themeMode: setting.themeMode,
debugShowCheckedModeBanner: false,
theme: theme.light().copyWith(splashColor: Colors.blueGrey),
// darkTheme: theme
// .darkMediumContrast()
// .copyWith(splashColor: Colors.blueGrey),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
locale: localViewModel.locale,
builder: (context, child) {
if (child == null) {
throw ('No child in .router constructor builder');
}
return AuthScope(
notifier: _authViewModel,
child: child,
);
},
routerConfig: router));
}),
);
}
New contributor
Rishi Tailor is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.