Я пытаюсь использовать общие предпочтения, чтобы сохранить логин пользователя, и я помещаю его в экран spla sh, и при запуске проекта появляется эта ошибка
[ОШИБКА: flutter / lib / ui / ui_dart_state. cc (157)] Необработанное исключение: setState () вызывается после dispose (): _SplashScreenState # aa9c8 (lifecycle state: defunct) Эта ошибка возникает, если вы вызываете setState () для объекта State для виджета это больше не появляется в дереве виджетов (например, чей родительский виджет больше не включает виджет в свою сборку). Эта ошибка может возникать, когда код вызывает setState () из таймера или анимационного обратного вызова. Предпочтительным решением является отмена таймера или прекращение прослушивания анимации в обратном вызове dispose (). Другое решение заключается в проверке свойства «mount» этого объекта перед вызовом setState (), чтобы убедиться, что объект все еще находится в дереве. Эта ошибка может указывать на утечку памяти, если вызывается setState (), потому что другой объект сохраняет ссылку на этот объект State после того, как он был удален из дерева. Чтобы избежать утечек памяти, рассмотрите возможность разрыва ссылки на этот объект во время dispose ().
и данные l oop не перестанут называть себя снова и снова
this мой метод использования общих предпочтений
bool isLoading = true;
init() async {
SharedPreferences prefs = await SharedPreferences.getInstance();
bool isLog = prefs.getBool("islog");
if (isLog == true) {
String email = prefs.getString("email");
String pass = prefs.getString("pass");
setState(() {
signIn(email, pass);
});
} else {
setState(() {
isLoading = false;
});
}
}
signIn(String email, String pass) async {
var res = await userProvider.login(email, pass);
var user = userProvider.user.tourist;
if (res is FailedRequest) {
Dialogs.showErrorDialog(context, message: res.message, code: res.code);
} else if (user == true) {
print("Signing in success");
await appProvider.countryList();
setState(() {
Navigator.pushReplacement(
context, MaterialPageRoute(builder: (context) => BottomScreen()));
});
}
userProvider.isLoading = false;
setState(() {
isLoading = false;
});
}
это мой экран spla sh, который содержит предыдущий код общего предпочтения
@override
Widget build(BuildContext context) {
userProvider = Provider.of<UserProvider>(context, listen: false);
appProvider = Provider.of<AppProvider>(context, listen: false);
init();
return isLoading == true
? Container(
color: Colors.white,
child: Center(
child: CircularProgressIndicator()),
)
: Container(
child: Scaffold(
body: Stack(
children: <Widget>[
Container(
foregroundDecoration: !AppTheme.isLightTheme
? BoxDecoration(
color: AppTheme.getTheme()
.backgroundColor
.withOpacity(0.4))
: null,
width: MediaQuery.of(context).size.width,
height: MediaQuery.of(context).size.height,
child: Image.asset('assets/images/introduction.jpg',
fit: BoxFit.cover),
),
Column(
children: <Widget>[
Expanded(
flex: 1,
child: SizedBox(),
),
Center(
child: Container(
width: 60,
height: 60,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(
Radius.circular(8.0),
),
boxShadow: <BoxShadow>[
BoxShadow(
color: AppTheme.getTheme().dividerColor,
offset: Offset(1.1, 1.1),
blurRadius: 10.0),
],
),
child: ClipRRect(
borderRadius: BorderRadius.all(
Radius.circular(8.0),
),
child: Image.asset('assets/images/appIcon.png'),
),
),
),
SizedBox(
height: 16,
),
Text(
"Voyager",
textAlign: TextAlign.left,
style: TextStyle(
fontWeight: FontWeight.w600,
fontSize: 24,
),
),
SizedBox(
height: 8,
),
Text(
"Best Trips deals for your holiday",
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 14,
),
),
Expanded(
flex: 4,
child: SizedBox(),
),
Padding(
padding: const EdgeInsets.only(
left: 48, right: 48, bottom: 8, top: 8),
child: Container(
height: 48,
decoration: BoxDecoration(
color: AppTheme.getTheme().primaryColor,
borderRadius:
BorderRadius.all(Radius.circular(24.0)),
boxShadow: <BoxShadow>[
BoxShadow(
color: AppTheme.getTheme().dividerColor,
blurRadius: 8,
offset: Offset(4, 4),
),
],
),
child: Material(
color: Colors.transparent,
child: InkWell(
borderRadius:
BorderRadius.all(Radius.circular(24.0)),
highlightColor: Colors.transparent,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
IntroductionScreen()),
);
},
child: Center(
child: Text(
"Get started",
style: TextStyle(
fontWeight: FontWeight.w500,
fontSize: 16,
color: Colors.white),
),
),
),
),
),
),
Padding(
padding: EdgeInsets.only(
bottom:
24.0 + MediaQuery.of(context).padding.bottom,
top: 16),
child: Container(
child: Material(
color: Colors.transparent,
child: InkWell(
borderRadius:
BorderRadius.all(Radius.circular(24.0)),
highlightColor: Colors.transparent,
onTap: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (context) =>
LoginScreen(context)),
);
},
child: Text(
"Already have account? LogIn",
textAlign: TextAlign.left,
style: TextStyle(
fontSize: 14,
color: Colors.white,
),
),
),
),
),
),
],
),
],
),
),
);
}
, так что любой может помочь мне, пожалуйста, в моем вопросе