flutter_pin_code_fields 2.2.0

SDKflutter
Platformandroidioswindowslinuxmacosweb

A flutter package which will help you generate customizable pin code fields. Can be used for login pins or OTP.

Flutter Pin Code Fields

GitHub workflow status Version GitHub license

A Flutter package to generate customizable pin code fields.

⭐️ to show support!

Features

  • Highly customizable
  • Responsive
  • Supports animations
  • Supports autofocus
  • Supports autofill
  • Supports obscuring text with custom character

Usage

Add flutter_pin_code_fields as a dependency in your pubspec.yaml file.

# pubspec.yaml

dependencies:
  flutter_pin_code_fields: <latest_version>
import import 'package:flutter_pin_code_fields/flutter_pin_code_fields.dart';

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return PinCodeFields(
      onComplete(text) => print(text);
    );
  }
}

Examples

Basic

Complete example at example/lib/basic.dart.

Example - Basic
PinCodeFields(
  onComplete(text) => print(text),
)

Obscuring text

Complete example at example/lib/obscuring_text.dart.

Example - Obscuring text
PinCodeFields(
  length: 6,
  obscureText: true,
  obscureCharacter: "🔴",
  onComplete(text) => print(text),
)

Customized

Complete example at example/lib/customized.dart.

Example - Customized
PinCodeFields(
  length: 4,
  fieldBorderStyle: FieldBorderStyle.square,
  responsive: false,
  fieldHeight: 130.0,
  fieldWidth: 130.0,
  borderWidth: 5.0,
  activeBorderColor: Colors.blue,
  activeBackgroundColor: Colors.white,
  borderRadius: BorderRadius.circular(20.0),
  keyboardType: TextInputType.number,
  inputFormatters: [FilteringTextInputFormatter.digitsOnly],
  autoHideKeyboard: false,
  fieldBackgroundColor: Colors.black12,
  borderColor: Colors.black12,
  textStyle: TextStyle(
    fontSize: 30.0,
    fontWeight: FontWeight.bold,
  ),
  onComplete(text) => print(text),
)

Animated

Complete example at example/lib/animated.dart.

Example - Animated
PinCodeFields(
  obscureText: true,
  obscureCharacter: "❌",
  animation: Animations.rotateRight,
  animationDuration: Duration(milliseconds: 250),
  animationCurve: Curves.bounceInOut,
  switchInAnimationCurve: Curves.bounceIn,
  switchOutAnimationCurve: Curves.bounceOut,
)

Properties

NameTypeDefaultDescription
lengthint4Total number of pin code fields.
marginEdgeInsetsEdgeInsets.all(5.0)Margin between the fields.
paddingEdgeInsetsEdgeInsets.only(bottom: 5.0)Padding within the field.
fieldHeightdoubleHeight of the field.
fieldWidthdoubleWidth of the field.
borderWidthdouble2.0Width of the border of the field.
borderRadiusBorderRadiusBorder raduis of the field.
borderColorColorColors.greyBorder color of the field.
activeBorderColorColorColors.blueBorder color of the active field.
fieldBorderStyleFieldBorderStyleFieldBorderStyle.bottomBorder styles of the field.
fieldBackgroundColorColorColors.transparentBackground color of the fields.
activeBackgroundColorColorColors.transparentBackground color of the active field.
enabledbooltrueEnable/ disable editing the fields.
responsivebooltrueAdjust the size of the fields automatically to the available space.
autofocusboolfalseEnable/ disabled autofocus.
textStyleTextStyleText style for the fields.
obscureTextboolfalseEnable/ disable obscuring the text in the fields.
obscureCharacterString*Character to obscure the text in the fields.
keyboardTypeTextInputTypeTextInputType.visiblePasswordKeyboard type.
inputFormattersList<TextInputFormatter>Input formatters for the fields.
autoHideKeyboardbooltrueHides the keyboard automatically on complete.
animationAnimationsAnimations.fadeAnimation for the fields.
animationDurationDurationDuration(milliseconds: 150)Duration of the animation.
animationCurveCurveCurves.easeInOutAnimation curve.
switchInAnimationCurveCurveCurves.easeInSwitch in animation curve.
switchOutAnimationCurveCurveCurves.easeOutSwitch out animation curve.
controllerTextEditingControllerText editing controller for the fields.
focusNodeFocusNodeFocus node for the fields.
onChangeValueChanged<String>Callback that returns text on input.
onComplete [required]ValueChanged<String>Callback that returns text on filling all the fields.