Skip to content

Commit de9c5ba

Browse files
committed
Optimize dashboard performance
Fix some issues
1 parent 2aae00c commit de9c5ba

File tree

19 files changed

+626
-171
lines changed

19 files changed

+626
-171
lines changed

lib/clash/core.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -235,12 +235,12 @@ class ClashCore {
235235
return int.parse(value);
236236
}
237237

238-
Future<ClashConfig?> getProfile(String id) async {
238+
Future<ClashConfigSnippet?> getProfile(String id) async {
239239
final res = await clashInterface.getProfile(id);
240240
if (res.isEmpty) {
241241
return null;
242242
}
243-
return ClashConfig.fromJson(json.decode(res));
243+
return ClashConfigSnippet.fromJson(json.decode(res));
244244
}
245245

246246
resetTraffic() {

lib/common/navigation.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@ class Navigation {
1414
const NavigationItem(
1515
icon: Icon(Icons.space_dashboard),
1616
label: PageLabel.dashboard,
17+
keep: false,
1718
fragment: DashboardFragment(
1819
key: GlobalObjectKey(PageLabel.dashboard),
1920
),

lib/common/render.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ class Render {
2525
debouncer.call(
2626
DebounceTag.renderPause,
2727
_pause,
28-
duration: Duration(seconds: 15),
28+
duration: Duration(seconds: 5),
2929
);
3030
}
3131

lib/fragments/dashboard/widgets/memory_info.dart

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -62,12 +62,12 @@ class _MemoryInfoState extends State<MemoryInfo> {
6262
onPressed: () {
6363
clashCore.requestGc();
6464
},
65-
child: ValueListenableBuilder(
66-
valueListenable: _memoryInfoStateNotifier,
67-
builder: (_, trafficValue, __) {
68-
return Column(
69-
children: [
70-
Padding(
65+
child: Column(
66+
children: [
67+
ValueListenableBuilder(
68+
valueListenable: _memoryInfoStateNotifier,
69+
builder: (_, trafficValue, __) {
70+
return Padding(
7171
padding: baseInfoEdgeInsets.copyWith(
7272
bottom: 0,
7373
top: 12,
@@ -87,30 +87,30 @@ class _MemoryInfoState extends State<MemoryInfo> {
8787
)
8888
],
8989
),
90-
),
91-
Flexible(
92-
child: Stack(
93-
children: [
94-
Positioned.fill(
95-
child: WaveView(
96-
waveAmplitude: 12.0,
97-
waveFrequency: 0.35,
98-
waveColor: darkenLighter,
99-
),
100-
),
101-
Positioned.fill(
102-
child: WaveView(
103-
waveAmplitude: 12.0,
104-
waveFrequency: 0.9,
105-
waveColor: darken,
106-
),
107-
),
108-
],
90+
);
91+
},
92+
),
93+
Flexible(
94+
child: Stack(
95+
children: [
96+
Positioned.fill(
97+
child: WaveView(
98+
waveAmplitude: 12.0,
99+
waveFrequency: 0.35,
100+
waveColor: darkenLighter,
101+
),
102+
),
103+
Positioned.fill(
104+
child: WaveView(
105+
waveAmplitude: 12.0,
106+
waveFrequency: 0.9,
107+
waveColor: darken,
108+
),
109109
),
110-
)
111-
],
112-
);
113-
},
110+
],
111+
),
112+
),
113+
],
114114
),
115115
),
116116
);

lib/fragments/dashboard/widgets/traffic_usage.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
1111
class TrafficUsage extends StatelessWidget {
1212
const TrafficUsage({super.key});
1313

14-
Widget getTrafficDataItem(
14+
Widget _buildTrafficDataItem(
1515
BuildContext context,
1616
Icon icon,
1717
TrafficValue trafficValue,
@@ -189,7 +189,7 @@ class TrafficUsage extends StatelessWidget {
189189
),
190190
),
191191
),
192-
getTrafficDataItem(
192+
_buildTrafficDataItem(
193193
context,
194194
Icon(
195195
Icons.arrow_upward,
@@ -201,7 +201,7 @@ class TrafficUsage extends StatelessWidget {
201201
const SizedBox(
202202
height: 8,
203203
),
204-
getTrafficDataItem(
204+
_buildTrafficDataItem(
205205
context,
206206
Icon(
207207
Icons.arrow_downward,

lib/fragments/profiles/custom_profile.dart

Lines changed: 0 additions & 54 deletions
This file was deleted.
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
import 'package:fl_clash/clash/core.dart';
2+
import 'package:fl_clash/models/models.dart';
3+
import 'package:fl_clash/state.dart';
4+
import 'package:fl_clash/widgets/card.dart';
5+
import 'package:fl_clash/widgets/scaffold.dart';
6+
import 'package:flutter/material.dart';
7+
8+
class GenProfile extends StatefulWidget {
9+
final String profileId;
10+
11+
const GenProfile({
12+
super.key,
13+
required this.profileId,
14+
});
15+
16+
@override
17+
State<GenProfile> createState() => _GenProfileState();
18+
}
19+
20+
class _GenProfileState extends State<GenProfile> {
21+
final _currentClashConfigNotifier = ValueNotifier<ClashConfigSnippet?>(null);
22+
23+
@override
24+
void initState() {
25+
super.initState();
26+
_initCurrentClashConfig();
27+
}
28+
29+
_initCurrentClashConfig() async {
30+
final currentProfileId = globalState.config.currentProfileId;
31+
if (currentProfileId == null) {
32+
return;
33+
}
34+
_currentClashConfigNotifier.value =
35+
await clashCore.getProfile(currentProfileId);
36+
}
37+
38+
@override
39+
Widget build(BuildContext context) {
40+
return CommonScaffold(
41+
body: ValueListenableBuilder(
42+
valueListenable: _currentClashConfigNotifier,
43+
builder: (_, clashConfig, ___) {
44+
if (clashConfig == null) {
45+
return Center(
46+
child: CircularProgressIndicator(),
47+
);
48+
}
49+
return Padding(
50+
padding: EdgeInsets.all(16),
51+
child: CustomScrollView(
52+
slivers: [
53+
SliverGrid.builder(
54+
gridDelegate: SliverGridDelegateWithMaxCrossAxisExtent(
55+
maxCrossAxisExtent: 100,
56+
mainAxisExtent: 50,
57+
mainAxisSpacing: 8,
58+
crossAxisSpacing: 8,
59+
),
60+
itemCount: clashConfig.proxyGroups.length,
61+
itemBuilder: (BuildContext context, int index) {
62+
return CommonCard(
63+
onPressed: () {},
64+
child: Text(
65+
clashConfig.proxyGroups[index].name,
66+
),
67+
);
68+
},
69+
),
70+
SliverList.builder(
71+
itemBuilder: (BuildContext context, int index) {
72+
final rule = clashConfig.rule[index];
73+
return Text(
74+
rule,
75+
);
76+
},
77+
itemCount: clashConfig.rule.length,
78+
)
79+
],
80+
),
81+
);
82+
},
83+
),
84+
title: "自定义",
85+
);
86+
}
87+
}

lib/fragments/profiles/profiles.dart

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import 'package:flutter/material.dart';
1111
import 'package:flutter_riverpod/flutter_riverpod.dart';
1212

1313
import 'add_profile.dart';
14+
import 'gen_profile.dart';
1415

1516
class ProfilesFragment extends StatefulWidget {
1617
const ProfilesFragment({super.key});
@@ -273,14 +274,14 @@ class ProfileItem extends StatelessWidget {
273274
}
274275
}
275276

276-
// _handlePushCustomPage(BuildContext context, String id) {
277-
// BaseNavigator.push(
278-
// context,
279-
// CustomProfile(
280-
// profileId: id,
281-
// ),
282-
// );
283-
// }
277+
_handlePushGenProfilePage(BuildContext context, String id) {
278+
BaseNavigator.push(
279+
context,
280+
GenProfile(
281+
profileId: id,
282+
),
283+
);
284+
}
284285

285286
@override
286287
Widget build(BuildContext context) {
@@ -334,7 +335,7 @@ class ProfileItem extends StatelessWidget {
334335
// icon: Icons.extension_outlined,
335336
// label: "自定义",
336337
// onPressed: () {
337-
// _handlePushCustomPage(context, profile.id);
338+
// _handlePushGenProfilePage(context, profile.id);
338339
// },
339340
// ),
340341
ActionItemData(

lib/models/clash_config.dart

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -273,6 +273,17 @@ class GeoXUrl with _$GeoXUrl {
273273
}
274274
}
275275

276+
@freezed
277+
class ClashConfigSnippet with _$ClashConfigSnippet {
278+
const factory ClashConfigSnippet({
279+
@Default([]) @JsonKey(name: "proxy-groups") List<ProxyGroup> proxyGroups,
280+
@Default([]) List<String> rule,
281+
}) = _ClashConfigSnippet;
282+
283+
factory ClashConfigSnippet.fromJson(Map<String, Object?> json) =>
284+
_$ClashConfigSnippetFromJson(json);
285+
}
286+
276287
@freezed
277288
class ClashConfig with _$ClashConfig {
278289
const factory ClashConfig({
@@ -301,7 +312,7 @@ class ClashConfig with _$ClashConfig {
301312
@JsonKey(name: "geodata-loader")
302313
GeodataLoader geodataLoader,
303314
@Default([]) @JsonKey(name: "proxy-groups") List<ProxyGroup> proxyGroups,
304-
@Default([]) List<String> rules,
315+
@Default([]) List<String> rule,
305316
@JsonKey(name: "global-ua") String? globalUa,
306317
@Default(ExternalControllerStatus.close)
307318
@JsonKey(name: "external-controller")

0 commit comments

Comments
 (0)