Skip to content

Instantly share code, notes, and snippets.

What would you like to do?
TextField formatter
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
main() {
runApp(new Home());
class MyFormatter extends TextInputFormatter {
TextEditingValue formatEditUpdate(TextEditingValue oldValue, TextEditingValue newValue) {
var val = newValue.text + "-";
return new TextEditingValue(text: val, composing: newValue.composing, selection: newValue.selection);
class Home extends StatelessWidget {
Widget build(BuildContext context) {
var widget = new MaterialApp(
home: new Scaffold(
body: new Center(
child: new Container(
width: 300.0,
child: new TextField(
inputFormatters: [
new MyFormatter()
return widget;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment