支持iOS、Android、webnode
支持明文/密文,有2種風格可供選擇,而且支持多種UI風格定製,包括密文字符、邊框、圓角、顏色、TextStyle等等,如下是全部支持的內容。web
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 地址bash
在你的項目中pubspec.yaml
中添加app
dependencies:
hb_password_input_textfield: ^0.1.1
複製代碼
有必要的話,執行一下這個命令,我是VSCode保存以後自動就執行了。 $ flutter pub get
less
而後在對應文件引用他ide
import 'package:hb_password_input_textfield/hb_password_input_textfield.dart';
複製代碼
import 'package:flutter/material.dart';
import 'package:hb_password_input_textfield/hb_password_input_textfield.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'HBPasswordInputTextField Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: HBPasswordInputTextFieldPage(),
);
}
}
class HBPasswordInputTextFieldPage extends StatefulWidget {
@override
_HBPasswordInputTextFieldPageState createState() =>
_HBPasswordInputTextFieldPageState();
}
class _HBPasswordInputTextFieldPageState
extends State<HBPasswordInputTextFieldPage> {
// int length = 0;
TextEditingController _controller = TextEditingController();
FocusNode _node = FocusNode();
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("HBPasswordInputTextField"),
),
body: GestureDetector(
behavior: HitTestBehavior.opaque,
onTap: () {
_node.unfocus();
},
child: Container(
margin: EdgeInsets.only(top: 50),
child: HBPasswordInputTextField(
// backgroundColor: Colors.red,
// fillColor: Colors.red,
borderWidth: 0.5,
borderRaiuds: 5,
controller: _controller,
node: _node,
backgroundColor: Colors.red,
obscureText: true,
// obscureTextString: "🤪",
// boxWidth: 50,
// boxHeight: 50,
type: HBPasswordInputTextFieldType.BOXES,
length: 6,
textStyle: TextStyle(fontSize: 20),
onChange: (text) {
print(text);
},
),
)),
);
}
}
複製代碼