Skip to content

Instantly share code, notes, and snippets.

Embed
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 {
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