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

插件详情v0.0.3

otp_screen

一个全新的 Flutter 包,可帮助开发者仅用几行代码即可创建 OTP 屏幕。

近 30 天下载
18
喜欢数
28
Pub 分数
30

安装插件

flutter pub add otp_screen

插件介绍

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

otp_screen 包是一个 Flutter 工具,可使用最少的代码简化 OTP 输入屏幕的创建。它提供了一个简洁、可自定义的小部件,用于输入一次性密码,支持数字和文本输入。该包会自动处理焦点管理,提供字段之间的平滑过渡,并可无缝集成到认证流程中。专为寻求快速可靠实现 OTP 输入的开发者设计,它减少了样板代码并提升了用户体验。

适合场景

  • 使用OTP进行用户身份验证
  • 账户验证工作流程
  • 双因素认证
  • 使用一次性验证码登录
  • 限时令牌的安全表单输入

主要特点

  • 最少的设置,只需几行代码
  • 字段之间的自动焦点处理
  • 可定制的输入设计
  • 支持数值和文本输入
  • 内置验证和错误处理

适合对象

  • 开发登录或验证屏幕的开发者
  • 需要安全OTP输入的项目
  • 使用双重身份验证或基于短信的身份验证的应用程序
  • 快速原型设计身份验证UI
  • 移动应用中的时效性代码输入

使用建议

  • 仅限OTP特定用途
  • 不支持动态字段数量的内置支持
  • 需要与后端验证进行手动集成
  • 不处理OTP重发逻辑
  • 不适合复杂表单场景

原始 README

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

otp_screen

A new Flutter package for both android & iOS which helps developer in creating Otp screen with few lines of code.

Show some :heart: and star the repo to support the project

Screenshots


Usage

Example

To use this package:

    dependencies:
        flutter:
          sdk: flutter
        otp_screen: <latest-version>
How to use

  // logic to validate otp return [null] when success else error [String]
  Future<String> validateOtp(String otp) async {
    await Future.delayed(Duration(milliseconds: 2000));
    if (otp == "1234") {
      return null;
    } else {
      return "The entered Otp is wrong";
    }
  }

  // action to be performed after OTP validation is success
  void moveToNextScreen(context) {
    Navigator.push(context, MaterialPageRoute(
        builder: (context) => SuccessfulOtpScreen()));
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      // initialize the OTP screen by passing validation logic and route callback
      home: OtpScreen(
        otpLength: 4,
        validateOtp: validateOtp,
        routeCallback: moveToNextScreen,
        titleColor: Colors.black,
        themeColor: Colors.black,
      ),
    );
  }
}

The above code opens the simple OTP screen


Customize Options

You can play with different colors and add gradients as background to the screen

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: OtpScreen.withGradientBackground(
          topColor: Color(0xFFcc2b5e),
          bottomColor: Color(0xFF753a88),
          otpLength: 4,
          validateOtp: validateOtp,
          routeCallback: moveToNextScreen,
          themeColor: Colors.white,
          titleColor: Colors.white,
          title: "Phone Number Verification",
          subTitle: "Enter the code sent to \n +919876543210",
          icon: Image.asset(
            'images/phone_logo.png',
            fit: BoxFit.fill,
          ),
      ),

The output of the above code will open below screen.

Created & Maintained By

[Lokesh Chennamchetty] (https://github.com/lokesh-sudhakar)

所属分类

依赖

依赖清单 1 项

源码仓库

使用此插件的项目

暂无相关数据。