优化输入框输入需要点击两次问题

This commit is contained in:
魏少阳 2024-03-20 15:12:35 +08:00
parent c7d0495ebe
commit 5bb1e9c438
14 changed files with 323 additions and 206 deletions

View File

@ -88,7 +88,7 @@ class _StarLockForgetPasswordPageState
height: 0.5.h,
color: Colors.grey,
),
LoginInput().tfInput(
LoginInput(
controller: state.phoneController,
onchangeAction: (v) {
logic.checkNext(state.phoneController);
@ -107,7 +107,7 @@ class _StarLockForgetPasswordPageState
LengthLimitingTextInputFormatter(30),
]),
SizedBox(height: 10.h),
LoginInput().tfInput(
LoginInput(
controller: state.pwdController,
onchangeAction: (v) {
logic.checkNext(state.pwdController);
@ -134,7 +134,7 @@ class _StarLockForgetPasswordPageState
color: AppColors.placeholderTextColor, fontSize: 20.sp),
),
SizedBox(height: 10.w),
LoginInput().tfInput(
LoginInput(
controller: state.sureController,
onchangeAction: (v) {
logic.checkNext(state.sureController);
@ -158,7 +158,7 @@ class _StarLockForgetPasswordPageState
Row(
children: [
Expanded(
child: LoginInput().tfInput(
child: LoginInput(
controller: state.codeController,
onchangeAction: (v) {
logic.checkNext(state.codeController);

View File

@ -1,3 +1,4 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
@ -7,6 +8,7 @@ import 'package:star_lock/flavors.dart';
import '../../appRouters.dart';
import '../../app_settings/app_colors.dart';
import '../../common/XSConstantMacro/XSConstantMacro.dart';
import '../../tools/commonItem.dart';
import '../../tools/tf_loginInput.dart';
import '../../tools/submitBtn.dart';
import '../../tools/titleAppBar.dart';
@ -54,15 +56,19 @@ class _StarLockLoginPageState extends State<StarLockLoginPage> {
child: Image.asset('images/icon_main_1024.png',
width: 110.w, height: 110.w))),
SizedBox(height: 50.w),
LoginInput().tfInput(
LoginInput(
controller: state.emailOrPhoneController,
onchangeAction: (v) {
logic.checkNext(state.emailOrPhoneController);
},
leftWidget: Image.asset(
'images/icon_login_account.png',
width: 36.w,
height: 36.w,
leftWidget: Padding(
padding: EdgeInsets.only(
top: 30.w, bottom: 20.w, right: 20.w, left: 5.w),
child: Image.asset(
'images/icon_login_account.png',
width: 36.w,
height: 36.w,
),
),
hintText:
TranslationLoader.lanKeys!.pleaseEnterNumberOrEmail!.tr,
@ -72,16 +78,20 @@ class _StarLockLoginPageState extends State<StarLockLoginPage> {
LengthLimitingTextInputFormatter(30),
]),
SizedBox(height: 10.h),
LoginInput().tfInput(
LoginInput(
controller: state.pwdController,
onchangeAction: (v) {
logic.checkNext(state.pwdController);
},
isPwd: true,
leftWidget: Image.asset(
'images/icon_login_password.png',
width: 36.w,
height: 36.w,
leftWidget: Padding(
padding: EdgeInsets.only(
top: 30.w, bottom: 20.w, right: 20.w, left: 5.w),
child: Image.asset(
'images/icon_login_password.png',
width: 36.w,
height: 36.w,
),
),
hintText:
"${TranslationLoader.lanKeys!.pleaseEnter!.tr}${TranslationLoader.lanKeys!.password!.tr}",
@ -215,4 +225,71 @@ class _StarLockLoginPageState extends State<StarLockLoginPage> {
],
));
}
Widget loginInput({
TextEditingController? controller,
List<TextInputFormatter>? inputFormatters,
String? hintText,
bool? isHaveLeftWidget,
Widget? leftWidget,
String? label,
bool? isPwd,
BlockStrCallback? onchangeAction}) {
return Container(
// color: Colors.red,
width: 1.sp,
// height: 200.h,
child: Column(
children: [
Row(
children: [
Container(
color: Colors.red,
child: Image.asset(
'images/icon_login_password.png',
width: 36.w,
height: 36.w,
),
),
SizedBox(width: 40.w,),
Expanded(
child: TextField(
//
maxLines: 1,
controller: controller,
onChanged: onchangeAction,
// autofocus: false,
inputFormatters:inputFormatters,
decoration: InputDecoration(
//
contentPadding: const EdgeInsets.only(
top: 8.0, left: -19.0, right: -15.0, bottom: 8.0),
labelText: label,
labelStyle: TextStyle(fontSize: 22.sp),
hintStyle: TextStyle(fontSize: 22.sp),
hintText: hintText,
//线
border: InputBorder.none,
//
// icon: isHaveLeftWidget == true
// ? leftWidget
// : SizedBox(
// width: 20.w,
// height: 40.w,
// ),
),
obscureText: isPwd ?? false,
),
),
],
),
Container(
height: 0.5.h,
color: Colors.grey,
),
],
),
);
}
}

View File

@ -13,8 +13,6 @@ class StarLockLoginState {
TextEditingController emailOrPhoneController = TextEditingController();
TextEditingController pwdController = TextEditingController();
late FocusNode myFocusNode1;
late FocusNode myFocusNode2;
StarLockLoginState() {
// emailOrPhone.value = StoreService.to.getLastUserAccount() as String;

View File

@ -196,7 +196,7 @@ class _StarLockRegisterPageState extends State<StarLockRegisterPage> {
Widget middleTFWidget() {
return Column(
children: [
LoginInput().tfInput(
LoginInput(
controller: state.phoneOrEmailController,
onchangeAction: (v) {
logic.checkNext(state.phoneOrEmailController);
@ -218,7 +218,7 @@ class _StarLockRegisterPageState extends State<StarLockRegisterPage> {
LengthLimitingTextInputFormatter(30),
]),
SizedBox(height: 10.w),
LoginInput().tfInput(
LoginInput(
controller: state.pwdController,
onchangeAction: (v) {
logic.checkNext(state.pwdController);
@ -244,7 +244,7 @@ class _StarLockRegisterPageState extends State<StarLockRegisterPage> {
TextStyle(color: AppColors.placeholderTextColor, fontSize: 20.sp),
),
SizedBox(height: 10.w),
LoginInput().tfInput(
LoginInput(
controller: state.sureController,
onchangeAction: (v) {
logic.checkNext(state.sureController);
@ -267,7 +267,7 @@ class _StarLockRegisterPageState extends State<StarLockRegisterPage> {
Row(
children: [
Expanded(
child: LoginInput().tfInput(
child: LoginInput(
controller: state.codeController,
onchangeAction: (v) {
logic.checkNext(state.codeController);

View File

@ -42,7 +42,7 @@ class _EditLockNamePageState extends State<EditLockNamePage> {
),
body: Container(
margin: EdgeInsets.only(left: 20.w, right: 20.w),
child: LoginInput().tfInput(
child: LoginInput(
controller: state.changeLockNameController,
leftWidget: const SizedBox(),
hintText: "请输入名称",

View File

@ -242,7 +242,7 @@ class NearbyLockLogic extends BaseGetXController {
//
var featureNetxLength = index + featureValueLength + 1;
if(reply.data.length < featureNetxLength){
showToast("特征值数据获取失败,请重新点击获取");
showToast("数据异常,请重试");
return;
}
var featureValue = reply.data.sublist(index + 1, index + featureValueLength + 1);
@ -257,7 +257,7 @@ class NearbyLockLogic extends BaseGetXController {
// 使()
var featureEnNextLength = index + featureEnValLength + 1;
if(reply.data.length < featureEnNextLength){
showToast("使能特征值数据获取失败,请重新点击获取");
showToast("数据异常,请重试");
return;
}
var featureEnVal = reply.data.sublist(index + 1, index + featureEnValLength + 1);

View File

@ -89,7 +89,7 @@ class _MinePersonInfoEditIphonePageState
color: Colors.grey,
),
SizedBox(height: 10.w),
LoginInput().tfInput(
LoginInput(
controller: _phoneController,
isPwd: true,
leftWidget: const SizedBox(),
@ -102,7 +102,7 @@ class _MinePersonInfoEditIphonePageState
Row(
children: [
Expanded(
child: LoginInput().tfInput(
child: LoginInput(
controller: _codeController,
isPwd: true,
leftWidget: const SizedBox(),

View File

@ -50,7 +50,7 @@ class _MinePersonInfoEditNamePageState
padding: EdgeInsets.all(15.w),
child: Column(
children: [
LoginInput().tfInput(
LoginInput(
controller: state.nickNameController,
onchangeAction: (textStr) {
logic.checkNext(state.nickNameController);

View File

@ -45,7 +45,7 @@ class _MineBindPhoneOrEmailPageState extends State<MineBindPhoneOrEmailPage> {
: TranslationLoader.lanKeys!.changeEmailTip!.tr,
style: TextStyle(fontSize: 20.sp),
)),
LoginInput().tfInput(
LoginInput(
controller: state.accountController,
isPwd: false,
onchangeAction: (textStr) {
@ -62,7 +62,7 @@ class _MineBindPhoneOrEmailPageState extends State<MineBindPhoneOrEmailPage> {
Row(
children: [
Expanded(
child: LoginInput().tfInput(
child: LoginInput(
controller: state.codeController,
isPwd: false,
leftWidget: const SizedBox(),

View File

@ -36,7 +36,7 @@ class _MinePersonInfoResetPasswordPageState
margin: EdgeInsets.only(left: 30.w, right: 30.w),
child: Column(
children: [
LoginInput().tfInput(
LoginInput(
controller: state.oldPwdController,
onchangeAction: (textStr) {
logic.changeInput(state.oldPwdController);
@ -50,7 +50,7 @@ class _MinePersonInfoResetPasswordPageState
inputFormatters: [
LengthLimitingTextInputFormatter(20),
]),
LoginInput().tfInput(
LoginInput(
controller: state.newPwdController,
onchangeAction: (textStr) {
logic.changeInput(state.newPwdController);
@ -64,7 +64,7 @@ class _MinePersonInfoResetPasswordPageState
inputFormatters: [
LengthLimitingTextInputFormatter(20),
]),
LoginInput().tfInput(
LoginInput(
controller: state.surePwdController,
onchangeAction: (textStr) {
logic.changeInput(state.surePwdController);

View File

@ -11,12 +11,22 @@ class LockUserManageListLogic extends BaseGetXController {
final LockUserManageListState state = LockUserManageListState();
//
void lockUserListRequest() async {
Future<LockUserListEntity> lockUserListRequest() async {
LockUserListEntity entity =
await ApiRepository.to.lockUserList('1', '20', state.searchController.text);
if (entity.errorCode!.codeIsSuccessful) {
state.dataList.value = entity.data!;
await ApiRepository.to.lockUserList(pageNo.toString(), '20', state.searchController.text);
if(entity.errorCode!.codeIsSuccessful){
if (pageNo == 1) {
state.dataList.value = entity.data!;
pageNo++;
} else {
if (entity.data!.isNotEmpty) {
state.dataList.value.addAll(entity.data!);
print("state.itemDataList.value.length:${state.dataList.value.length}");
pageNo++;
}
}
}
return entity;
}
//
@ -24,7 +34,10 @@ class LockUserManageListLogic extends BaseGetXController {
var entity = await ApiRepository.to.deletLockUser(uid);
if (entity.errorCode!.codeIsSuccessful) {
EasyLoading.showToast('删除成功',duration: 2000.milliseconds);
lockUserListRequest();
showToast('删除成功', something: (){
pageNo = 1;
lockUserListRequest();
});
}
}
@ -33,7 +46,7 @@ class LockUserManageListLogic extends BaseGetXController {
// TODO: implement onReady
super.onReady();
lockUserListRequest();
// lockUserListRequest();
}
@override

View File

@ -1,5 +1,6 @@
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:flutter_slidable/flutter_slidable.dart';
import 'package:get/get.dart';
import 'package:star_lock/main/lockDetail/electronicKey/massSendElectronicKey/massSendLockGroupList/lockUserList/lockUserListEntity.dart';
import 'package:star_lock/tools/noData.dart';
@ -8,6 +9,8 @@ import '../../../../../appRouters.dart';
import '../../../../../app_settings/app_colors.dart';
import '../../../../../tools/titleAppBar.dart';
import '../../../../../translations/trans_lib.dart';
import '../../../../tools/EasyRefreshTool.dart';
import '../../../../tools/keySearchWidget.dart';
import '../../../../tools/left_slide_actions.dart';
import '../../../../tools/showIosTipView.dart';
import 'lockUserManageList_logic.dart';
@ -22,7 +25,20 @@ class LockUserManageListPage extends StatefulWidget {
class _LockUserManageListPageState extends State<LockUserManageListPage> {
final logic = Get.put(LockUserManageListLogic());
final state = Get.find<LockUserManageListLogic>().state;
Future<void> getHttpData() async {
logic.lockUserListRequest().then((LockUserListEntity value){
if(mounted) setState(() {});
});
}
@override
void initState() {
super.initState();
getHttpData();
}
@override
Widget build(BuildContext context) {
return Scaffold(
@ -43,75 +59,53 @@ class _LockUserManageListPageState extends State<LockUserManageListPage> {
),
],
),
body: Column(
children: [
_searchWidget(),
SizedBox(
height: 20.h,
),
Obx(() => Expanded(child: _buildMainUI())),
SizedBox(
width: ScreenUtil().screenWidth - 40.w,
height: 90.h,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white,
),
onPressed: () {
Navigator.pushNamed(
context, Routers.massSendElectronicKeyManagePage)
.then((value) {
logic.lockUserListRequest();
});
},
child: Text(
TranslationLoader.lanKeys!.sendGroupKey!.tr,
style: TextStyle(
color: AppColors.mainColor,
fontSize: 24.sp,
fontWeight: FontWeight.w600),
)),
),
SizedBox(
height: 64.h,
)
],
),
);
}
Widget _searchWidget() {
return Container(
height: 60.h,
margin: EdgeInsets.only(top: 20.w, left: 20.w, right: 20.w),
decoration: BoxDecoration(
color: Colors.white, borderRadius: BorderRadius.circular(5)),
child: TextField(
//
maxLines: 1,
controller: state.searchController,
autofocus: false,
onSubmitted: (value) {
logic.lockUserListRequest();
body: EasyRefreshTool(
onRefresh: (){
logic.pageNo = 1;
getHttpData();
},
decoration: InputDecoration(
//
contentPadding: const EdgeInsets.only(
top: 12.0, left: -19.0, right: -15.0, bottom: 8.0),
hintText: TranslationLoader.lanKeys!.pleaseEnter!.tr,
hintStyle: TextStyle(fontSize: 22.sp, height: 3.0),
//线
border: InputBorder.none,
//
icon: Padding(
padding: EdgeInsets.only(
top: 20.h, bottom: 20.h, right: 20.w, left: 10.w),
child: Image.asset(
'images/main/icon_main_search.png',
width: 40.w,
height: 40.w,
onLoad: (){
getHttpData();
},
child: Column(
children: [
KeySearchWidget(
editingController: state.searchController,
onSubmittedAction: () {
logic.pageNo = 1;
getHttpData();
},
),
),
SizedBox(
height: 20.h,
),
Obx(() => Expanded(child: _buildMainUI())),
SizedBox(
width: ScreenUtil().screenWidth - 40.w,
height: 90.h,
child: ElevatedButton(
style: ElevatedButton.styleFrom(
backgroundColor: Colors.white,
),
onPressed: () {
Navigator.pushNamed(
context, Routers.massSendElectronicKeyManagePage)
.then((value) {
logic.lockUserListRequest();
});
},
child: Text(
TranslationLoader.lanKeys!.sendGroupKey!.tr,
style: TextStyle(
color: AppColors.mainColor,
fontSize: 24.sp,
fontWeight: FontWeight.w600),
)),
),
SizedBox(
height: 64.h,
)
],
),
),
);
@ -119,34 +113,56 @@ class _LockUserManageListPageState extends State<LockUserManageListPage> {
Widget _buildMainUI() {
return state.dataList.isEmpty
? NoData()
: ListView.separated(
itemCount: state.dataList.length,
itemBuilder: (c, index) {
LockUserData indexEntity = state.dataList[index];
if (index < state.dataList.length) {
return LeftSlideActions(
key: Key(indexEntity.userid!),
actionsWidth: 60,
actions: [
_buildDeleteBtn(indexEntity),
],
decoration: const BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(1)),
),
child: _electronicKeyItem(indexEntity),
? NoData(noDataHeight: 1.sh - ScreenUtil().statusBarHeight - ScreenUtil().bottomBarHeight - 190.h - 64.h)
: SlidableAutoCloseBehavior(
child: ListView.separated(
itemCount: state.dataList.length,
itemBuilder: (c, index) {
LockUserData indexEntity = state.dataList[index];
if (index < state.dataList.length) {
return Slidable(
key:ValueKey(indexEntity.uid),
endActionPane: ActionPane(
extentRatio: 0.2,
motion: const ScrollMotion(),
children: [
SlidableAction(
onPressed: (BuildContext context){
showIosTipViewDialog(context, indexEntity);
},
backgroundColor: Colors.red,
foregroundColor: Colors.white,
label: '删除',
padding: EdgeInsets.only(left: 5.w, right: 5.w),
),
],
),
child: _electronicKeyItem(indexEntity),
);
// return LeftSlideActions(
// key: Key(indexEntity.userid!),
// actionsWidth: 60,
// actions: [
// _buildDeleteBtn(indexEntity),
// ],
// decoration: const BoxDecoration(
// borderRadius: BorderRadius.all(Radius.circular(1)),
// ),
// child: _electronicKeyItem(indexEntity),
// );
}
return const SizedBox.shrink();
// return _electronicKeyItem(indexEntity);
},
separatorBuilder: (BuildContext context, int index) {
return const Divider(
height: 1,
color: AppColors.greyLineColor,
);
}
return const SizedBox.shrink();
// return _electronicKeyItem(indexEntity);
},
separatorBuilder: (BuildContext context, int index) {
return const Divider(
height: 1,
color: AppColors.greyLineColor,
);
},
);
},
),
);
}
Widget _electronicKeyItem(LockUserData itemData) {
@ -217,28 +233,28 @@ class _LockUserManageListPageState extends State<LockUserManageListPage> {
);
}
Widget _buildDeleteBtn(LockUserData passwordKeyListItem) {
return GestureDetector(
onTap: () {
// :
showIosTipViewDialog(context, passwordKeyListItem);
},
child: Container(
width: 60,
color: const Color(0xFFF20101),
alignment: Alignment.center,
child: const Text(
'删除',
style: TextStyle(
fontSize: 16,
fontWeight: FontWeight.w500,
color: Colors.white,
height: 1,
),
),
),
);
}
// Widget _buildDeleteBtn(LockUserData passwordKeyListItem) {
// return GestureDetector(
// onTap: () {
// // :
// showIosTipViewDialog(context, passwordKeyListItem);
// },
// child: Container(
// width: 60,
// color: const Color(0xFFF20101),
// alignment: Alignment.center,
// child: const Text(
// '删除',
// style: TextStyle(
// fontSize: 16,
// fontWeight: FontWeight.w500,
// color: Colors.white,
// height: 1,
// ),
// ),
// ),
// );
// }
void showIosTipViewDialog(BuildContext context, LockUserData lockUserData) {
showDialog(

View File

@ -763,9 +763,9 @@ class ApiRepository {
}
//
Future<LockUserListEntity> deletLockUser(int uid) async {
Future<LoginEntity> deletLockUser(int uid) async {
final res = await apiProvider.deletLockUser(uid);
return LockUserListEntity.fromJson(res.body);
return LoginEntity.fromJson(res.body);
}
//

View File

@ -8,61 +8,74 @@ import 'package:flutter_screenutil/flutter_screenutil.dart';
* */
typedef BlockStrCallback = void Function(dynamic textStr);
typedef BlockClickCallback = void Function();
class LoginInput extends StatelessWidget {
TextEditingController? controller;
FocusNode? focusNode;
List<TextInputFormatter>? inputFormatters;
TextInputType? keyboardType;
Color? background;
String? hintText;
bool? isHaveLeftWidget;
Widget? leftWidget;
String? label;
bool? isPwd;
Widget? rightSlot;
BlockStrCallback? onchangeAction;
BlockClickCallback? onTapAction;
LoginInput(
{Key? key,
required this.controller,
this.focusNode,
this.rightSlot,
this.label,
this.isPwd,
this.inputFormatters,
this.keyboardType,
this.background,
this.hintText,
this.isHaveLeftWidget = true,
this.leftWidget,
this.onchangeAction,
this.onTapAction})
: super(key: key);
class LoginInput{
Widget tfInput({
TextEditingController? controller,
List<TextInputFormatter>? inputFormatters,
TextInputType? keyboardType,
Color? background,
String? hintText,
bool? isHaveLeftWidget,
Widget? leftWidget,
String? label,
bool? isPwd,
Widget? rightSlot,
BlockStrCallback? onchangeAction}) {
return SizedBox(
@override
Widget build(BuildContext context) {
return Container(
// color: Colors.red,
width: 1.sp,
// width: 1.sp,
// height: 200.h,
child: Column(
children: [
Row(
children: [
leftWidget ?? SizedBox(width: 36.w, height: 36.w),
SizedBox(width: 40.w,),
Expanded(
child: TextField(
//
maxLines: 1,
controller: controller,
onChanged: onchangeAction,
// autofocus: false,
inputFormatters:inputFormatters,
decoration: InputDecoration(
//
contentPadding: const EdgeInsets.only(
top: 8.0, left: -19.0, right: -15.0, bottom: 8.0),
labelText: label,
labelStyle: TextStyle(fontSize: 22.sp),
hintStyle: TextStyle(fontSize: 22.sp),
hintText: hintText,
//线
border: InputBorder.none,
//
// icon: isHaveLeftWidget == true
// ? leftWidget
// : SizedBox(
// width: 20.w,
// height: 40.w,
// ),
),
obscureText: isPwd ?? false,
),
),
],
TextField(
//
maxLines: 1,
controller: controller,
focusNode: focusNode,
onChanged: onchangeAction,
onTap: onTapAction,
autofocus: false,
inputFormatters:inputFormatters,
decoration: InputDecoration(
//
contentPadding: const EdgeInsets.only(
top: 8.0, left: -19.0, right: -15.0, bottom: 8.0),
labelText: label,
labelStyle: TextStyle(fontSize: 22.sp),
hintStyle: TextStyle(fontSize: 22.sp),
hintText: hintText,
//线
border: InputBorder.none,
//
icon: isHaveLeftWidget == true
? leftWidget
: SizedBox(
width: 20.w,
height: 40.w,
),
),
obscureText: isPwd ?? false,
),
Container(
height: 0.5.h,