Skip to content

Instantly share code, notes, and snippets.

@shaxxx
Forked from escamoteur/nextField.dart
Created September 16, 2019 07:30
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save shaxxx/ce6a4c9fc7100598cded4202c8f3ad48 to your computer and use it in GitHub Desktop.
Save shaxxx/ce6a4c9fc7100598cded4202c8f3ad48 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
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