Android TV support - search screen

This commit is contained in:
kilowatt 2020-11-01 00:04:27 +03:00
parent f91fe8f216
commit daee0c03e0

View File

@ -1,5 +1,6 @@
import 'package:connectivity/connectivity.dart'; import 'package:connectivity/connectivity.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/src/services/keyboard_key.dart';
import 'package:freezer/api/cache.dart'; import 'package:freezer/api/cache.dart';
import 'package:freezer/api/download.dart'; import 'package:freezer/api/download.dart';
import 'package:freezer/api/player.dart'; import 'package:freezer/api/player.dart';
@ -121,6 +122,7 @@ class _SearchScreenState extends State<SearchScreen> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
var textFielFocusNode = FocusNode();
return Scaffold( return Scaffold(
appBar: FreezerAppBar('Search'.i18n), appBar: FreezerAppBar('Search'.i18n),
body: ListView( body: ListView(
@ -134,24 +136,36 @@ class _SearchScreenState extends State<SearchScreen> {
child: Stack( child: Stack(
alignment: Alignment(1.0, 0.0), alignment: Alignment(1.0, 0.0),
children: [ children: [
TextField( RawKeyboardListener(
onChanged: (String s) { focusNode: FocusNode(),
setState(() => _query = s); onKey: (event) { // For Android TV: quit search textfield
_loadSuggestions(); if (event.runtimeType.toString() == 'RawKeyUpEvent') {
}, LogicalKeyboardKey key = event.data.logicalKey;
decoration: InputDecoration( if (key == LogicalKeyboardKey.arrowDown) {
labelText: 'Search or paste URL'.i18n, textFielFocusNode.unfocus();
fillColor: Theme.of(context).bottomAppBarColor, }
filled: true, }
focusedBorder: OutlineInputBorder( },
borderSide: BorderSide(color: Colors.grey) child: TextField(
), onChanged: (String s) {
enabledBorder: OutlineInputBorder( setState(() => _query = s);
borderSide: BorderSide(color: Colors.grey) _loadSuggestions();
), },
), focusNode: textFielFocusNode,
controller: _controller, decoration: InputDecoration(
onSubmitted: (String s) => _submit(context, query: s), labelText: 'Search or paste URL'.i18n,
fillColor: Theme.of(context).bottomAppBarColor,
filled: true,
focusedBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey)
),
enabledBorder: OutlineInputBorder(
borderSide: BorderSide(color: Colors.grey)
),
),
controller: _controller,
onSubmitted: (String s) => _submit(context, query: s),
)
), ),
Row( Row(
mainAxisSize: MainAxisSize.min, mainAxisSize: MainAxisSize.min,