搜尋套件、儲存庫與 APP 分類

fancy_password_field 封面
套件詳情v3.0.0

fancy_password_field

一個高度可自訂的密碼輸入控制元件。它具備密碼強度和規則驗證等功能

AndroidiOSWebmacOSWindowsLinux
近 30 天下載
6630
喜歡數
110
Pub 分數
160

安裝套件

flutter pub add fancy_password_field

套件介紹

根據套件公開資料產生的選型評估,僅供參考。

一個高度可自訂的 Flutter 密碼輸入元件,提供即時密碼強度評估與規則驗證。它透過顯示密碼複雜度的視覺反饋(例如長度、特殊字元和大寫字母)來增進使用者體驗。此元件支援 Android、iOS、Web、macOS、Windows 與 Linux 等多個平台,非常適合需要安全驗證的跨平台應用程式。開發者可依應用設計需求客製化其外觀與行為。

適用情境

  • 安全登入表單
  • 用戶註冊流程
  • 即時反饋的密碼建立
  • 多平台身份驗證介面
  • 帶有視覺指示器的表單驗證

主要特色

  • 即時密碼強度分析
  • 可設定的驗證規則
  • 可自定義的使用者介面和樣式
  • 跨平台相容性
  • 密碼要求的互動式反饋
  • 對國際化支援

適合對象

  • 開發安全驗證系統的開發者
  • 需要強密碼策略的應用程式
  • 想要靈活表單組件的設計師
  • 針對多個操作系統的專案
  • 優先考慮使用者友善的密碼輸入的團隊

使用建議

  • 需要仔細配置驗證規則
  • 可能需要額外的本地化以支援非英文使用者
  • 在大型表單中過度使用時的性能影響
  • 僅限密碼專用使用案例,不適用於一般文字輸入

原始 README

以下為關聯原始碼儲存庫的 README 原文快照,最新內容請造訪原始碼儲存庫。

codecov

Buy Me A Coffee

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.

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: Scaffold(
        body: FancyPasswordField(),
      ),
    );
  }
}

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.

enter image description here

We can go a bit further and pass some validations rules to our widget.

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: Scaffold(
        body: FancyPasswordField(
            validationRules: {
                DigitValidationRule(),
                UppercaseValidationRule(),
                LowercaseValidationRule(),
                SpecialCharacterValidationRule(),
                MinCharactersValidationRule(6),
                MaxCharactersValidationRule(12),
            },
        ),
      ),
    );
  }
}

enter image description here

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.

class ContainsTripleAValidationRule extends ValidationRule {
  @override
  String get name => 'Contains AAA';

  @override
  bool validate(String value) {
    return value.contains('AAA');
  }
}

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.

final FancyPasswordController _passwordController = FancyPasswordController();

@override
Widget build(BuildContext context) {
  return Scaffold(
    body: Center(
      child: Form(
        key: _formKey,
        child: Column(
          mainAxisAlignment: MainAxisAlignment.center,
          children: <Widget>[
            SizedBox(
              width: 400,
              child: FancyPasswordField(
                passwordController: _passwordController,
                validationRules: {
                  DigitValidationRule(),
                  UppercaseValidationRule(),
                },
                validator: (value) {
                  return _passwordController.areAllRulesValidated
                      ? null
                      : 'Not Validated';
                },
              ),
            ),
          ],
        ),
      ),
    ),
  );
}

Customization

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.

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      home: Scaffold(
        body: SizedBox(
            width: 400,
            child: FancyPasswordField(
                validationRules: {
                    DigitValidationRule(),
                    UppercaseValidationRule(),
                    LowercaseValidationRule(),
                    SpecialCharacterValidationRule(),
                    MinCharactersValidationRule(6),
                    MaxCharactersValidationRule(12),
                },
                strengthIndicatorBuilder: (strength) => Text(
                  strength.toString(),
                ),
                validationRuleBuilder: (rules, value) {
                  if (value.isEmpty) {
                    return const SizedBox.shrink();
                  }
                  return ListView(
                    shrinkWrap: true,
                    children: rules
                        .map(
                          (rule) => rule.validate(value)
                              ? Row(
                                  children: [
                                    const Icon(
                                        Icons.check,
                                        color: Colors.green,
                                    ),
                                    const SizedBox(width: 12),
                                    Text(
                                        rule.name,
                                        style: const TextStyle(
                                            color: Colors.green,
                                        ),
                                    ),
                                  ],
                                )
                              : Row(
                                  children: [
                                    const Icon(
                                        Icons.close,
                                        color: Colors.red,
                                    ),
                                    const SizedBox(width: 12),
                                    Text(
                                        rule.name,
                                        style: const TextStyle(
                                            color: Colors.red,
                                        ),
                                    ),
                                  ],
                                ),
                        )
                        .toList(),
                  );
                },
              ),
            ),
      ),
    );
  }
}

enter image description here

Samples

Sample 1 Sample 2 Sample 3 Sample 4

Suggestions & Bugs

For any suggestions or bug report please head to issue tracker.

所屬分類

依賴

依賴清單 2 項

原始碼儲存庫

使用此套件的專案