File tree Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Expand file tree Collapse file tree 1 file changed +9
-6
lines changed Original file line number Diff line number Diff 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}
You can’t perform that action at this time.
0 commit comments