Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
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",
),
],
),
)
],
),
),
),
);
}
}
@giuliano-oliveira

This comment has been minimized.

Copy link

@giuliano-oliveira giuliano-oliveira commented May 14, 2020

thank you my dude

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment