Created
September 13, 2019 12:22
-
-
Save escamoteur/2d8a43de7c33c151f6bf71b613d753d5 to your computer and use it in GitHub Desktop.
So easy is it now to implement a next field behavior for forms, meaning that the focus is moved as soon the user tabs the next button on the keyboard
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
class _MyHomePageState extends State<MyHomePage> | |
with SingleTickerProviderStateMixin { | |
TabController _tabController; | |
FocusScopeNode _node = FocusScopeNode(); /// <----------------- | |
@override | |
void initState() { | |
_tabController = TabController(length: 3, vsync: this); | |
super.initState(); | |
} | |
@override | |
Widget build(BuildContext context) { | |
// return TestWidget(); | |
return Scaffold( | |
resizeToAvoidBottomPadding: true, | |
appBar: new AppBar( | |
backgroundColor: Colors.white, | |
centerTitle: true, | |
title: new Text("Create Event"), | |
), | |
body: new Center( | |
child: FocusScope( /// <------------- | |
node: _node, /// <------------- | |
child: Column( | |
children: <Widget>[ | |
Expanded( | |
child: SingleChildScrollView( | |
child: Container( | |
padding: | |
EdgeInsets.symmetric(horizontal: 30.0, vertical: 20.0), | |
child: Column( | |
crossAxisAlignment: CrossAxisAlignment.stretch, | |
children: [ | |
TextFormField( | |
onFieldSubmitted: (_) => _node.nextFocus(), //<------------ | |
textInputAction: TextInputAction.next, | |
), | |
TextFormField( | |
onFieldSubmitted: (_) => _node.nextFocus(), //<------------ | |
textInputAction: TextInputAction.next, | |
), | |
TextFormField( | |
onFieldSubmitted: (_) => _node.nextFocus(), //<----------- | |
textInputAction: TextInputAction.next, | |
), | |
// Expanded(child: Container(color: Colors.blue,)), | |
], | |
), | |
), | |
), | |
), | |
Padding( | |
padding: const EdgeInsets.all(8.0), | |
child: TabBar( | |
labelColor: Theme.of(context).accentColor, | |
controller: _tabController, | |
tabs: [ | |
Tab( | |
text: "General", | |
), | |
Tab( | |
text: "Location & Time", | |
), | |
Tab( | |
text: "Requirements", | |
), | |
], | |
), | |
) | |
], | |
), | |
), | |
), | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
thank you my dude