hyzp_ybqx-Commit092:已初步实现显示保存的用户列表,选择列表项目后能够成功登录

master
WinUser01 4 years ago
parent dffaf9b467
commit 964c57c1e1

@ -3,6 +3,7 @@ import 'dart:developer' as developer;
import 'dart:io'; import 'dart:io';
import 'dart:math'; import 'dart:math';
import 'package:ai_save_account/ai_save_account.dart';
import 'package:camera/camera.dart'; import 'package:camera/camera.dart';
import 'package:convert/convert.dart'; import 'package:convert/convert.dart';
import 'package:crypto/crypto.dart' as crypto; import 'package:crypto/crypto.dart' as crypto;
@ -221,6 +222,7 @@ int faceLogin = -1; //1 成功0 失败,-1 处理中
int faceRegUserID = -1; //ID-1 int faceRegUserID = -1; //ID-1
List<CameraDescription> cameras; List<CameraDescription> cameras;
List<UserAccount> g_users = new List(); //
UserInfo g_userInfo = UserInfo(mapUserInfoRet: { UserInfo g_userInfo = UserInfo(mapUserInfoRet: {
"ret": 200, "ret": 200,
"data": { "data": {

@ -0,0 +1,503 @@
import 'dart:convert';
import 'package:ai_save_account/ai_save_account.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:hyzp_ybqx/pages/Works/TJXX/tj_data.dart';
import '../../components/EncryptUtil.dart';
import '../../components/commonFun.dart';
import '../../config/service_url.dart';
import '../../services/EventBus.dart';
import '../../services/Storage.dart';
import '../../widget/JdText.dart';
class LoginByName3 extends StatefulWidget {
LoginByName3({Key key, this.height}) : super(key: key);
double height;
_LoginPageState createState() => _LoginPageState();
}
class _LoginPageState extends State<LoginByName3> {
//try_setState(); //
try_setState() {
try {
setState(() {});
} catch (e) {
print('setState(() {})异常:${e}');
}
}
//
dispose() {
super.dispose();
eventBus.fire(new UserEvent('登录成功...'));
}
bool bRemmberPW = false;
GlobalKey _globalKey = new GlobalKey(); //
bool _can_expand_ListView = false; //
// List<UserAccount> g_users = new List(); //
@override
void initState() {
super.initState();
// g_userInfo.username = 'the_user_03';
// g_userInfo.password = '123456';
// g_userInfo.password = 'ybhb1234';
g_userInfo.username = '';
g_userInfo.password = '';
doInit();
//
eventBus.on<StatisDataUpdate>().listen((event) {
print(event.str);
updateMayLogin();
});
}
// APP05
updateMayLogin() {
//
// if (listZptjStatisAlone.length >= dwSum &&
// listTodayShtj.length >= dwSum &&
// listClltjStatisAlone.length >= dwSum) {
// bMayLogin = true;
// }
if (listAllStatisData.length >= dwSum) {
bMayLogin = true;
}
if (bMayLogin && bLoginVerify) {
//
// bMayLogin = false;
// bPreLoading = false;
// bLoginVerify = false; //
Navigator.pushNamed(context, '/tabs', arguments: g_iIndex);
// Future.delayed(const Duration(milliseconds: 1000), () {
// });
}
}
doInit() async {
bRemmberPW = await Storage.getBool('bRemmberPW');
bRemmberPW = (null == bRemmberPW) ? false : bRemmberPW;
print('bRemmberPW = $bRemmberPW');
if (bRemmberPW) {
//
g_userInfo.username = await Storage.getString('username');
g_userInfo.username = EncryptUtil.aesDecode(g_userInfo.username);
g_userInfo.password = await Storage.getString('password');
g_userInfo.password = EncryptUtil.aesDecode(g_userInfo.password);
//user account list
_gainUsers();
}
try_setState();
}
doLogin() async {
//
// Navigator.pushNamed(context, '/tabs', arguments: g_iIndex);
// return;
// if (!bMayLogin) {
// bPreLoading = true;
// try_setState();
// }
// APP01 ...
bPreLoading = true;
try_setState();
// APP02
if (bRemmberPW) {
Storage.setBool('bRemmberPW', bRemmberPW);
//
Storage.setString('username', EncryptUtil.aesEncode(g_userInfo.username));
Storage.setString('password', EncryptUtil.aesEncode(g_userInfo.password));
} else {
Storage.remove('username');
Storage.remove('password');
}
var api = ServicePath.loginUrl;
print(api);
try {
print('开始处理登录请求...');
print('username = ${g_userInfo.username}');
print('password = ${g_userInfo.password}');
Response response;
Dio dio = Dio();
String random = RandomBit(6); //flutter dartN
print('random = ${random}');
print('sign = ${GenerateMd5(APPkey + random)}');
response = await dio.post(api, data: {
"username": g_userInfo.username,
"password": g_userInfo.password,
"sign": GenerateMd5(APPkey + random),
"random": random,
});
print('response = ${response.toString()}');
//I/flutter ( 5242): {"ret":200,"data":{"is_login":true,"user_id":3,"token":"32EE57A0109A3D1D6590CFD3DEBA71820F77AB654093C1DE750347C88D1A41CF"},"msg":""}
if (response.statusCode == 200) {
// Storage.setString('userInfo', json.encode(response.data["userinfo"]));
// //Navigator.pop(context);
// Navigator.pushNamed(context, '/tabs', arguments: g_iIndex);
//print('response.data["data"]["is_login"] = ${response.data["data"]["is_login"]}');
//I/flutter ( 5242): response.data["data"]["is_login"] = true
//{
// "ret": 200,
// "data": {
// "is_login": true,
// "user_id": 1,
// "token": "B93EC91FA2FE293B7077162D4527FC4BB228CD6C0A4F24A882B9A8BBE6C3FB47"
// },
// "msg": ""
// }
print('response = ${response}');
//response = {"ret":406,"data":{},"msg":"非法请求:签名错误"}
if (true == response.data["data"]["is_login"]) {
print('登录成功');
print('response.data = ${response.data}');
// if (bRemmberPW) {
// // SaveAccountPasswordManager.getUsers();
// SaveAccountPasswordManager.saveUser(
// UserAccount(g_userInfo.username, g_userInfo.password));
// SaveAccountPasswordManager.getUsers().then((listUsers) {
// print("listUsers =\n${listUsers}");
// });
// } else {
// SaveAccountPasswordManager.getUsers().then((listUsers) {
// // print("listUsers =\n${listUsers}");
// for (var user in listUsers) {
// print("User = ${user}");
// SaveAccountPasswordManager.delUser(user);
// }
// });
// }
// APP03
Storage.setString('userInfo', json.encode(response.data["data"]));
g_userInfo
.setUserInfo(theMapUserInfoRet: await getMapFromJson(response.data))
.then((value) {
// APP04使bLoginVerify = true
bLoginVerify = true; //
startGetStatisDataNew(); // 2
// Navigator.pushNamed(context, '/tabs', arguments: g_iIndex);
});
//
// getUserGroupAll().then((value) {
// bLoginVerify = true; //
// if (bMayLogin) {
// // bMayLogin = false;
// // bPreLoading = false;
// // bLoginVerify = false; //
// Navigator.pushNamed(context, '/tabs', arguments: g_iIndex);
// }
// });
// bLoginVerify = true; //
// Navigator.pushNamed(context, '/tabs', arguments: g_iIndex);
} else {
print('登录失败:${response.data["data"]}');
bLoginVerify = false; //
bPreLoading = false;
try_setState(); //
Fluttertoast.showToast(
msg: '登录失败:用户名或密码不正确。',
toastLength: Toast.LENGTH_LONG,
gravity: ToastGravity.BOTTOM,
);
print('登录失败:${response.data["data"]}');
}
print('登录过程正常完成');
} else {
throw Exception('后端接口出现异常,请检测代码和服务器情况.........');
}
} catch (e) {
print('登录过程异常...');
print('ERROR:======>${e}');
Fluttertoast.showToast(
msg: 'ERROR:======>${e}',
toastLength: Toast.LENGTH_SHORT,
gravity: ToastGravity.CENTER,
);
}
return;
}
@override
Widget build(BuildContext context) {
return Scaffold(
//resizeToAvoidBottomPadding: false, //-
backgroundColor: Colors.transparent,
body: GestureDetector(
onTap: () {
FocusScopeNode currentFocus = FocusScope.of(context);
// if (!currentFocus.hasPrimaryFocus && currentFocus.focusedChild != null) {
if (true) {
FocusManager.instance.primaryFocus.unfocus(); // Flutter
//
if (g_users.isNotEmpty) {
//1
// _can_expand_ListView = !_can_expand_ListView;
_can_expand_ListView = false;
}
setState(() {});
}
},
child: Container(
height: widget.height,
child: Column(
children: [
Container(color: Colors.transparent, height: ScreenUtil().setHeight(45)),
Container(
color: Colors.white,
width: double.infinity,
height: ScreenUtil().setHeight(156),
padding: EdgeInsets.only(top: 10, bottom: 0, left: 20, right: 20),
child: JdText(
height: 126,
//JdText使ScreenUtil().setHeight(126) ScreenUtil().setHeight(126)
title: '用户名:',
text: "请输入用户名",
onChanged: (String value) {
// print(value);
g_userInfo.username = value;
},
endBtn: 'ClearBtn',
controller: TextEditingController(text: g_userInfo.username),
onEndBtn: () {
if (g_users.isNotEmpty) {
//1
setState(() {
_can_expand_ListView = !_can_expand_ListView;
});
}
},
onEndBtn2: () {
// FocusManager.instance.primaryFocus.unfocus(); // Flutter
//
print('xx2');
if (g_users.isNotEmpty) {
//1
_can_expand_ListView = false;
}
setState(() {});
},
),
),
Stack(
children: [
Column(
children: [
Container(
color: Colors.white,
width: double.infinity,
height: ScreenUtil().setHeight(224),
padding: EdgeInsets.only(top: 0, bottom: 20, left: 20, right: 20),
child: Column(
children: <Widget>[
Container(
color: Colors.transparent, height: ScreenUtil().setHeight(30)),
JdText(
height: 126,
//JdText使ScreenUtil().setHeight(126) ScreenUtil().setHeight(126)
title: '密 码:',
text: "请输入密码",
password: true,
onChanged: (String value) {
g_userInfo.password = value;
},
endBtn: 'ShowHiddenBtn',
controller: TextEditingController(text: g_userInfo.password),
),
],
),
),
Container(color: Colors.transparent, height: ScreenUtil().setHeight(30)),
Container(
//color: Colors.transparent,
padding: EdgeInsets.all(ScreenUtil().setWidth(10)),
child: Row(
children: [
SizedBox(width: ScreenUtil().setWidth(45)),
InkWell(
onTap: () {
//Navigator.pushNamed(context, '/registerFirst');
this.setState(() {
bRemmberPW = !bRemmberPW;
});
Storage.setBool('bRemmberPW', bRemmberPW);
},
child: Container(
alignment: Alignment(1, -1),
//width: 150,
child: Row(
mainAxisAlignment: MainAxisAlignment.start,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
Container(
alignment: Alignment(0, 0),
height: 22,
width: 22,
padding: EdgeInsets.only(top: ScreenUtil().setHeight(3)),
// child: Checkbox(
// value: bRemmberPW,
// activeColor: Colors.blue,
// onChanged: (bool val) {
// this.setState(() {
// bRemmberPW = !bRemmberPW;
// });
// Storage.setBool('bRemmberPW', bRemmberPW);
// },
// ),
child: bRemmberPW
? Icon(Icons.check_box, color: Colors.blue)
: Icon(Icons.check_box_outline_blank,
color: Colors.white),
),
SizedBox(width: ScreenUtil().setWidth(15)),
Text('记住密码',
style: TextStyle(fontSize: 17, color: Colors.white)),
],
),
),
),
],
),
),
SizedBox(height: ScreenUtil().setHeight(48)),
InkWell(
onTap: doLogin,
child: Container(
alignment: Alignment(0, 0),
margin: EdgeInsets.all(5),
padding: EdgeInsets.all(5),
width: ScreenUtil().setWidth(999),
height: ScreenUtil().setHeight(126),
decoration: BoxDecoration(
color: Color.fromRGBO(23, 176, 91, 1),
borderRadius: BorderRadius.circular(10)),
child: Text(
bPreLoading ? "加载中 . . ." : "登 录",
style: TextStyle(color: Colors.white, fontSize: 18),
),
),
),
],
),
g_users.isNotEmpty ? _buildListView() : Container(),
],
),
// JdButton(
// height: 126,
// //JdText使ScreenUtil().setHeight(126) ScreenUtil().setHeight(126)
// width: 999,
// text: "登 录",
// color: Color.fromRGBO(23, 176, 91, 1),
// onTop: doLogin,
// ),
],
),
),
),
);
}
///
///ListView
Widget _buildListView() {
if (_can_expand_ListView) {
return Column(
children: [
ListView.builder(
shrinkWrap: true,
physics: BouncingScrollPhysics(),
itemBuilder: (context, index) {
UserAccount user = g_users[index];
return GestureDetector(
child: Column(
children: [
Container(
width: ScreenUtil().screenWidth * 0.9,
// color: Colors.grey[200],
color: Colors.grey[200],
padding: EdgeInsets.only(left: 8, top: 8, right: 8, bottom: 8),
child: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: <Widget>[
Text("${user.username}"),
GestureDetector(
child: Padding(
padding: EdgeInsets.all(0),
child: Icon(
Icons.remove_circle_outline,
color: Colors.grey,
),
),
onTap: () {
setState(() {
g_users.remove(user);
SaveAccountPasswordManager.delUser(user);
//Expandfalse
//1
_can_expand_ListView = g_users.isNotEmpty;
});
},
),
],
),
Divider(height: 1.0, color: Colors.black),
],
),
),
],
),
onTap: () {
setState(() {
g_userInfo.username = user.username;
g_userInfo.password = user.password;
});
},
);
},
itemCount: g_users.length,
)
],
);
}
return Container();
}
///
void _gainUsers() async {
g_users.clear();
g_users.addAll(await SaveAccountPasswordManager.getUsers());
//
if (g_users.isNotEmpty) {
setState(() {
g_userInfo.username = g_users[0].username;
g_userInfo.password = g_users[0].password;
});
}
}
}

@ -7,7 +7,7 @@ import 'package:hyzp_ybqx/widget/my_Tabs.dart' as my_Tabs;
import '../../components/commonFun.dart'; import '../../components/commonFun.dart';
import '../../services/Storage.dart'; import '../../services/Storage.dart';
import 'FaceLogin2.dart'; import 'FaceLogin2.dart';
import 'LoginByName2.dart'; import 'LoginByName3.dart';
// class LoginTabsWidget extends StatelessWidget { // class LoginTabsWidget extends StatelessWidget {
// // This widget is the root of your application. // // This widget is the root of your application.
@ -157,7 +157,7 @@ class _MyHomePageState extends State<LoginTabsWidget> with SingleTickerProviderS
//flutter tabbar-OK //flutter tabbar-OK
physics: new NeverScrollableScrollPhysics(), physics: new NeverScrollableScrollPhysics(),
children: <Widget>[ children: <Widget>[
LoginByName2(height: _height), LoginByName3(height: _height),
FaceLogin2(), FaceLogin2(),
], ],
), ),

