From f41510dc4e54a8c15c58a4d7ca5ecc5c023b2285 Mon Sep 17 00:00:00 2001 From: Akshay Nair Date: Sun, 21 Jun 2020 23:07:33 +0530 Subject: Implements node focus in/out --- lib/main.dart | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) (limited to 'lib/main.dart') diff --git a/lib/main.dart b/lib/main.dart index fa48706..f7f3c06 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -36,6 +36,9 @@ class MyAppState extends StreamState { stream$: Stream.periodic(Duration(seconds: 1), (_x) => DateTime.now()).asBroadcastStream(), value: DateTime.now(), ); + + FocusNode searchFieldFocus = FocusNode(); + void initState() { super.initState(); @@ -51,6 +54,11 @@ class MyAppState extends StreamState { initStateValue(dateTime); } + void dispose() { + searchFieldFocus.dispose(); + super.dispose(); + } + void openApp(Application app) { DeviceApps.openApp(app.packageName); } @@ -103,8 +111,13 @@ class MyAppState extends StreamState { onWillPop: () => Future.value(false), child: PageView( controller: PageController(keepPage: true), - onPageChanged: (_x) { - SystemChannels.textInput.invokeMethod('TextInput.hide'); + onPageChanged: (x) { + if (x == 1) { + searchFieldFocus.requestFocus(); + } else { + searchFieldFocus.unfocus(); + //SystemChannels.textInput.invokeMethod('TextInput.hide'); + } }, children: [ HomeView( @@ -117,6 +130,7 @@ class MyAppState extends StreamState { appList: applications.value, openApp: openApp, openOptionsMenu: openOptionsMenu, + searchFieldFocus: searchFieldFocus, ), ], ), -- cgit v1.3.1