Search packages, repositories and app categories

Package detailsv0.0.3

otp_screen

A new Flutter package which helps developer in creating Otp screen with few lines of code.

30-day downloads
18
Likes
28
Pub points
30

Install package

flutter pub add otp_screen

Package Overview

Package selection guidance compiled from public package information, community data, and project usage.

The otp_screen package is a Flutter utility that simplifies the creation of OTP input screens with minimal code. It provides a clean, customizable widget for entering one-time passwords, supporting both numeric and text inputs. The package handles focus management automatically, offers smooth transitions between fields, and integrates seamlessly into authentication flows. Designed for developers seeking a quick and reliable way to implement OTP entry, it reduces boilerplate and enhances user experience.

Use cases

  • User authentication with OTP
  • Account verification workflows
  • Two-factor authentication
  • Login with one-time codes
  • Secure form input for time-limited tokens

Key features

  • Minimal setup with few lines of code
  • Automatic focus handling between fields
  • Customizable input design
  • Supports both numeric and text input
  • Built-in validation and error handling

Suitable for

  • Developers building login or verification screens
  • Projects requiring secure OTP input
  • Apps using 2FA or SMS-based authentication
  • Fast prototyping of authentication UIs
  • Mobile apps with time-sensitive code entry

Considerations

  • Limited to OTP-specific use cases
  • No built-in support for dynamic field count
  • Requires manual integration with backend validation
  • Does not handle OTP resend logic
  • Not suitable for complex form scenarios

Original README

Original README snapshot from the linked source repository. Visit the repository for the latest content.

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)

Categories

Dependencies

Dependency list 1 items

Source repository

Projects using this package

No data available yet.