开发过程中有遇到这种需求,发现网上案例还比较少,所以决定还是自己撸一个。
支持限制尺寸,也可以根据字符长度自适应。
差不多就是长这样子。
WeChata674f8a31d96e0c460a67aaf7ab94946.png
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,
)));
}
}
网友评论