@ -1,17 +1,19 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart'; import 'package:flutter/rendering.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:hyzp_ybqx/components/commonFun.dart';
class JdText extends StatefulWidget { class JdText extends StatefulWidget {
final String text; final String text;
final String title; final String title;
bool password; bool password;
final Object onChanged; final Function(String) onChanged;
final int maxLines; final int maxLines;
final double height; final double height;
TextEditingController controller; TextEditingController controller;
final String endBtn; final String endBtn;
final Function() onEndBtn;
final Function() onEndBtn2;
JdText( JdText(
{Key key, {Key key,
@ -22,7 +24,9 @@ class JdText extends StatefulWidget {
this.maxLines = 1, this.maxLines = 1,
this.height = 68, this.height = 68,
this.controller, this.controller,
this.endBtn}) this.endBtn,
this.onEndBtn,
this.onEndBtn2})
: super(key: key); : super(key: key);
_JdTextState createState() => _JdTextState(); _JdTextState createState() => _JdTextState();
@ -31,8 +35,40 @@ class JdText extends StatefulWidget {
class _JdTextState extends State<JdText> { class _JdTextState extends State<JdText> {
Icon ShowHiddenIcon = Icon(Icons.more_horiz); Icon ShowHiddenIcon = Icon(Icons.more_horiz);
// Flutter TextField
FocusNode _focusNode = FocusNode();
bool isFocus = false;
void initState() { void initState() {
super.initState(); super.initState();
// _focusNode.addListener(() {
// setState(() {
// isFocus = _focusNode.hasFocus;
// widget.onEndBtn2();
// });
// });
//
_focusNode.addListener(() {
if (!_focusNode.hasFocus) {
print(widget.endBtn + ':失去焦点');
} else {
print(widget.endBtn + ':得到焦点');
if (null != widget.onEndBtn2) {
widget.onEndBtn2();
setState(() {});
}
}
});
}
//
@override
void dispose() {
// TODO: implement dispose
_focusNode.unfocus();
super.dispose();
} }
@override @override
@ -63,6 +99,7 @@ class _JdTextState extends State<JdText> {
//FlutterRow使textfield //FlutterRow使textfield
Expanded( Expanded(
child: TextField( child: TextField(
focusNode: _focusNode,
textAlignVertical: TextAlignVertical(y: 1.0), textAlignVertical: TextAlignVertical(y: 1.0),
controller: widget.controller, controller: widget.controller,
maxLines: 1, maxLines: 1,
@ -91,14 +128,29 @@ class _JdTextState extends State<JdText> {
// alignment: Alignment(0, -1), // alignment: Alignment(0, -1),
// padding: EdgeInsets.only(bottom: 23), // padding: EdgeInsets.only(bottom: 23),
child: IconButton( child: IconButton(
icon: Icon(Icons.highlight_off), padding: EdgeInsets.only(bottom: 0.0),
onPressed: () { iconSize: 40,
setState(() { icon: Icon(
widget.controller.clear(); Icons.arrow_drop_down,
}); color: g_users.isNotEmpty ? Colors.blueAccent : Colors.grey,
}), ),
onPressed: widget.onEndBtn),
); );
break; break;
// case 'ClearBtn':
// widget.controller = new TextEditingController();
// btn = Container(
// // alignment: Alignment(0, -1),
// // padding: EdgeInsets.only(bottom: 23),
// child: IconButton(
// icon: Icon(Icons.highlight_off),
// onPressed: () {
// setState(() {
// widget.controller.clear();
// });
// }),
// );
// break;
case 'ShowHiddenBtn': case 'ShowHiddenBtn':
btn = Container( btn = Container(
// alignment: Alignment(0, -1), // alignment: Alignment(0, -1),

@ -1,6 +1,13 @@
# Generated by pub # Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile # See https://dart.dev/tools/pub/glossary#lockfile
packages: packages:
ai_save_account:
dependency: "direct main"
description:
name: ai_save_account
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.1"
app_installer: app_installer:
dependency: "direct main" dependency: "direct main"
description: description:

@ -177,7 +177,7 @@ dependencies:
qr_flutter: ^3.2.0 qr_flutter: ^3.2.0
# Flutter 保存用户登录历史记录 ai_save_account # Flutter 保存用户登录历史记录 ai_save_account
# ai_save_account: ^1.0.1 ai_save_account: ^1.0.1
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:

Loading…
Cancel
Save