2021年12月31日更新
-
支持null-safety
2021年01月21日更新
- 支持controller.clear()
正文內(nèi)容
支持iOS柒巫、Android、web
支持明文/密文猜敢,有2種風(fēng)格可供選擇,并且支持多種UI風(fēng)格定制没佑,包括密文字符、邊框靴迫、圓角点弯、顏色、TextStyle等等榛了,以下是所有支持的內(nèi)容在讶。
final HBPasswordInputTextFieldType type; //格子樣式
final Function onChange;//輸入監(jiān)聽
final int length; //輸入長(zhǎng)度
final TextEditingController controller; //輸入控制器
final FocusNode node; //焦點(diǎn)
final double boxWidth; //格子寬
final double boxHeight; //格子高
final double borderWidth; //邊框?qū)? final double borderRaiuds; //圓角
final Color borderColor; //邊框顏色
final Color fillColor; //填充顏色
final Color backgroundColor; //填充顏色
final double spacing; //格子間隔
final bool obscureText; //是否密文
final String obscureTextString; //密文字符
final TextStyle textStyle; //文本樣式
安裝
在你的項(xiàng)目中pubspec.yaml
中添加
dependencies:
hb_password_input_textfield: ^1.0.1
有必要的話,執(zhí)行一下這個(gè)命令忽冻,我是VSCode保存之后自動(dòng)就執(zhí)行了真朗。
$ flutter pub get
然后在對(duì)應(yīng)文件引用他
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<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
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,
),
)),
);
}
}