From 87ab88dcaa137bfb40c639d23909d1d8cd5b027c Mon Sep 17 00:00:00 2001 From: poppingmoon <63451158+poppingmoon@users.noreply.github.com> Date: Sun, 3 Sep 2023 20:18:18 +0900 Subject: [PATCH] =?UTF-8?q?=E6=A4=9C=E7=B4=A2=E7=94=BB=E9=9D=A2=E3=81=A7?= =?UTF-8?q?=E3=82=BF=E3=83=96=E5=A4=89=E6=9B=B4=E6=99=82=E3=81=AB=E3=83=95?= =?UTF-8?q?=E3=82=A9=E3=83=BC=E3=82=AB=E3=82=B9=E3=82=92=E5=88=87=E3=82=8A?= =?UTF-8?q?=E6=9B=BF=E3=81=88=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- lib/view/search_page/note_search.dart | 8 ++- lib/view/search_page/search_page.dart | 82 ++++++++++++++++++++------- lib/view/user_select_dialog.dart | 9 ++- 3 files changed, 77 insertions(+), 22 deletions(-) diff --git a/lib/view/search_page/note_search.dart b/lib/view/search_page/note_search.dart index 9bf7a5c93..9e1108605 100644 --- a/lib/view/search_page/note_search.dart +++ b/lib/view/search_page/note_search.dart @@ -13,8 +13,13 @@ import 'package:misskey_dart/misskey_dart.dart'; class NoteSearch extends ConsumerStatefulWidget { final String? initialSearchText; + final FocusNode? focusNode; - const NoteSearch({super.key, required this.initialSearchText}); + const NoteSearch({ + super.key, + required this.initialSearchText, + this.focusNode, + }); @override ConsumerState createState() => NoteSearchState(); @@ -52,6 +57,7 @@ class NoteSearchState extends ConsumerState { decoration: const InputDecoration( prefixIcon: Icon(Icons.search), ), + focusNode: widget.focusNode, autofocus: true, textInputAction: TextInputAction.done, onSubmitted: (value) { diff --git a/lib/view/search_page/search_page.dart b/lib/view/search_page/search_page.dart index 72ff57289..652deaf3e 100644 --- a/lib/view/search_page/search_page.dart +++ b/lib/view/search_page/search_page.dart @@ -31,34 +31,76 @@ class SearchPage extends ConsumerStatefulWidget { } class NoteSearchPageState extends ConsumerState { + late final List focusNodes; + int tabIndex = 0; + + @override + void initState() { + super.initState(); + focusNodes = [FocusNode(), FocusNode()]; + } + + @override + void dispose() { + for (final focusNode in focusNodes) { + focusNode.dispose(); + } + super.dispose(); + } + @override Widget build(BuildContext context) { return DefaultTabController( length: 2, child: AccountScope( - account: widget.account, - child: Scaffold( - appBar: AppBar( - title: const Text("検索"), - bottom: const TabBar( - tabs: [ - Tab(text: "ノート"), - Tab(text: "ユーザー"), - ], - ), - ), - body: TabBarView( + account: widget.account, + child: Scaffold( + appBar: AppBar( + title: const Text("検索"), + bottom: const TabBar( + tabs: [ + Tab(text: "ノート"), + Tab(text: "ユーザー"), + ], + ), + ), + body: Builder( + builder: (context) { + final tabController = DefaultTabController.of(context); + tabController.addListener(() { + if (tabController.index != tabIndex) { + focusNodes[tabController.index].requestFocus(); + setState(() { + tabIndex = tabController.index; + }); + } + }); + return TabBarView( + controller: tabController, children: [ - NoteSearch(initialSearchText: widget.initialSearchText), + NoteSearch( + initialSearchText: widget.initialSearchText, + focusNode: focusNodes[0], + ), Padding( - padding: - const EdgeInsets.only(left: 10, right: 10, top: 10), - child: UserSelectContent( - onSelected: (item) => context.pushRoute(UserRoute( - userId: item.id, account: widget.account)), - )) + padding: + const EdgeInsets.only(left: 10, right: 10, top: 10), + child: UserSelectContent( + focusNode: focusNodes[1], + onSelected: (item) => context.pushRoute( + UserRoute( + userId: item.id, + account: widget.account, + ), + ), + ), + ), ], - ))), + ); + }, + ), + ), + ), ); } } diff --git a/lib/view/user_select_dialog.dart b/lib/view/user_select_dialog.dart index 8cbeeb570..fff251c83 100644 --- a/lib/view/user_select_dialog.dart +++ b/lib/view/user_select_dialog.dart @@ -31,7 +31,13 @@ class UserSelectDialog extends StatelessWidget { class UserSelectContent extends ConsumerStatefulWidget { final void Function(User) onSelected; - const UserSelectContent({super.key, required this.onSelected}); + final FocusNode? focusNode; + + const UserSelectContent({ + super.key, + required this.onSelected, + this.focusNode, + }); @override ConsumerState createState() => @@ -55,6 +61,7 @@ class UserSelectContentState extends ConsumerState { children: [ TextField( controller: queryController, + focusNode: widget.focusNode, autofocus: true, decoration: const InputDecoration(prefixIcon: Icon(Icons.search)), onSubmitted: (value) {