I'm trying to add a date mask to a textField since I did not like the Date Picker because for date of birth, for example, it is not as nimble. After that, converting from string to datetime, I believe I can continue the project, Thanks in advance.
static final TextEditingController _birthDate = new TextEditingController();
new TextFormField(
controller: _birthDate,
maxLength: 10,
keyboardType: TextInputType.datetime,
validator: _validateDate
), String _validateDate(String value) {
if(value.isEmpty)
return null;
if(value.length != 10)
return 'Enter date in DD / MM / YYYY format';
return null;
}
First, create a text field or text from field. Then declare a variable inside the class called _isvisible or anything you want and set the value false.
By default, a TextField is decorated with an underline. You can add a label, icon, inline hint text, and error text by supplying an InputDecoration as the decoration property of the TextField . To remove the decoration entirely (including the underline and the space reserved for the label), set the decoration to null.
You can use the decoration on TextField like this: decoration: InputDecoration( hintText: 'Type Text Here', enabledBorder: UnderlineInputBorder( borderSide: BorderSide(color: Colors. red), ), And this will change the line to color red.
flutter_masked_text Masked text input for flutter. Install Follow this GUIDE Usage Import the library import 'package:flutter_masked_text/flutter_masked_text.dart'; MaskedText Create your mask controller: var controller = new MaskedTextController(mask: '000.000.000-00');
Text fields allow users to type text into an app. They are used to build forms, send messages, create search experiences, and more. In this recipe, explore how to create and style text fields. Flutter provides two text fields: TextField and TextFormField. TextField is the most commonly used text input widget.
Create your mask controller: var controller = new MaskedTextController(mask: '000.000.000-00'); Set controller to your text field:
Initial Value To start a mask with initial value, just use textproperty on constructor: var controller = new MaskedTextController(mask: '000-000', text: '123456'); Update text programaticaly If you want to set new text after controller initiatialization, use the updateTextmethod:
https://pub.dartlang.org/packages/masked_text
masked_text
A package for masked texts, so if you want a mask for phone, or zip code or any kind of mask, just use it :D
Getting Started
It's very simple, it's a Widget as all the other ones.
new MaskedTextField
(
maskedTextFieldController: _textCPFController,
mask: "xx/xx/xxxx",
maxLength: 10,
keyboardType: TextInputType.number,
inputDecoration: new InputDecoration(
hintText: "Digite a data do seu nascimento", labelText: "Data"),
);
'x' is the normal char that your text will have.
this sample reproduces something like this in the end: 11/02/1995
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With