Auto unfocus to hide IME

This commit is contained in:
Junyuan Feng
2022-01-31 16:26:01 +08:00
parent 86be556a22
commit 5d9b19407f
8 changed files with 45 additions and 50 deletions

View File

@@ -2,8 +2,9 @@
class BuildData {
static const String name = "ServerBox";
static const int build = 85;
static const String engine = "Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 77d935af4d (5 weeks ago) • 2021-12-16 08:37:33 -0800\nEngine • revision 890a5fca2e\nTools • Dart 2.15.1\n";
static const String buildAt = "2022-01-18 13:38:59.083528";
static const int modifications = 1;
static const int build = 86;
static const String engine =
"Flutter 2.8.1 • channel stable • https://github.com/flutter/flutter.git\nFramework • revision 77d935af4d (5 weeks ago) • 2021-12-16 08:37:33 -0800\nEngine • revision 890a5fca2e\nTools • Dart 2.15.1\n";
static const String buildAt = "2022-01-19 16:54:18.470020";
static const int modifications = 0;
}

View File

@@ -6,6 +6,5 @@ class SettingStore extends PersistentStore {
property('primaryColor', defaultValue: Colors.deepPurpleAccent.value);
StoreProperty<int> get serverStatusUpdateInterval =>
property('serverStatusUpdateInterval', defaultValue: 3);
StoreProperty<int> get launchPage =>
property('launchPage', defaultValue: 0);
StoreProperty<int> get launchPage => property('launchPage', defaultValue: 0);
}

View File

@@ -4,6 +4,7 @@ import 'package:clipboard/clipboard.dart';
import 'package:flutter/material.dart';
import 'package:toolbox/core/utils.dart';
import 'package:toolbox/data/res/color.dart';
import 'package:toolbox/view/widget/input_field.dart';
class ConvertPage extends StatefulWidget {
const ConvertPage({Key? key}) : super(key: key);
@@ -82,14 +83,14 @@ class _ConvertPageState extends State<ConvertPage>
case 3:
return Uri.decodeFull(text);
default:
return 'Unknown';
return 'Unknown Convert Method';
}
}
Widget _buildInputTop() {
return SizedBox(
height: _media.size.height * 0.33,
child: _buildInput(_textEditingController),
child: buildInput(context, _textEditingController),
);
}
@@ -161,20 +162,7 @@ class _ConvertPageState extends State<ConvertPage>
Widget _buildResult() {
return SizedBox(
height: _media.size.height * 0.33,
child: _buildInput(_textEditingControllerResult),
);
}
Widget _buildInput(TextEditingController controller) {
return Card(
child: TextField(
maxLines: 20,
decoration: InputDecoration(
fillColor: Theme.of(context).cardColor,
filled: true,
border: InputBorder.none),
controller: controller,
),
child: buildInput(context, _textEditingControllerResult),
);
}

View File

@@ -44,7 +44,15 @@ class _MyHomePageState extends State<MyHomePage>
super.initState();
_serverProvider = locator<ServerProvider>();
WidgetsBinding.instance?.addObserver(this);
_tabController = TabController(initialIndex: locator<SettingStore>().launchPage.fetch()!, length: tabs.length, vsync: this);
_tabController = TabController(
initialIndex: locator<SettingStore>().launchPage.fetch()!,
length: tabs.length,
vsync: this);
_tabController.addListener(() {
if (_tabController.index == 0) {
FocusScope.of(context).unfocus();
}
});
}
@override

View File

@@ -5,6 +5,7 @@ import 'package:dart_ping_ios/dart_ping_ios.dart';
import 'package:flutter/material.dart';
import 'package:toolbox/core/utils.dart';
import 'package:toolbox/data/res/color.dart';
import 'package:toolbox/view/widget/input_field.dart';
class PingPage extends StatefulWidget {
const PingPage({Key? key}) : super(key: key);
@@ -44,9 +45,10 @@ class _PingPageState extends State<PingPage>
padding: const EdgeInsets.symmetric(horizontal: 7),
child: Column(children: [
const SizedBox(height: 13),
_buildInputTop(),
buildInput(context, _textEditingController,
maxLines: 1, hint: 'Type here.'),
_buildControl(),
_buildResult(),
buildInput(context, _textEditingControllerResult, hint: 'Result here.'),
])),
onTap: () => FocusScope.of(context).requestFocus(FocusNode()),
),
@@ -68,7 +70,9 @@ class _PingPageState extends State<PingPage>
return SizedBox(
height: 57,
child: Card(
child: Row(
child: InkWell(
onTap: () => FocusScope.of(context).unfocus(),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
TextButton(
@@ -109,28 +113,7 @@ class _PingPageState extends State<PingPage>
)
],
),
),
);
}
Widget _buildInputTop() {
return _buildInput(_textEditingController, maxLines: 1, hint: 'Type here.');
}
Widget _buildResult() {
return _buildInput(_textEditingControllerResult, hint: 'Result here.');
}
Widget _buildInput(TextEditingController controller, {int maxLines = 20, String? hint}) {
return Card(
child: TextField(
maxLines: maxLines,
decoration: InputDecoration(
fillColor: Theme.of(context).cardColor,
hintText: hint,
filled: true,
border: InputBorder.none),
controller: controller,
),
),
);
}

View File

@@ -204,7 +204,7 @@ class _SettingPageState extends State<SettingPage> {
title: Text(
e,
style: TextStyle(
fontSize: 14,
fontSize: 14,
color: _theme.textTheme.bodyText2!.color!.withAlpha(177)),
),
trailing: _buildRadio(tabs.indexOf(e)),

View File

@@ -0,0 +1,16 @@
import 'package:flutter/material.dart';
Widget buildInput(BuildContext context, TextEditingController controller,
{int maxLines = 20, String? hint}) {
return Card(
child: TextField(
maxLines: maxLines,
decoration: InputDecoration(
fillColor: Theme.of(context).cardColor,
hintText: hint,
filled: true,
border: InputBorder.none),
controller: controller,
),
);
}