패키지, 저장소 및 앱 카테고리 검색

otp_pin_field 표지
패키지 상세v1.5.2

otp_pin_field

아름다운 디자인과 애니메이션을 갖춘 핀 코드 필드를 생성하는 데 도움이 되는 플러터 패키지입니다. OTP 또는 핀 코드 입력에 유용할 수 있습니다.

AndroidiOSWeb
30일 다운로드
2.5천
좋아요
54
Pub 점수
130

패키지 설치

flutter pub add otp_pin_field

패키지 개요

공개 정보를 바탕으로 생성한 선택 가이드입니다.

시각적으로 매력적인 핀 코드 필드를 부드러운 애니메이션과 함께 생성하기 위한 플러터 패키지로, OTP 또는 비밀번호 입력 시나리오에 이상적입니다. 인증 흐름 중 사용자 경험을 향상시키는 깔끔하고 사용자 정의 가능한 인터페이스를 제공합니다. Android, iOS, Web 등 다양한 플랫폼을 지원하여 크로스플랫폼 애플리케이션에 유연하게 활용할 수 있습니다. pub 명령어를 통해 최소한의 설정으로 개발자는 빠르게 반응형이고 상호작용 가능한 핀 필드를 앱에 통합할 수 있습니다.

사용 사례

  • OTP 인증 화면
  • 보안 PIN 입력 양식
  • 로그인 또는 인증 흐름
  • 이중 인증
  • 디지털 지갑 액세스 코드
  • 온라인 결제 확인

주요 기능

  • 애니메이션 입력 전환
  • 사용자 정의 가능한 디자인 및 색상
  • 장치 간 반응형 레이아웃
  • Flutter와의 간편한 통합
  • 다중 플랫폼 지원
  • 내장된 검증 및 포커스 관리

적합한 대상

  • 모바일 앱 개발자
  • 인증 기능 구현자
  • 사용자 경험 중심의 애플리케이션 빌더
  • 크로스 플랫폼 앱 제작자
  • 재사용 가능한 컴포넌트를 찾는 프론트엔드 개발자
  • 보안 숫자 입력이 필요한 앱

고려 사항

  • 숫자 입력만 가능
  • 기본 검증을 넘어서는 내장된 오류 처리 없음
  • 고급 사용자 정의를 위해 수동 구현이 필요합니다
  • 다크 모드 호환성을 위해 추가 스타일링이 필요할 수 있습니다
  • 완전한 기능을 위해 외부 종속성에 의존합니다
  • 비숫자 또는 긴 형식의 입력에 최적화되어 있지 않음

원본 README

연결된 소스 저장소의 README 원문 스냅샷입니다. 최신 내용은 저장소에서 확인하세요.

Pub

otp_pin_field

A flutter package which will help you to generate pin code fields with beautiful design and animations. It's a beautiful and highly customizable Flutter widget for entering pin code.

Created by Techahead Software

Usage

Use this package as a library

  1. Depend on it Add this to your package's pubspec.yaml file:
dependencies:
  otp_pin_field: <VERSION>
  1. Install it You can install packages from the command line: with Flutter:
$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

  1. Import it Now in your Dart code, you can use:
import 'package:otp_pin_field/otp_pin.dart';

Properties

