优化Android返回键体验

This commit is contained in:
jyuesong
2022-01-19 15:54:06 +08:00
parent 346ebd68cf
commit 4fe730d414
4 changed files with 54 additions and 45 deletions

View File

@@ -4,6 +4,7 @@
* 增加环境变量详情页 * 增加环境变量详情页
* 环境变量列表使用体验优化 * 环境变量列表使用体验优化
* 部分页面进入卡顿优化 * 部分页面进入卡顿优化
* 扩大任务的搜索范围
## 1.0.0 ## 1.0.0

View File

@@ -1,5 +1,6 @@
import 'package:flutter/cupertino.dart'; import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:qinglong_app/base/ql_app_bar.dart'; import 'package:qinglong_app/base/ql_app_bar.dart';
import 'package:qinglong_app/base/routes.dart'; import 'package:qinglong_app/base/routes.dart';
@@ -7,6 +8,7 @@ import 'package:qinglong_app/module/config/config_page.dart';
import 'package:qinglong_app/module/env/env_page.dart'; import 'package:qinglong_app/module/env/env_page.dart';
import 'package:qinglong_app/module/others/other_page.dart'; import 'package:qinglong_app/module/others/other_page.dart';
import 'package:qinglong_app/module/task/task_page.dart'; import 'package:qinglong_app/module/task/task_page.dart';
import 'package:move_to_background/move_to_background.dart';
class HomePage extends ConsumerStatefulWidget { class HomePage extends ConsumerStatefulWidget {
const HomePage({Key? key}) : super(key: key); const HomePage({Key? key}) : super(key: key);
@@ -100,48 +102,54 @@ class _HomePageState extends ConsumerState<HomePage> {
)); ));
} }
return Scaffold( return WillPopScope(
appBar: QlAppBar( onWillPop: () async {
canBack: false, await MoveToBackground.moveTaskToBack();
title: _title, return false;
actions: actions, },
), child: Scaffold(
body: IndexedStack( appBar: QlAppBar(
index: _index, canBack: false,
children: [ title: _title,
const Positioned.fill( actions: actions,
child: TaskPage(), ),
), body: IndexedStack(
const Positioned.fill( index: _index,
child: EnvPage(), children: [
), const Positioned.fill(
Positioned.fill( child: TaskPage(),
child: ConfigPage(
key: configKey,
), ),
), const Positioned.fill(
const Positioned.fill( child: EnvPage(),
child: OtherPage(), ),
), Positioned.fill(
], child: ConfigPage(
), key: configKey,
bottomNavigationBar: BottomNavigationBar(
items: titles
.map(
(e) => BottomNavigationBarItem(
icon: Icon(e.icon),
activeIcon: Icon(e.checkedIcon),
label: e.title,
), ),
) ),
.toList(), const Positioned.fill(
currentIndex: _index, child: OtherPage(),
onTap: (index) { ),
_index = index; ],
_title = titles[index].title; ),
setState(() {}); bottomNavigationBar: BottomNavigationBar(
}, items: titles
type: BottomNavigationBarType.fixed, .map(
(e) => BottomNavigationBarItem(
icon: Icon(e.icon),
activeIcon: Icon(e.checkedIcon),
label: e.title,
),
)
.toList(),
currentIndex: _index,
onTap: (index) {
_index = index;
_title = titles[index].title;
setState(() {});
},
type: BottomNavigationBarType.fixed,
),
), ),
); );
} }

View File

@@ -23,7 +23,6 @@ class TaskPage extends StatefulWidget {
} }
class _TaskPageState extends State<TaskPage> { class _TaskPageState extends State<TaskPage> {
String? _searchKey;
final TextEditingController _searchController = TextEditingController(); final TextEditingController _searchController = TextEditingController();
@override @override
@@ -102,9 +101,9 @@ class _TaskPageState extends State<TaskPage> {
TaskBean item = list[index]; TaskBean item = list[index];
if (_searchController.text.isEmpty || if (_searchController.text.isEmpty ||
(item.name?.contains(_searchController.text) ?? false) || (item.name?.toLowerCase().contains(_searchController.text.toLowerCase()) ?? false) ||
(item.command?.contains(_searchController.text) ?? false) || (item.command?.toLowerCase().contains(_searchController.text.toLowerCase()) ?? false) ||
(item.schedule?.contains(_searchController.text) ?? false)) { (item.schedule?.contains(_searchController.text.toLowerCase()) ?? false)) {
return TaskItemCell(item, ref); return TaskItemCell(item, ref);
} else { } else {
return const SizedBox.shrink(); return const SizedBox.shrink();
@@ -162,7 +161,7 @@ class TaskItemCell extends StatelessWidget {
final TaskBean bean; final TaskBean bean;
final WidgetRef ref; final WidgetRef ref;
TaskItemCell(this.bean, this.ref, {Key? key}) : super(key: key); const TaskItemCell(this.bean, this.ref, {Key? key}) : super(key: key);
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {

View File

@@ -26,6 +26,7 @@ dependencies:
flutter_highlight: ^0.7.0 flutter_highlight: ^0.7.0
drag_and_drop_lists: ^0.3.2+2 drag_and_drop_lists: ^0.3.2+2
fluttertoast: ^8.0.8 fluttertoast: ^8.0.8
move_to_background: ^1.0.2
dev_dependencies: dev_dependencies:
flutter_native_splash: ^1.3.3 flutter_native_splash: ^1.3.3