搜索插件、代码仓与 APP 分类

flutter_pin_code_fields 封面
插件详情v2.2.0

flutter_pin_code_fields

一个 Flutter 包,可帮助您生成可自定义的验证码输入框。可用于登录密码或 OTP。

AndroidiOSWebmacOSWindowsLinux
近 30 天下载
2490
喜欢数
28
Pub 分数
150

安装插件

flutter pub add flutter_pin_code_fields

插件介绍

基于插件公开信息、社区数据与项目使用情况整理的选型参考。

一个可自定义的 Flutter 包,用于创建验证码输入框,非常适合登录密码或 OTP 输入。它提供了一个简洁、可重复使用的界面,支持多种样式选项和输入验证。该包可在所有主要平台(包括 Android、iOS、Web、macOS、Windows 和 Linux)上兼容使用。设计简单灵活,使开发者能够轻松地将安全且用户友好的 PIN 码输入体验集成到他们的应用中。

适合场景

  • OTP 验证流程
  • 用户使用PIN码登录
  • 安全的身份验证接口
  • 需要数字代码的表单输入
  • 多步骤注册流程

主要特点

  • 可自定义字段外观
  • 支持不同的输入类型
  • 内置验证
  • 跨平台兼容性
  • 与表单控制器轻松集成
  • 适用于所有设备的响应式设计

适合对象

  • 开发身份验证功能的开发者
  • 需要安全PIN码输入的应用程序
  • 需要 OTP 输入字段的项目
  • 包含数值输入的界面密集型表单
  • 移动和网页应用的统一用户体验

使用建议

  • 需要手动处理提交逻辑
  • 有限的内置错误反馈
  • 无原生生物识别回退支持
  • 可能需要为复杂主题添加额外的样式
  • 未针对超过6-8位数的长PIN进行优化

原始 README

以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。

Flutter Pin Code Fields

GitHub workflow status Version GitHub license

A Flutter package to generate customizable pin code fields.

⭐️ to show support!

Features

  • Highly customizable
  • Responsive
  • Supports animations
  • Supports autofocus
  • Supports autofill
  • Supports obscuring text with custom character

Usage

Add flutter_pin_code_fields as a dependency in your pubspec.yaml file.

# pubspec.yaml

dependencies:
  flutter_pin_code_fields: <latest_version>
import import 'package:flutter_pin_code_fields/flutter_pin_code_fields.dart';

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return PinCodeFields(
      onComplete(text) => print(text);
    );
  }
}

Examples

Basic

Complete example at example/lib/basic.dart.

Example - Basic
PinCodeFields(
  onComplete(text) => print(text),
)

Obscuring text

Complete example at example/lib/obscuring_text.dart.

Example - Obscuring text
PinCodeFields(
  length: 6,
  obscureText: true,
  obscureCharacter: "🔴",
  onComplete(text) => print(text),
)

Customized

Complete example at example/lib/customized.dart.

Example - Customized
PinCodeFields(
  length: 4,
  fieldBorderStyle: FieldBorderStyle.square,
  responsive: false,
  fieldHeight: 130.0,
  fieldWidth: 130.0,
  borderWidth: 5.0,
  activeBorderColor: Colors.blue,
  activeBackgroundColor: Colors.white,
  borderRadius: BorderRadius.circular(20.0),
  keyboardType: TextInputType.number,
  inputFormatters: [FilteringTextInputFormatter.digitsOnly],
  autoHideKeyboard: false,
  fieldBackgroundColor: Colors.black12,
  borderColor: Colors.black12,
  textStyle: TextStyle(
    fontSize: 30.0,
    fontWeight: FontWeight.bold,
  ),
  onComplete(text) => print(text),
)

Animated

Complete example at example/lib/animated.dart.

Example - Animated
PinCodeFields(
  obscureText: true,
  obscureCharacter: "❌",
  animation: Animations.rotateRight,
  animationDuration: Duration(milliseconds: 250),
  animationCurve: Curves.bounceInOut,
  switchInAnimationCurve: Curves.bounceIn,
  switchOutAnimationCurve: Curves.bounceOut,
)

Properties

Name Type Default Description
length int 4 Total number of pin code fields.
margin EdgeInsets EdgeInsets.all(5.0) Margin between the fields.
padding EdgeInsets EdgeInsets.only(bottom: 5.0) Padding within the field.
fieldHeight double Height of the field.
fieldWidth double Width of the field.
borderWidth double 2.0 Width of the border of the field.
borderRadius BorderRadius Border raduis of the field.
borderColor Color Colors.grey Border color of the field.
activeBorderColor Color Colors.blue Border color of the active field.
fieldBorderStyle FieldBorderStyle FieldBorderStyle.bottom Border styles of the field.
fieldBackgroundColor Color Colors.transparent Background color of the fields.
activeBackgroundColor Color Colors.transparent Background color of the active field.
enabled bool true Enable/ disable editing the fields.
responsive bool true Adjust the size of the fields automatically to the available space.
autofocus bool false Enable/ disabled autofocus.
textStyle TextStyle Text style for the fields.
obscureText bool false Enable/ disable obscuring the text in the fields.
obscureCharacter String * Character to obscure the text in the fields.
keyboardType TextInputType TextInputType.visiblePassword Keyboard type.
inputFormatters List<TextInputFormatter> Input formatters for the fields.
autoHideKeyboard bool true Hides the keyboard automatically on complete.
animation Animations Animations.fade Animation for the fields.
animationDuration Duration Duration(milliseconds: 150) Duration of the animation.
animationCurve Curve Curves.easeInOut Animation curve.
switchInAnimationCurve Curve Curves.easeIn Switch in animation curve.
switchOutAnimationCurve Curve Curves.easeOut Switch out animation curve.
controller TextEditingController Text editing controller for the fields.
focusNode FocusNode Focus node for the fields.
onChange ValueChanged<String> Callback that returns text on input.
onComplete [required] ValueChanged<String> Callback that returns text on filling all the fields.

所属分类

源码仓库

使用此插件的项目