name type default description
fieldCount int 4 The total length of pin number & the number of pin boxes.
highlightBorder bool true highlight the focused pin box.
activeFieldBorderColor Color Colors.black Set color of the focused pin box.
activeFieldBackgroundColor Color Colors.transparent Set background color of the focused pin box.
defaultFieldBorderColor Color Colors.black45 Set color of the unfocused pin box.
defaultFieldBackgroundColor Color Colors.transparent Set background color of the unfocused pin box.
fieldPadding double 20.0 Set padding for pin box.
fieldBorderRadius double 2.0 Set border radius for pin box.
fieldBorderWidth double 2.0 Set border width for pin box.
textStyle TextStyle TextStyle(fontSize: 18.0,color: Colors.black,) TextStyle for styling pin characters.
otpPinFieldInputType OtpPinFieldInputType OtpPinFieldInputType.none Want to show text of otp_pin_field(OtpPinFieldInputType.none) or not(OtpPinFieldInputType.password) or want to show some special character(OtpPinFieldInputType.custom)
otpPinInputCustom String "*" Special character to mask the pin code. Will only work if uses otpPinFieldInputType is set to OtpPinFieldInputType.custom.
onSubmit void Function(String) Callback when the max length of pin code is reached.
onChange void Function(String) Callback when there is any change in OTP Pin Field.
otpPinFieldStyle OtpPinFieldStyle OtpPinFieldStyle() Customization for the individual pin boxes. Check OtpPinFieldStyle for possible options.
fieldHeight double 45.0 Height of pin boxes.
fieldWidth double 70.0 Width of pin boxes.
otpPinFieldDecoration OtpPinFieldDecoration OtpPinFieldDecoration.underlinedPinBoxDecoration Predefine customization for the individual pin boxes. Check OtpPinFieldStyle for possible options and use OtpPinFieldDecoration.custom for fully customization like boarder radius,width, active and default otp_pin_field colors and etc..
keyboardType TextInputType TextInputType.number The type of the input keyboard
autofocus bool false Autofocus on view entered
cursorColor Color Color.black To give color to the cursor
cursorWidth double 2 To give width to the cursor
showCursor bool true To show cursor in the otp pin fields
mainAxisAlignment MainAxisAlignment MainAxisAlignment.center Manage the spacing in the otp pin fields
upperChild Widget Container() Widget which will show above the otp pin fields only when showCustomKeyboard is set to be true
middleChild Widget Container() Widget which will show between the otp pin fields and Custom Keyboard only when showCustomKeyboard is set to be true
showCustomKeyboard bool false To show custom keyboard in place default keyboard
customKeyboard Widget Widget which help you to show your own custom keyboard in place if default custom keyboard
showDefaultKeyboard bool true Bool which manage to show default OS keyboard
autoFillEnable bool false Bool which manage to enable auto fill functionality For Ios it is not needed as the SMS autofill is provided by default, but not for Android, that's where this key is useful.
smsRegex String '\d{0,4}' String which take use to show the OTP from the message
phoneNumbersHint bool false Bool which manage to enable auto fill functionality Is a widget that will allow you ask for system phone number and autofill the widget if a phone is choosen by the user. [Android only]
textInputAction TextInputAction TextInputAction.done In case you want to change the action of keyboard
filledFieldBackgroundColor Color Colors.transparent Set background color of the filled field pin box.
filledFieldBorderColor Color Colors.transparent Set color of the border of filled field pin box.
activeFieldBorderGradient Gradient Set gradient border Color for focused field pin box.
filledFieldBorderGradient Gradient Set gradient border Color for filled field pin box.
defaultFieldBorderGradient Gradient Set gradient border Color for unfocused/default field pin box.
onPhoneHintSelected Function(String) Callback when you select the autofill hints.
beforeTextPaste bool Function(String?)? null This callback execute before you copy paste the OTP
showHintText bool false Bool to show hints in pin field or not
hintTextColor Color Color.black45 To set the color of hints in pin field or not
hintText String 0 To set the text of hints in pin field
unFocusOnEnding bool true A boolean that controls hiding and unhiding the keyboard after entering the OTP.

Example


