Skip to content

Instantly share code, notes, and snippets.

@manujbahl
Created July 16, 2018 21:18
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 manujbahl/82ddf859c60700a697fecb58114a0b2f to your computer and use it in GitHub Desktop.
Save manujbahl/82ddf859c60700a697fecb58114a0b2f to your computer and use it in GitHub Desktop.
TextField formatter
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
main() {
runApp(new Home());
}
class MyFormatter extends TextInputFormatter {
MyFormatter();
@override
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 {
@override
Widget build(BuildContext context) {
var widget = new MaterialApp(
home: new Scaffold(
body: new Center(
child: new Container(
width: 300.0,
child: new TextField(
keyboardType:TextInputType.number,
inputFormatters: [
new MyFormatter()
],
)
)
)
),
);
return widget;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment