app-starlock/star_lock/lib/tools/tf_loginInput.dart
魏少阳 08de8f1fdf 1、修复登录注册问题,统一添加隐藏显示密码按钮
2、部分协议Nember 1个字节修改2字节
3、修复无网络开锁获取token异常情况
2024-05-03 18:31:15 +08:00

114 lines
3.4 KiB
Dart

import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:star_lock/app_settings/app_colors.dart';
/*
* 登录注册页面 input
* */
typedef BlockStrCallback = void Function(dynamic textStr);
typedef BlockClickCallback = void Function();
class LoginInput extends StatefulWidget {
TextEditingController? controller;
FocusNode? focusNode;
List<TextInputFormatter>? inputFormatters;
TextInputType? keyboardType;
Color? background;
String? hintText;
bool? isHaveLeftWidget;
Widget? leftWidget;
String? label;
bool? isPwd;
int? isSuffixIcon;
Widget? rightSlot;
BlockStrCallback? onchangeAction;
BlockClickCallback? onTapAction;
LoginInput(
{Key? key,
required this.controller,
this.focusNode,
this.rightSlot,
this.label,
this.isPwd,
this.isSuffixIcon,
this.inputFormatters,
this.keyboardType,
this.background,
this.hintText,
this.isHaveLeftWidget = true,
this.leftWidget,
this.onchangeAction,
this.onTapAction,
})
: super(key: key);
@override
State<LoginInput> createState() => _LoginInputState();
}
class _LoginInputState extends State<LoginInput> {
@override
Widget build(BuildContext context) {
return Container(
child: Column(
children: [
TextField(
//输入框一行
maxLines: 1,
controller: widget.controller,
focusNode: widget.focusNode,
onChanged: widget.onchangeAction,
onTap: widget.onTapAction,
autofocus: false,
inputFormatters: widget.inputFormatters,
decoration: InputDecoration(
//输入里面输入文字内边距设置
contentPadding: const EdgeInsets.only(
top: 8.0, left: -19.0, right: -15.0, bottom: 8.0),
labelText: widget.label,
labelStyle: TextStyle(fontSize: 22.sp,color: AppColors.darkGrayTextColor),
hintStyle: TextStyle(fontSize: 22.sp),
hintText: widget.hintText,
//不需要输入框下划线
border: InputBorder.none,
suffixIcon: (widget.isSuffixIcon == 1)
? IconButton(
icon: const Icon(Icons.clear),
onPressed: widget.controller!.clear,
)
: (widget.isSuffixIcon == 2 ? IconButton(
icon: Icon(
// 根据 _obscureText 的值切换图标
widget.isPwd! ? Icons.visibility_off : Icons.visibility,
),
onPressed: () {
// 当按钮被点击时,切换 _obscureText 的值
setState(() {
widget.isPwd = !widget.isPwd!;
});
},
):null),
//左边图标设置
icon: widget.isHaveLeftWidget == true
? widget.leftWidget
: SizedBox(
width: 20.w,
height: 40.w,
),
),
obscureText: widget.isPwd ?? false,
),
Container(
height: 0.5.h,
color: Colors.grey,
),
],
),
);
}
}