Skip to content

Commit

Permalink
perf(startup): ⚡ #12 Optimize startup speed
Browse files Browse the repository at this point in the history
  • Loading branch information
ys1231 committed Nov 18, 2024
1 parent 1cb9125 commit d82d775
Show file tree
Hide file tree
Showing 5 changed files with 46 additions and 47 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
## 项目简介

1. 基于flutter和[tun2socks](https://github.com/xjasonlyu/tun2socks)开发.
2. [appproxy](https://github.com/ys1231/appproxy) 是一个轻量级的VPN代理工具,支持HTTP, SOCKS5协议
2. [appproxy](https://github.com/ys1231/appproxy) 是一个轻量级的VPN代理工具,支持HTTP, SOCKS5协议.
3. 功能单只做代理,可分app代理, **_双击修改配置_** 逻辑比较简单, 主打一个能用就行.
4. 出于学习熟悉flutter的目的去做的,分享给大家,顺便帮我测试一下.
5. 加上[MoveCertificate](https://github.com/ys1231/MoveCertificate) 上下游都有了哈哈.
Expand All @@ -35,6 +35,7 @@
```shell
# 如果发现Android Studio 调试flutter 自动跳到一个只读的文件,调试的时候无法修改代码,可以恢复上一个版本,是的坑.
# 推荐 Android Studio Iguana | 2023.2.1 Patch 2
# line 设置为 100
flutter build apk --release --split-per-abi --build-name=$VERSION --obfuscate --split-debug-info ./build/
```

Expand Down
1 change: 0 additions & 1 deletion lib/events/app_events.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import 'dart:convert';

import 'package:event_bus/event_bus.dart';
import 'package:flutter/foundation.dart';

// 创建一个全局的EventBus实例
Expand Down
31 changes: 24 additions & 7 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,18 +24,16 @@ class MyApp extends StatelessWidget {
*/
return MaterialApp(
// 应用标题
title: 'iyue Flutter',
title: "appproxy",
// 在调试模式下打开一个小“DEBUG”横幅,以指示应用程序处于调试模式。默认情况下(在调试模式下)处于打开状态,要将其关闭,请将构造函数参数设置为 false。在发布模式下这没有任何效果
debugShowCheckedModeBanner: true,
localeResolutionCallback:
(Locale? locale, Iterable<Locale> supportedLocales) {
var result = supportedLocales
.where((element) => element.languageCode == locale?.languageCode);
localeResolutionCallback: (Locale? locale, Iterable<Locale> supportedLocales) {
var result =
supportedLocales.where((element) => element.languageCode == locale?.languageCode);
if (result.isNotEmpty) {
debugPrint(locale?.languageCode);
if (locale.toString().contains("zh")) {
return const Locale('zh', 'CN');
;
} else {
return const Locale('en', 'US');
}
Expand Down Expand Up @@ -87,7 +85,26 @@ class _iyueMainPageState extends State<iyueMainPage> {
// 首页Widget
const ProxyListHome(),
// app配置列表
const AppConfigList(),
FutureBuilder(
// 先启动后加载
future: Future.delayed(const Duration(seconds: 1)),
builder: (BuildContext context, AsyncSnapshot<dynamic> snapshot) {
// 当计算状态为等待时,显示加载动画
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(
// 显示一个加载动画
child: CircularProgressIndicator(),
);
} else if (snapshot.hasError) {
// 当 future 出现错误时,显示错误信息
return Center(
child: Text('Error: ${snapshot.error}'),
);
} else {
// 当计算完成时,显示app配置列表
return const AppConfigList();
}
}),
// 设置页面
const AppSettings(), // 设置页Widget
];
Expand Down
56 changes: 19 additions & 37 deletions lib/ui/app_config_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ class AppConfigState extends State<AppConfigList> {
void initState() {
super.initState();
debugPrint("iyue-> initState");
_initData().then((value) => null);
_initData();
}

// 初始化数据
Expand Down Expand Up @@ -201,18 +201,14 @@ class AppConfigState extends State<AppConfigList> {
if (searchText.isNotEmpty) {
_searchAppListInfo = _jsonAppListInfo.where((itemMap) {
final label =
PinyinHelper.getShortPinyin(itemMap["label"]).toLowerCase() +
itemMap["packageName"];
PinyinHelper.getShortPinyin(itemMap["label"]).toLowerCase() + itemMap["packageName"];
final search = searchText.toLowerCase();
return label.startsWith(search) ||
label.startsWith(search) ||
label.contains(search);
return label.startsWith(search) || label.startsWith(search) || label.contains(search);
}).toList();
}
if (_searchAppListInfo.isNotEmpty) {
// _searchAppListInfo = _jsonAppListInfo;
debugPrint(
"searchApp:${_searchAppListInfo.length} , all: $_searchAppListInfo");
debugPrint("searchApp:${_searchAppListInfo.length} , all: $_searchAppListInfo");
} else {
_searchAppListInfo = _jsonAppListInfo.toList();
}
Expand All @@ -238,9 +234,7 @@ class AppConfigState extends State<AppConfigList> {
backgroundColor: Theme.of(context).primaryColor,
actions: <Widget>[
AnimatedCrossFade(
crossFadeState: _showSearch
? CrossFadeState.showSecond
: CrossFadeState.showFirst,
crossFadeState: _showSearch ? CrossFadeState.showSecond : CrossFadeState.showFirst,
firstChild: IconButton(
key: const ValueKey(1),
autofocus: true,
Expand All @@ -252,8 +246,7 @@ class AppConfigState extends State<AppConfigList> {
_searchController.clear();
_searchApp("");
Future.delayed(const Duration(milliseconds: 100), () {
FocusScope.of(context)
.requestFocus(_searchFocusNode);
FocusScope.of(context).requestFocus(_searchFocusNode);
});
}
});
Expand Down Expand Up @@ -346,8 +339,7 @@ class AppConfigState extends State<AppConfigList> {
} else {
// 够建用于调用子控件CheckBox的key
_cardKeys.clear();
_cardKeys = List.generate(
_itemCount, (index) => GlobalKey<CardCheckboxState>());
_cardKeys = List.generate(_itemCount, (index) => GlobalKey<CardCheckboxState>());
// 带刷新的动态列表
return RefreshIndicator(
onRefresh: () {
Expand All @@ -367,29 +359,25 @@ class AppConfigState extends State<AppConfigList> {
// 创建从边缘反弹的滚动物理效果。
physics: const BouncingScrollPhysics(),
// 返回一个零尺寸的SizedBox
separatorBuilder: (BuildContext context, int index) =>
const SizedBox.shrink(),
separatorBuilder: (BuildContext context, int index) => const SizedBox.shrink(),
// 列表项数量
itemCount:
_showSearch ? _searchAppListInfo.length : _itemCount,
itemCount: _showSearch ? _searchAppListInfo.length : _itemCount,
// 列表项构建器
itemBuilder: (BuildContext context, int c_index) {
Map<String, dynamic> itemMap = _showSearch
? _searchAppListInfo[c_index]
: _jsonAppListInfo[c_index];
Map<String, dynamic> itemMap =
_showSearch ? _searchAppListInfo[c_index] : _jsonAppListInfo[c_index];
// 返回一个卡片
return Card(
margin: const EdgeInsets.symmetric(
horizontal: 10.0, vertical: 3.0),
margin: const EdgeInsets.symmetric(horizontal: 10.0, vertical: 3.0),
key: ValueKey(c_index),
// 列表项内容
child: ListTile(
// 设置水平标题间距
horizontalTitleGap: 20,
// textColor:Colors.deepOrangeAccent,
// 设置内容内边距
contentPadding: const EdgeInsets.symmetric(
vertical: 0.0, horizontal: 16.0),
contentPadding:
const EdgeInsets.symmetric(vertical: 0.0, horizontal: 16.0),
// 显示一个图标icon
leading: SizedBox(
width: 38, // 设置宽度
Expand All @@ -407,23 +395,18 @@ class AppConfigState extends State<AppConfigList> {
trailing: CardCheckbox(
key: _cardKeys[c_index],
// 根据是否选中列表初始化状态
isSelected:
_selectedItemsMap[itemMap["packageName"]] ??
false,
isSelected: _selectedItemsMap[itemMap["packageName"]] ?? false,
// 子控件回调这个函数更新界面对应的数据
callbackOnChanged: (newValue) {
// 如果选中了,添加到代理列表
_selectedItemsMap[itemMap["packageName"]] =
newValue;
_selectedItemsMap[itemMap["packageName"]] = newValue;
// 并且更新本地数据
_appfile.saveAppConfig(_selectedItemsMap);
if (newValue) {
// 添加到代理列表
appProxyPackageList
.add(itemMap["packageName"]);
appProxyPackageList.add(itemMap["packageName"]);
} else {
appProxyPackageList
.remove(itemMap["packageName"]);
appProxyPackageList.remove(itemMap["packageName"]);
}
}),
onTap: () {
Expand All @@ -443,8 +426,7 @@ class AppConfigState extends State<AppConfigList> {
}

class CardCheckbox extends StatefulWidget {
CardCheckbox(
{super.key, required this.isSelected, required this.callbackOnChanged});
CardCheckbox({super.key, required this.isSelected, required this.callbackOnChanged});

// 构造函数
Function(bool) callbackOnChanged;
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
# In Windows, build-name is used as the major, minor, and patch parts
# of the product and file versions while build-number is used as the build suffix.
version: 0.0.5+5
version: 0.0.8+8

environment:
sdk: '>=3.3.1 <4.0.0'
Expand Down

0 comments on commit d82d775

Please sign in to comment.