開發過程中有遇到這種需求,發現網上案例還比較少,所以決定還是自己擼一個。
支援限制尺寸,也可以根據字元長度自適應。 差不多就是長這樣子。
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,
)));
}
}
複製程式碼