登录后重新渲染个人页面bug fixed
This commit is contained in:
@ -2,17 +2,17 @@ import 'package:fengshui_compass/components/custom_textfield_widget.dart';
|
||||
import 'package:fengshui_compass/models/login_bean.dart';
|
||||
import 'package:fengshui_compass/net/dio_utils.dart';
|
||||
import 'package:fengshui_compass/pages/register_page.dart';
|
||||
import 'package:fengshui_compass/states/token.dart';
|
||||
import 'package:fengshui_compass/utils/token_helper.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:fluttertoast/fluttertoast.dart';
|
||||
import 'package:provider/provider.dart';
|
||||
|
||||
import '../components/controller.dart';
|
||||
import '../models/user_bean.dart';
|
||||
import '../utils/user_helper.dart';
|
||||
|
||||
class LoginPage extends StatefulWidget {
|
||||
|
||||
final String username;
|
||||
|
||||
const LoginPage({Key key, this.username}) : super(key: key);
|
||||
|
||||
@override
|
||||
@ -20,7 +20,6 @@ class LoginPage extends StatefulWidget {
|
||||
}
|
||||
|
||||
class _LoginPageState extends State<LoginPage> {
|
||||
|
||||
final FocusNode _userNameFocusNode = FocusNode();
|
||||
final FocusNode _passwordFocusNode = FocusNode();
|
||||
|
||||
@ -31,7 +30,7 @@ class _LoginPageState extends State<LoginPage> {
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
if(widget.username != null) {
|
||||
if (widget.username != null) {
|
||||
setState(() {
|
||||
_userNameEditController.text = widget.username;
|
||||
});
|
||||
@ -39,10 +38,8 @@ class _LoginPageState extends State<LoginPage> {
|
||||
super.initState();
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
|
||||
return Scaffold(
|
||||
// appBar: AppBar(
|
||||
// elevation: 0,
|
||||
@ -109,11 +106,13 @@ class _LoginPageState extends State<LoginPage> {
|
||||
submit: (value) {
|
||||
if (value.length != 11) {
|
||||
Fluttertoast.showToast(msg: "请输入11位手机号");
|
||||
FocusScope.of(context).requestFocus(_userNameFocusNode);
|
||||
FocusScope.of(context)
|
||||
.requestFocus(_userNameFocusNode);
|
||||
return;
|
||||
}
|
||||
_userNameFocusNode.unfocus();
|
||||
FocusScope.of(context).requestFocus(_passwordFocusNode);
|
||||
FocusScope.of(context)
|
||||
.requestFocus(_passwordFocusNode);
|
||||
},
|
||||
focusNode: _userNameFocusNode,
|
||||
prefixIconData: Icons.phone_android_outlined,
|
||||
@ -124,9 +123,10 @@ class _LoginPageState extends State<LoginPage> {
|
||||
TextFieldWidget(
|
||||
hintText: "密码",
|
||||
submit: (value) {
|
||||
if(value.length < 5) {
|
||||
if (value.length < 5) {
|
||||
Fluttertoast.showToast(msg: "请输入5位以上密码");
|
||||
FocusScope.of(context).requestFocus(_passwordFocusNode);
|
||||
FocusScope.of(context)
|
||||
.requestFocus(_passwordFocusNode);
|
||||
return;
|
||||
}
|
||||
_userNameFocusNode.unfocus();
|
||||
@ -163,12 +163,14 @@ class _LoginPageState extends State<LoginPage> {
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
const Text("没有账号, "),
|
||||
TextButton(onPressed: (){
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => RegisterPage()));
|
||||
}, child: const Text("点击注册"))
|
||||
TextButton(
|
||||
onPressed: () {
|
||||
Navigator.push(
|
||||
context,
|
||||
MaterialPageRoute(
|
||||
builder: (context) => RegisterPage()));
|
||||
},
|
||||
child: const Text("点击注册"))
|
||||
],
|
||||
)
|
||||
],
|
||||
@ -180,17 +182,17 @@ class _LoginPageState extends State<LoginPage> {
|
||||
);
|
||||
}
|
||||
|
||||
void submitFunction() async{
|
||||
void submitFunction() async {
|
||||
// 获取输入用户名密码
|
||||
String userName = _userNameEditController.text;
|
||||
String password = _passwordEditController.text;
|
||||
|
||||
if(userName.trim().length != 11) {
|
||||
if (userName.trim().length != 11) {
|
||||
Fluttertoast.showToast(msg: "请输入11位手机号");
|
||||
return;
|
||||
}
|
||||
|
||||
if(password.trim().length < 5) {
|
||||
if (password.trim().length < 5) {
|
||||
Fluttertoast.showToast(msg: "请输入5位以上密码");
|
||||
}
|
||||
|
||||
@ -207,23 +209,20 @@ class _LoginPageState extends State<LoginPage> {
|
||||
);
|
||||
|
||||
if (responseInfo.success) {
|
||||
Map<String, dynamic> res = {
|
||||
"token": responseInfo.token.toString()
|
||||
};
|
||||
LoginBean loginBean = LoginBean.fromMap(res);
|
||||
TokenHelper.getInstance.loginBean = loginBean;
|
||||
|
||||
Fluttertoast.showToast(msg: "登录成功");
|
||||
|
||||
//关闭当前页面
|
||||
Navigator.of(context).pop(true);
|
||||
//发送消息更新我的页面显示内容
|
||||
loginStreamController.add(0);
|
||||
Map<String, dynamic> res = {"token": responseInfo.token.toString()};
|
||||
LoginBean loginBean = LoginBean.fromMap(res);
|
||||
TokenHelper.getInstance.loginBean = loginBean;
|
||||
// 将token添加到状态管理器中
|
||||
Provider.of<TokenProvider>(context, listen: false).setToken(loginBean);
|
||||
Fluttertoast.showToast(msg: "登录成功");
|
||||
|
||||
//关闭当前页面
|
||||
Navigator.of(context).pop(true);
|
||||
//发送消息更新我的页面显示内容
|
||||
// loginStreamController.add(0);
|
||||
} else {
|
||||
//登录失败页面小提示
|
||||
Fluttertoast.showToast(msg: responseInfo.msg);
|
||||
}
|
||||
|
||||
//登录失败页面小提示
|
||||
Fluttertoast.showToast(msg: responseInfo.msg);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user