///  Otp pin Controller
  final _otpPinFieldController = GlobalKey<OtpPinFieldState>();
  
  
         OtpPinField(
            key: _otpPinFieldController,

            ///in case you want to enable autoFill
            autoFillEnable: false,

            ///for Ios it is not needed as the SMS autofill is provided by default, but not for Android, that's where this key is useful.
            textInputAction: TextInputAction.done,

            ///in case you want to change the action of keyboard
            /// to clear the Otp pin Controller
            onSubmit: (text) {
              print('Entered pin is $text');

              /// return the entered pin
            },
            onChange: (text) {
              print('Enter on change pin is $text');

              /// return the entered pin
            },
            onCodeChanged: (code) {
              print('onCodeChanged  is $code');
            },

            /// to decorate your Otp_Pin_Field
            otpPinFieldStyle: OtpPinFieldStyle(
            
              /// bool to show hints in pin field or not
                showHintText: true,

              /// to set the color of hints in pin field or not
              // hintTextColor: Colors.red,

              /// To set the text  of hints in pin field
              // hintText: '1',
                
              /// border color for inactive/unfocused Otp_Pin_Field
              // defaultFieldBorderColor: Colors.red,

              /// border color for active/focused Otp_Pin_Field
              // activeFieldBorderColor: Colors.indigo,

              /// Background Color for inactive/unfocused Otp_Pin_Field
              // defaultFieldBackgroundColor: Colors.yellow,

              /// Background Color for active/focused Otp_Pin_Field
              // activeFieldBackgroundColor: Colors.cyanAccent,

              /// Background Color for filled field pin box
              // filledFieldBackgroundColor: Colors.green,

              /// border Color for filled field pin box
              // filledFieldBorderColor: Colors.green,
              //
              /// gradient border Color for field pin box
              activeFieldBorderGradient: LinearGradient(colors: [Colors.black, Colors.redAccent]),
              filledFieldBorderGradient: LinearGradient(colors: [Colors.green, Colors.tealAccent]),
              defaultFieldBorderGradient: LinearGradient(colors: [Colors.orange, Colors.brown]),
            ),
            maxLength: 4,

            /// no of pin field
            showCursor: true,

            /// bool to show cursor in pin field or not
            cursorColor: Colors.indigo,

            /// to choose cursor color
            upperChild: Column(
              children: [
                SizedBox(height: 30),
                Icon(Icons.flutter_dash_outlined, size: 150),
                SizedBox(height: 20),
              ],
            ),
            middleChild: Column(
              children: [
                SizedBox(height: 30),
                ElevatedButton(
                    onPressed: () {
                      _otpPinFieldController.currentState
                          ?.clearOtp(); // clear controller
                    },
                    child: Text('clear OTP')),
                SizedBox(height: 10),
                ElevatedButton(
                    onPressed: () => Navigator.push(context,
                        MaterialPageRoute(builder: (context) => NextPage())),
                    child: Text('Next Class')),
                SizedBox(height: 30),
              ],
            ),

            ///bool which manage to show custom keyboard
            showCustomKeyboard: true,

            /// Widget which help you to show your own custom keyboard in place if default custom keyboard
            // customKeyboard: Container(),
            ///bool which manage to show default OS keyboard
            // showDefaultKeyboard: true,

            /// to select cursor width
            cursorWidth: 3,

            /// place otp pin field according to yourself
            mainAxisAlignment: MainAxisAlignment.center,

            /// predefine decorate of pinField use  OtpPinFieldDecoration.defaultPinBoxDecoration||OtpPinFieldDecoration.underlinedPinBoxDecoration||OtpPinFieldDecoration.roundedPinBoxDecoration
            ///use OtpPinFieldDecoration.custom  (by using this you can make Otp_Pin_Field according to yourself like you can give fieldBorderRadius,fieldBorderWidth and etc things)
            otpPinFieldDecoration:
                OtpPinFieldDecoration.defaultPinBoxDecoration,
          ),
              
Android SMS constraint

For the code to be receive, it need to follow some rules as describe here: https://developers.google.com/identity/sms-retriever/verify

  • Be no longer than 140 bytes
  • Contain a one-time code that the client sends back to your server to complete the verification flow
  • End with an 11-character hash string that identifies your app

One example of SMS would be:

8125 is you verification code Ov114rXIhwf ( Ov114rXIhwf is your hash value which you will get in log ``` search  your hash value is`` and append that value in your sms)

refer to example/lib/main.dart

Different Shapes
OTP Pin Field - Example 1 OTP Pin Field - Example 2 OTP Pin Field - Example 3 OTP Pin Field - Example 4 OTP Pin Field - Example 5 OTP Pin Field - Example 6 OTP Pin Field - Example 7 OTP Pin Field - Example 8 OTP Pin Field - Example 9 OTP Pin Field - Example 10
video
Animated OTP Pin Field Example

More information

Pub package

Flutter documentation.

카테고리

의존성

의존성 목록 2 개

소스 저장소

이 패키지를 사용하는 프로젝트

아직 데이터가 없습니다.