Skip to content

Instantly share code, notes, and snippets.

@b-cancel
Created August 15, 2018 05:11
Show Gist options
  • Save b-cancel/b84bbd7304c44628864ddd56110000ce to your computer and use it in GitHub Desktop.
Save b-cancel/b84bbd7304c44628864ddd56110000ce to your computer and use it in GitHub Desktop.
FLUTTER => using inputFormatters for things other than inputFormatting
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