2021年12月31日更新
-
支持null-safety
image.png
2021年01月21日更新
- 支持controller.clear()
正文内容
支持iOS、Android、web
image.png
支持明文/密文,有2种风格可供选择,并且支持多种UI风格定制,包括密文字符、边框、圆角、颜色、TextStyle等等,以下是所有支持的内容。
final HBPasswordInputTextFieldType type; //格子样式
final Function onChange;//输入监听
final int length; //输入长度
final TextEditingController controller; //输入控制器
final FocusNode node; //焦点
final double boxWidth; //格子宽
final double boxHeight; //格子高
final double borderWidth; //边框宽
final double borderRaiuds; //圆角
final Color borderColor; //边框颜色
final Color fillColor; //填充颜色
final Color backgroundColor; //填充颜色
final double spacing; //格子间隔
final bool obscureText; //是否密文
final String obscureTextString; //密文字符
final TextStyle textStyle; //文本样式
安装
pub.dev 地址
在你的项目中pubspec.yaml
中添加
dependencies:
hb_password_input_textfield: ^1.0.1
有必要的话,执行一下这个命令,我是VSCode保存之后自动就执行了。
$ flutter pub get
然后在对应文件引用他
import 'package:hb_password_input_textfield/hb_password_input_textfield.dart';
Example
import 'package:hb_password_input_textfield/hb_password_input_textfield.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(
title: "MyHomePage",
),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({Key? key, required this.title}) : super(key: key);
final String title;
@override
State createState() => _MyHomePageState();
}
class _MyHomePageState extends State {
final TextEditingController _controller = TextEditingController();
final FocusNode _node = FocusNode();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
_node.unfocus();
},
child: Container(
margin: const EdgeInsets.only(top: 50),
child: HBPasswordInputTextField(
backgroundColor: Colors.white,
fillColor: Colors.red,
borderWidth: 0.5,
borderRaiuds: 5,
controller: _controller,
node: _node,
obscureText: true,
obscureTextString: "",
boxWidth: 50,
boxHeight: 50,
type: HBPasswordInputTextFieldType.BOXES,
length: 6,
textStyle: const TextStyle(fontSize: 20),
onChange: (text) {
if (text.length == 6) {
_node.unfocus();
}
},
borderColor: Colors.grey,
spacing: 10,
),
)),
);
}
}