開發(fā)過程中有遇到這種需求蚁孔,發(fā)現(xiàn)網(wǎng)上案例還比較少荒叶,所以決定還是自己擼一個肆汹。
支持限制尺寸愚墓,也可以根據(jù)字符長度自適應(yīng)。
差不多就是長這樣子昂勉。
Installing
在你的package's pubspec.yaml中加入
dependencies:
hb_check_code: ^0.0.1
DEMO
import 'dart:math';
import 'package:hb_check_code/hb_check_code.dart';
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'HBCheckCode Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: CodeTestPage(),
);
}
}
class CodeTestPage extends StatefulWidget {
@override
_CodeTestPageState createState() => _CodeTestPageState();
}
class _CodeTestPageState extends State<CodeTestPage> {
@override
Widget build(BuildContext context) {
String code = "";
for (var i = 0; i < 6; i++) {
code = code + Random().nextInt(9).toString();
}
return Scaffold(
appBar: AppBar(
title: Text("生成圖形驗證碼"),
),
body: Container(
alignment: Alignment.center,
child: HBCheckCode(
code: code,
)));
}
}