Home > Mobile >  Flutter TextField for input time
Flutter TextField for input time

Time:01-11

As I wrote in the title I'd like to create a specific TextField to enter time. More in depth I wanted the user to enter just 4 digits and the field automatically shows somethings like that 12:23, so automatically the field will insert ":" character.

An empty TextField will show nothing. When user enters digits TextField will show : 1 --> 12 --> 12:2 --> 12:23 I've tried controller but I'm not able to reach my purpose. Can someone help me?

thank you, have a nice day

CodePudding user response:

https://pub.dev/packages/flutter_multi_formatter

Custom format

TextFormField(
    keyboardType: TextInputType.number,
    inputFormatters: [
        MaskedInputFormatter('##:##'))
    ],
),

CodePudding user response:

Try this one

 TextFormField(
      controller: _controller,
      maxLength: 5,
      onChanged: (value){
        if(_controller.text.length==2){
          _controller.text = _controller.text   ":";
        }
      },
    ),
  •  Tags:  
  • Related