I would like to focus on a DropdownButtonFormField from a TextFormField in Form using FocusScope.of(context).nextFocus()
or FocusScope.of(context).requestFocus(_myNextNode)
.
The problem is that DropdownButtonFormField does not provide focusNode
attribute.
I saw that focusNode
is available in DropdownButton yet.
SampleApp code :
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'ListeTile Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: HomeScreen(),
);
}
}
class HomeScreen extends StatefulWidget {
@override
HomeScreenState createState() {
return HomeScreenState();
}
}
class HomeScreenState extends State<HomeScreen> {
var _formKey = GlobalKey<FormState>();
String dropdownValue = 'One';
@override
Widget build(BuildContext context) {
return DefaultTabController(
length: 3,
child: Scaffold(
appBar: AppBar(),
body: Form(
key: _formKey,
child: Column(children: <Widget>[
TextFormField(
onFieldSubmitted: (_) => FocusScope.of(context).nextFocus(),
),
DropdownButtonFormField(
value: dropdownValue,
items: <String>['One', 'Two', 'Free', 'Four']
.map<DropdownMenuItem<String>>((String value) {
return DropdownMenuItem<String>(
value: value,
child: Text(value),
);
}).toList(),
onChanged: (String newValue) {
setState(() {
dropdownValue = newValue;
});
},
)
])),
),
);
}
}
Do you know how to do it?