Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

entering pin code

it’s a flutter widget for entering pin code. suitable for use cases such as login and otp.

usage

use this package as a library

  1. depend on it
    add this to your package’s pubspec.yaml file:
dependencies:
  pin_code_text_field: ^1.2.1
  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:pin_code_text_field/pin_code_text_field.dart';

api

name type default description
maxlength int 4 the total length of pin number & the number of pin boxes.
hidecharacter bool false show or hide the pin code.
highlight bool false highlight the focused pin box.
highlightcolor color colors.black set color of the focused pin box.
pinboxdecoration boxdecoration providedpinboxdecoration._defaultpinboxdecoration customization for the individual pin boxes. check providedpinboxdecoration for possible options.
pintextstyle textstyle textstyle for styling pin characters.
maskcharacter string “u25cf” special character to mask the pin code. will only work if hidecharacter is set to true.
pinboxheight double 70.0 height of pin boxes.
pinboxwidth double 70.0 width of pin boxes.
ondone void function(string) callback when the max length of pin code is reached.
hastextbordercolor color colors.black set color of pin box containing text.
pintextanimatedswitchertransition function(widget child, animation animation) animation of text appearing/disappearing, you can write your own or use a few presets: 1. pincodetextfield.awesometransition 2. pincodetextfield.defaultscalingtransition 3. pincodetextfield.defaultrotatetransition
pintextanimatedswitcherduration duration const duration() duration of pintextanimatedswitchertransition. check providedpinboxtextanimation for possible options.
errorbordercolor color colors.red highlight all textboxes to this color if haserror is set to true
ontextchange function(string) callback that returns a text on input
haserror bool false set all border color to errorbordercolor
autofocus bool false autofocus on view entered
wrapalignment wrapalignment wrapalignment.start alignment of the wrapped pin boxes
pincodetextfieldlayouttype pincodetextfieldlayouttype pincodetextfieldlayouttype.normal auto adjust width with pincodetextfieldlayouttype.auto_adjust_width, wrap the pin box row with pincodetextfieldlayouttype.wrap

example


class myhomepagestate extends state<myhomepage> {
  texteditingcontroller controller = texteditingcontroller();
  string thistext = "";
  int pinlength = 4;

  bool haserror = false;
  string errormessage;


  @override
  widget build(buildcontext context) {
    return scaffold(
      appbar: appbar(
        title: text("pin code text field example"),
      ),
      body: container(
        child: singlechildscrollview(
          child: column(
            mainaxisalignment: mainaxisalignment.center,
            crossaxisalignment: crossaxisalignment.center,
            children: <widget>[
              padding(
                padding: const edgeinsets.only(bottom: 60.0),
                child: text(thistext, style: theme.of(context).texttheme.title),
              ),
              pincodetextfield(
                autofocus: false,
                controller: controller,
                hidecharacter: true,
                highlight: true,
                highlightcolor: colors.blue,
                defaultbordercolor: colors.black,
                hastextbordercolor: colors.green,
                maxlength: pinlength,
                haserror: haserror,
                maskcharacter: "��",

                ontextchanged: (text) {
                  setstate(() {
                    haserror = false;
                  });
                },
                ondone: (text){
                  print("done $text");
                },
                pincodetextfieldlayouttype: pincodetextfieldlayouttype.auto_adjust_width,
                wrapalignment: wrapalignment.start,
                pinboxdecoration: providedpinboxdecoration.underlinedpinboxdecoration,
                pintextstyle: textstyle(fontsize: 30.0),
                pintextanimatedswitchertransition: providedpinboxtextanimation.scalingtransition,
                pintextanimatedswitcherduration: duration(milliseconds: 300),
              ),
              visibility(
                child: text(
                  "wrong pin!",
                  style: textstyle(color: colors.red),
                ),
                visible: haserror,
              ),
              padding(
                padding: const edgeinsets.only(top: 32.0),
                child: row(
                  mainaxisalignment: mainaxisalignment.spaceevenly,
                  children: <widget>[
                    materialbutton(
                      color: colors.blue,
                      textcolor: colors.white,
                      child: text("+"),
                      onpressed: () {
                        setstate(() {
                          this.pinlength++;
                        });
                      },
                    ),
                    materialbutton(
                      color: colors.blue,
                      textcolor: colors.white,
                      child: text("-"),
                      onpressed: () {
                        setstate(() {
                          this.pinlength--;
                        });
                      },
                    ),
                    materialbutton(
                      color: colors.blue,
                      textcolor: colors.white,
                      child: text("submit"),
                      onpressed: () {
                        setstate(() {
                          this.thistext = controller.text;
                        });
                      },
                    ),
                    materialbutton(
                      color: colors.red,
                      textcolor: colors.white,
                      child: text("submit error"),
                      onpressed: () {
                        setstate(() {
                          this.haserror = true;
                        });
                      },
                    ),
                  ],
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}

wishlist

  1. localization (l-r, r-l)
  2. highlight animation
  3. pin box animation

pin usage
entering pin code


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD


Download this source code for
5 USD

Comments are closed.