一个高度可定制的 Flutter 密码输入小部件,提供实时密码强度评估和规则验证。它通过显示密码复杂性的视觉反馈(如长度、特殊字符和大写字母)来提升用户体验。该小部件支持 Android、iOS、Web、macOS、Windows 和 Linux 等多个平台,非常适合需要安全认证的跨平台应用程序。开发者可以根据应用设计需求自定义其外观和行为。
适合场景
安全登录表单
用户注册流程
实时反馈的密码创建
多平台身份验证接口
带有视觉指示器的表单验证
主要特点
实时密码强度分析
可配置的验证规则
可自定义的用户界面和样式
跨平台兼容性
密码要求的交互式反馈
对国际化支持
适合对象
开发安全认证系统的开发者
需要强密码策略的应用程序
想要灵活表单组件的设计师
针对多个操作系统的项目
优先考虑用户友好的密码输入的团队
使用建议
需要仔细配置验证规则
可能需要额外的本地化以支持非英语用户
在大型表单中过度使用时的性能影响
仅限密码专用用例,不适用于通用文本输入
原始 README
以下为关联源码仓库的 README 原文快照,最新内容请访问源码仓库。
Introduction
FancyPasswordField is a widget that acts as a password validation field. You can have all the features of a commom password field, and also gets cool features like setting validation rules and password strength.
Requirements
Starting with 3.0.0 this package is built on top of material_ui, the Material Design library that has been decoupled from the Flutter framework. It requires Flutter 3.44.0 or newer and Dart 3.12.0 or newer.
Because material_ui ships its own copies of the Material widgets, InputDecoration from package:material_ui/material_ui.dart is a different type from the one in package:flutter/material.dart. Your app has to import Material from the same place this package does:
import'package:fancy_password_field/fancy_password_field.dart';
import'package:material_ui/material_ui.dart'; // instead of package:flutter/material.dart
If you are not ready to move your app off package:flutter/material.dart, stay on fancy_password_field: ^2.0.8.
Basic Usage
The most simple usage is just using FancyPasswordField withou any properties.
This will create a password field with some default configurations. The default behavior is to show the strength indicator
above the form field. You can disabled this behavior passing false to the hasStrengthIndicator property.
We can go a bit further and pass some validations rules to our widget.
These package comes if some pre defined commom rules so you can just use out of the box. Feel free to implement your own [ValidationRule] and adds normaly to the password field.
Custom Rules
As described earlier, the package comes with built in commom used rules, but you can create your own custom rules. To do this, just extends the base [ValidationRule] abstract class. You'll have to provide a name and a validation function for your rule.
Just doing that is already enough for your rule just work. Pass your rule to the [validationRules] set of the [FancyPasswordField] and the showing and validation of the rules will occur.
Password Controller
The [FancyPasswordField] has a controller that you can pass. The purpose of this controller is almost the same as any controller on the Flutter world. The controller gives you access to underline info of the field. Notably, it gives you information about the rules and what rules are beeing ofended at any point. The controller has also one getter that indicates whether all rules are ok or not.
One use case of this is if you want to validate the status of the form field to enable or disable the saving of a form.
The [FancyPasswordField] comes with some pre defined widget that show some okish good looking components for the strenght indicator
and for the rules. But the widget was designed to be fully customizable. So you can pass your own builers to both the
strength password widget and the rules widget.
On the Samples section you can grab a lot of customizations samples.
Above we can see an example of some possible customization for these fields.