Skip to content

Instantly share code, notes, and snippets.

@atreeon
Last active November 29, 2022 16:48
Show Gist options
  • Save atreeon/55b83253540890dad410349224e30736 to your computer and use it in GitHub Desktop.
Save atreeon/55b83253540890dad410349224e30736 to your computer and use it in GitHub Desktop.
Flutter TextField events
// ignore_for_file: annotate_overrides
// ignore_for_file: prefer_const_constructors
// ignore_for_file: prefer_const_literals_to_create_immutables
// ignore_for_file: unused_local_variable
// ignore_for_file: library_private_types_in_public_api
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: Center(
child: Blah(),
),
),
);
}
}
class Blah extends StatefulWidget {
_BlahState createState() => _BlahState();
}
class _BlahState extends State<Blah> {
var onValue = <String>[];
Widget build(BuildContext context) {
return Column(
children: [
Text('TextField'),
Text('Interactive view of onChanged, onSubmitted & onEditingComplete'),
Text('Press enter key to trigger onSubmitted & onEditingComplete'),
Text('More: https://stackoverflow.com/questions/63690311/flutter-textfield-difference-between-onedittingcomplete-and-onsubmitted'),
Text(' '),
TextField(
onChanged: (x) => setState(() => onValue.insert(0, "onChanged")),
onSubmitted: (x) => setState(() => onValue.insert(0, "onSubmitted")),
onEditingComplete: () =>
setState(() => onValue.insert(0, "onEditingComplete")),
),
...onValue.map((x) => Text(x)),
],
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment