// Copyright 2014 The Flutter Authors. All rights reserved. // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; /// Flutter code sample for [TextFormField]. void main() => runApp(const TextFormFieldExampleApp()); class TextFormFieldExampleApp extends StatelessWidget { const TextFormFieldExampleApp({super.key}); @override Widget build(BuildContext context) { return const MaterialApp(home: TextFormFieldExample()); } } class TextFormFieldExample extends StatefulWidget { const TextFormFieldExample({super.key}); @override State createState() => _TextFormFieldExampleState(); } class _TextFormFieldExampleState extends State { @override Widget build(BuildContext context) { return Material( child: Center( child: Shortcuts( shortcuts: const { // Pressing space in the field will now move to the next field. SingleActivator(LogicalKeyboardKey.space): NextFocusIntent(), }, child: FocusTraversalGroup( child: Form( autovalidateMode: AutovalidateMode.always, onChanged: () { Form.of(primaryFocus!.context!).save(); }, child: Wrap( children: List.generate(5, (int index) { return Padding( padding: const EdgeInsets.all(8.0), child: ConstrainedBox( constraints: BoxConstraints.tight(const Size(200, 50)), child: TextFormField( onSaved: (String? value) { debugPrint('Value for field $index saved as "$value"'); }, ), ), ); }), ), ), ), ), ), ); } }