Created
August 15, 2018 05:11
-
-
Save b-cancel/b84bbd7304c44628864ddd56110000ce to your computer and use it in GitHub Desktop.
FLUTTER => using inputFormatters for things other than inputFormatting
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'dart:async'; | |
import 'package:flutter/material.dart'; | |
import 'package:flutter/services.dart'; | |
void main() => runApp( | |
MaterialApp(home: new MyApp()) | |
); | |
class MyApp extends StatefulWidget { | |
@override | |
MyAppState createState() { | |
return new MyAppState(); | |
} | |
} | |
class MyAppState extends State<MyApp> { | |
final FocusNode emailFocusNode = new FocusNode(); | |
final KeyboardListener keyboardListen = new KeyboardListener(); | |
@override | |
Widget build(BuildContext context) { | |
return Scaffold( | |
body: Center( | |
child: Form( | |
child: TextFormField( | |
inputFormatters: <TextInputFormatter> [keyboardListen], | |
focusNode: emailFocusNode, | |
decoration: new InputDecoration( | |
labelText: "Email", | |
hintText: '[email protected]', | |
), | |
//onFieldSubmitted: (value) => focusEmail(), | |
), | |
), | |
), | |
); | |
} | |
} | |
class KeyboardListener extends TextInputFormatter { | |
@override | |
TextEditingValue formatEditUpdate( | |
TextEditingValue oldValue, | |
TextEditingValue newValue, | |
){ | |
print("find key pressed from a bit of processing with these two values\n " + oldValue.text + " vs " + newValue.text); | |
return newValue; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment