Skip to content

Instantly share code, notes, and snippets.

@saliouseck2009
Created January 28, 2022 15:22
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save saliouseck2009/29e62c2128d513f11039297065cca4b9 to your computer and use it in GitHub Desktop.
Save saliouseck2009/29e62c2128d513f11039297065cca4b9 to your computer and use it in GitHub Desktop.
Flutter TextField
TextEditingController controller = TextEditingController();
TextField(
keyboardType: TextInputType.number,
textCapitalization: TextCapitalization.sentences,
textAlign: TextAlign.center,
style: TextStyle(color: Colors.red, fontWeight: FontWeight.w300),
cursorColor: Colors.red,
cursorRadius: Radius.circular(16.0),
cursorWidth: 16.0,
maxLength: 4,
obscureText: true,
decoration: InputDecoration(
icon: Icon(Icons.print)
border: OutlineInputBorder()
),
textInputAction: TextInputAction.continueAction,
onChanged: (text) {
value = text;
},
controller: controller,
onEditingComplete: () {},
onSubmitted: (value) {},
autofocus: true,
)
#Working with custom focus changes
# Initialise outside the build method
FocusNode nodeOne = FocusNode();
FocusNode nodeTwo = FocusNode();
// Do this inside the build method
TextField(
focusNode: nodeOne,
decoration: InputDecoration(
hintText: "Demo Text",
hintStyle: TextStyle(fontWeight: FontWeight.w300, color: Colors.red)
),
TextField(
focusNode: nodeTwo,
),
RaisedButton(
onPressed: () {
FocusScope.of(context).requestFocus(nodeTwo);
},
child: Text("Next Field"),
),
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment