I have a working Flutter application with simple registration form. I tried to install this in Android TV. And able to see it is running with TV related configurations in android manifest.
The button is not clickable even after providing the focus. Following is the scenario. My form elements as shown in the below order.
- --(Name)TextFormField--
- --(Age)TextFormField--
- --(Submit)FlatButton--
From TV remote, using dpat, I have navigated like below.
- Navigated to Name, clicked on next button from soft keyboard.
- Age filed focused with keyboard, clicked on done button from soft keyboard.
- Submit focused. And when i clicked it is working fine.
- Using remote d-pad hit up button. Focus moved back to Age fields and did some change in it.
- Again clicked on done button and. Focus moved back to Submit button.
- Now click on submit button do nothing. (NOT WORKING HERE)
What can I do about focus/selection failures?
Attaching the minimal reproducible code. This code has to be executed in android TV emulator or real Android TV after manifest configuration changes.
Code:
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Shortcuts(
shortcuts: <LogicalKeySet, Intent>{
LogicalKeySet(LogicalKeyboardKey.select): ActivateIntent(),
},
child: MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage();
@override
_MyAppState createState() => _MyAppState();
}
class _MyAppState extends State<MyHomePage> {
FocusNode fname = FocusNode();
FocusNode age = FocusNode();
FocusNode submit = FocusNode();
@override
void initState() {
super.initState();
}
@override
void dispose() {
fname.dispose();
age.dispose();
submit.dispose();
super.dispose();
}
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Focus Node',
home: Scaffold(
appBar: AppBar(
title: Text('Focus Node'),
centerTitle: true,
),
body: Padding(
padding: const EdgeInsets.all(16.0),
child: SingleChildScrollView(
child: Column(
children: [
Text(
'Personal',
style: TextStyle(
fontSize: 40.0,
fontWeight: FontWeight.w800,
color: Colors.indigoAccent,
),
),
TextFormField(
autofocus: true,
focusNode: fname,
keyboardType: TextInputType.text,
enabled: true,
textInputAction: TextInputAction.next,
decoration: InputDecoration(
labelText: 'First Name',
hintText: 'Enter your first name',
border: OutlineInputBorder(
borderSide: BorderSide(color: Colors.teal),
),
),
onFieldSubmitted: (term) {
fname.unfocus();
FocusScope.of(context).requestFocus(age);
},
),
SizedBox(
height: 10,
),
TextFormField(
focusNode: age,
enabled: true,
keyboardType: TextInputType.text,
textInputAction: TextInputAction.done,
decoration: InputDecoration(
labelText: 'Age',
hintText: 'Enter your age',
border: OutlineInputBorder(
borderSide: BorderSide(color: Colors.teal),
),
),
onFieldSubmitted: (term) {
print('focus is -==========${submit.canRequestFocus} ');
age.unfocus();
FocusScope.of(context).requestFocus(submit);
},
),
SizedBox(
height: 10,
),
FlatButton(
autofocus: true,
focusColor: Colors.green,
focusNode: submit,
onPressed: () {
print('Submit clicked');
},
child: Text('Submit'),
color: Colors.lightBlueAccent,
),
],
),
),
)),
);
}
}