From a6ffe45651d84ba7ed61966e0d918e85a2c531da Mon Sep 17 00:00:00 2001 From: Dain Nilsson Date: Thu, 10 Feb 2022 11:20:21 +0100 Subject: [PATCH] Search field: Jump to first result on Enter/Down. --- lib/app/views/main_page.dart | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) diff --git a/lib/app/views/main_page.dart b/lib/app/views/main_page.dart index 27c4bf8f..9c47f471 100755 --- a/lib/app/views/main_page.dart +++ b/lib/app/views/main_page.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'device_avatar.dart'; @@ -67,14 +68,30 @@ class MainPage extends ConsumerWidget { width: 8, color: Theme.of(context).scaffoldBackgroundColor), ), */ - title: TextField( - decoration: const InputDecoration( - hintText: 'Search...', - border: InputBorder.none, - ), - onChanged: (value) { - ref.read(searchProvider.notifier).setFilter(value); + title: Focus( + canRequestFocus: false, + onKeyEvent: (node, event) { + if (event.logicalKey == LogicalKeyboardKey.arrowDown) { + node.focusInDirection(TraversalDirection.down); + return KeyEventResult.handled; + } + return KeyEventResult.ignored; }, + child: Builder(builder: (context) { + return TextField( + decoration: const InputDecoration( + hintText: 'Search...', + border: InputBorder.none, + ), + onChanged: (value) { + ref.read(searchProvider.notifier).setFilter(value); + }, + textInputAction: TextInputAction.next, + onSubmitted: (value) { + Focus.of(context).focusInDirection(TraversalDirection.down); + }, + ); + }), ), actions: [ Padding(