Skip to content

Commit 4f64e85

Browse files
committed
fix warn
1 parent 3c74b6d commit 4f64e85

File tree

1 file changed

+9
-6
lines changed

1 file changed

+9
-6
lines changed

lib/test/demo_bloc_page.dart

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -79,7 +79,9 @@ class _LoginPageState extends State<LoginPage> with LoginBLoC {
7979
),
8080
backgroundColor:
8181
Theme.of(context).primaryColor),
82-
onPressed: loginIn,
82+
onPressed: (){
83+
loginIn(context);
84+
},
8385
child: const Text("登陆",
8486
style: TextStyle(fontSize: 14),
8587
textAlign: TextAlign.center,
@@ -141,7 +143,7 @@ mixin LoginBLoC on State<LoginPage> {
141143
pwController.value = TextEditingValue(text: _password ?? "");
142144
}
143145

144-
loginIn() async {
146+
loginIn(BuildContext ctx) async {
145147
if (_userName == null || _userName!.isEmpty) {
146148
return;
147149
}
@@ -151,9 +153,10 @@ mixin LoginBLoC on State<LoginPage> {
151153
SharedPreferences prefs = await SharedPreferences.getInstance();
152154
await prefs.setString("username", _userName!);
153155
await prefs.setString("password", _password!);
154-
155-
///通过 redux 去执行登陆流程
156-
StoreProvider.of<GSYState>(context)
157-
.dispatch(LoginAction(context, _userName, _password));
156+
if(ctx.mounted) {
157+
///通过 redux 去执行登陆流程
158+
StoreProvider.of<GSYState>(ctx)
159+
.dispatch(LoginAction(ctx, _userName, _password));
160+
}
158161
}
159162
}

0 commit comments

Comments
 (0)