Skip to content

Commit 600b681

Browse files
Add FPS
1 parent d4581b4 commit 600b681

File tree

13 files changed

+405
-58
lines changed

13 files changed

+405
-58
lines changed

lib/Screens/Setting/experiment_setting_screen.dart

Lines changed: 66 additions & 57 deletions
Original file line numberDiff line numberDiff line change
@@ -81,70 +81,79 @@ class _ExperimentSettingScreenState extends State<ExperimentSettingScreen>
8181
children: [
8282
if (ResponsiveUtil.isLandscape()) const SizedBox(height: 10),
8383
..._privacySettings(),
84-
if (ResponsiveUtil.isAndroid()) const SizedBox(height: 10),
85-
if (ResponsiveUtil.isAndroid())
86-
ItemBuilder.buildEntryItem(
87-
// tip: _modes.isNotEmpty
88-
// ? _modes[_refreshRate.clamp(0, _modes.length - 1)]
89-
// .toString()
90-
// : "",
91-
context: context,
92-
title: "刷新率",
93-
description:
94-
"意在解决部分机型高刷失效的问题,如无问题,请不要修改\n如果您的设备支持LTPO,可能会设置失败\n已选模式: ${_modes.isNotEmpty ? _modes[_refreshRate.clamp(0, _modes.length - 1)].toString() : ""}\n首选模式: ${_preferredMode?.toString() ?? "Unknown"}\n活动模式: ${_activeMode?.toString() ?? "Unknown"}",
95-
topRadius: true,
96-
bottomRadius: true,
97-
onTap: () {
98-
getRefreshRate();
99-
BottomSheetBuilder.showListBottomSheet(
100-
context,
101-
(context) => TileList.fromOptions(
102-
_supportedModeTuples,
103-
(item2) async {
104-
try {
105-
ILogger.info(
106-
"Try to set display mode: ${item2.toString()}");
107-
ILogger.info(
108-
"Active display mode before set: ${_activeMode.toString()}\nPreferred display mode before set: ${_preferredMode.toString()}");
109-
await FlutterDisplayMode.setPreferredMode(item2);
110-
_activeMode = await FlutterDisplayMode.active;
111-
_preferredMode = await FlutterDisplayMode.preferred;
112-
ILogger.info(
113-
"Active display mode after set: ${_activeMode.toString()}\nPreferred display mode after set: ${_preferredMode.toString()}");
114-
if (_preferredMode?.toString() != item2.toString()) {
115-
IToast.showTop("刷新率设置失败");
116-
} else {
117-
if (_activeMode?.toString() != item2.toString()) {
118-
IToast.showTop("刷新率设置成功,但当前显示模式未改变");
119-
} else {
120-
IToast.showTop("刷新率设置成功");
121-
}
122-
}
123-
} catch (e, t) {
124-
IToast.showTop("刷新率设置失败: ${e.toString()}");
125-
ILogger.error("Failed to set display mode", e, t);
126-
}
127-
_refreshRate = _modes.indexOf(item2);
128-
getRefreshRate();
129-
HiveUtil.put(HiveUtil.refreshRateKey, _refreshRate);
130-
Navigator.pop(context);
131-
},
132-
selected:
133-
_modes[_refreshRate.clamp(0, _modes.length - 1)],
134-
context: context,
135-
title: "选择刷新率",
136-
onCloseTap: () => Navigator.pop(context),
137-
),
138-
);
139-
},
140-
),
84+
if (ResponsiveUtil.isAndroid()) ..._fpsSettings(),
14185
const SizedBox(height: 30),
14286
],
14387
),
14488
),
14589
);
14690
}
14791

92+
_fpsSettings() {
93+
return [
94+
const SizedBox(height: 10),
95+
ItemBuilder.buildEntryItem(
96+
context: context,
97+
title: "刷新率",
98+
description:
99+
"意在解决部分机型高刷失效的问题,如无问题,请不要修改\n如果您的设备支持LTPO,可能会设置失败\n已选模式: ${_modes.isNotEmpty ? _modes[_refreshRate.clamp(0, _modes.length - 1)].toString() : ""}\n首选模式: ${_preferredMode?.toString() ?? "Unknown"}\n活动模式: ${_activeMode?.toString() ?? "Unknown"}",
100+
topRadius: true,
101+
onTap: () {
102+
getRefreshRate();
103+
BottomSheetBuilder.showListBottomSheet(
104+
context,
105+
(context) => TileList.fromOptions(
106+
_supportedModeTuples,
107+
(item2) async {
108+
try {
109+
ILogger.info("Try to set display mode: ${item2.toString()}");
110+
ILogger.info(
111+
"Active display mode before set: ${_activeMode.toString()}\nPreferred display mode before set: ${_preferredMode.toString()}");
112+
await FlutterDisplayMode.setPreferredMode(item2);
113+
_activeMode = await FlutterDisplayMode.active;
114+
_preferredMode = await FlutterDisplayMode.preferred;
115+
ILogger.info(
116+
"Active display mode after set: ${_activeMode.toString()}\nPreferred display mode after set: ${_preferredMode.toString()}");
117+
if (_preferredMode?.toString() != item2.toString()) {
118+
IToast.showTop("刷新率设置失败");
119+
} else {
120+
if (_activeMode?.toString() != item2.toString()) {
121+
IToast.showTop("刷新率设置成功,但当前显示模式未改变");
122+
} else {
123+
IToast.showTop("刷新率设置成功");
124+
}
125+
}
126+
} catch (e, t) {
127+
IToast.showTop("刷新率设置失败: ${e.toString()}");
128+
ILogger.error("Failed to set display mode", e, t);
129+
}
130+
_refreshRate = _modes.indexOf(item2);
131+
getRefreshRate();
132+
HiveUtil.put(HiveUtil.refreshRateKey, _refreshRate);
133+
Navigator.pop(context);
134+
},
135+
selected: _modes[_refreshRate.clamp(0, _modes.length - 1)],
136+
context: context,
137+
title: "选择刷新率",
138+
onCloseTap: () => Navigator.pop(context),
139+
),
140+
);
141+
},
142+
),
143+
ItemBuilder.buildRadioItem(
144+
context: context,
145+
value: appProvider.showFPS,
146+
title: "显示实时FPS",
147+
bottomRadius: true,
148+
onTap: () {
149+
setState(() {
150+
appProvider.showFPS = !appProvider.showFPS;
151+
});
152+
},
153+
),
154+
];
155+
}
156+
148157
_privacySettings() {
149158
return [
150159
ItemBuilder.buildCaptionItem(

lib/Screens/panel_screen.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import 'package:loftify/Screens/Navigation/mine_screen.dart';
2020
import 'package:loftify/Screens/refresh_interface.dart';
2121
import 'package:loftify/Utils/ilogger.dart';
2222
import 'package:provider/provider.dart';
23+
import 'package:show_fps/show_fps.dart';
2324

2425
import '../Utils/app_provider.dart';
2526
import '../Utils/constant.dart';

lib/Utils/app_provider.dart

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -66,6 +66,16 @@ class AppProvider with ChangeNotifier {
6666

6767
bool shownShortcutHelp = false;
6868

69+
bool _showFPS = HiveUtil.getBool(HiveUtil.showFPSKey, defaultValue: false);
70+
71+
bool get showFPS => _showFPS;
72+
73+
set showFPS(bool value) {
74+
_showFPS = value;
75+
HiveUtil.put(HiveUtil.showFPSKey, value);
76+
notifyListeners();
77+
}
78+
6979
String _captchaToken = "";
7080

7181
String get captchaToken => _captchaToken;

lib/Utils/hive_util.dart

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -104,6 +104,7 @@ class HiveUtil {
104104
//System
105105
static const String firstLoginKey = "firstLogin";
106106
static const String refreshRateKey = "refreshRate";
107+
static const String showFPSKey = "showFPS";
107108

108109
static confirmLogout(BuildContext context) {
109110
DialogBuilder.showConfirmDialog(

lib/main.dart

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import 'package:package_info_plus/package_info_plus.dart';
2020
import 'package:path/path.dart';
2121
import 'package:protocol_handler/protocol_handler.dart';
2222
import 'package:provider/provider.dart';
23+
import 'package:show_fps/show_fps.dart';
2324
import 'package:window_manager/window_manager.dart';
2425

2526
import 'Screens/main_screen.dart';
@@ -151,6 +152,27 @@ class MyApp extends StatelessWidget {
151152
this.title = 'Loftify',
152153
});
153154

155+
_buildFPS(BuildContext context, Widget child) {
156+
if (appProvider.showFPS) {
157+
return ShowFPS(
158+
alignment: Alignment.topRight,
159+
visible: true,
160+
showChart: false,
161+
textStyle: Theme.of(context)
162+
.textTheme
163+
.titleLarge
164+
?.apply(color: Colors.red, fontSizeDelta: 10),
165+
// decoration: BoxDecoration(
166+
// color: Colors.black54,
167+
// borderRadius: BorderRadius.circular(8),
168+
// ),
169+
child: child,
170+
);
171+
} else {
172+
return child;
173+
}
174+
}
175+
154176
@override
155177
Widget build(BuildContext context) {
156178
return MultiProvider(
@@ -206,7 +228,7 @@ class MyApp extends StatelessWidget {
206228
FocusManager.instance.primaryFocus?.unfocus();
207229
}
208230
},
209-
child: widget,
231+
child: _buildFPS(context, widget),
210232
),
211233
),
212234
],

pubspec.lock

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1499,6 +1499,13 @@ packages:
14991499
url: "https://pub.flutter-io.cn"
15001500
source: hosted
15011501
version: "0.1.2"
1502+
show_fps:
1503+
dependency: "direct main"
1504+
description:
1505+
path: "third-party/show_fps"
1506+
relative: true
1507+
source: path
1508+
version: "1.0.6"
15021509
sky_engine:
15031510
dependency: transitive
15041511
description: flutter

pubspec.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,8 @@ dependencies:
7777
flutter_native_splash: ^2.4.1 # Splash屏
7878
palette_generator: ^0.3.3+3 # 获取主色调
7979
vector_math: ^2.1.4
80+
show_fps:
81+
path: third-party/show_fps
8082
# 平台适配
8183
responsive_builder: ^0.7.1 # 响应式布局
8284
tray_manager: ^0.2.3 # 托盘图标

third-party/show_fps/CHANGELOG.md

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
## 1.0.6
2+
3+
- Bug fixes & improvements.
4+
5+
## 1.0.5
6+
7+
- Documentation update.
8+
9+
## 1.0.4
10+
11+
- Fixed customization in FPS Badge position.
12+
13+
## 1.0.3
14+
15+
- Font size fixed.
16+
17+
## 1.0.2
18+
19+
- README.md update.
20+
21+
## 1.0.1
22+
23+
- FPS chart graph color is now blue.
24+
25+
## 1.0.0
26+
27+
- Show FPS Badge on top of the screen.

third-party/show_fps/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2023 Mantresh Khurana
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

third-party/show_fps/README.md

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
# Show FPS
2+
3+
[![GitHub stars](https://img.shields.io/github/stars/mantreshkhurana/show_fps.svg?style=social)](https://github.com/mantreshkhurana/show_fps)
4+
[![pub package](https://img.shields.io/pub/v/show_fps.svg)](https://pub.dartlang.org/packages/show_fps)
5+
6+
Use ShowFPS to monitor your app's FPS (Frames Per Second) in real time.
7+
8+
![Screenshot](https://raw.githubusercontent.com/mantreshkhurana/show_fps/stable/screenshots/screenshot-1.png)
9+
10+
## Installation
11+
12+
Add `show_fps: ^1.0.6` in your project's pubspec.yaml:
13+
14+
```yaml
15+
dependencies:
16+
show_fps: ^1.0.6
17+
```
18+
19+
## Usage
20+
21+
Import `show_fps` in your dart file:
22+
23+
```dart
24+
import 'package:show_fps/show_fps.dart';
25+
```
26+
27+
Then warp your Main Widget with `ShowFPS` widget:
28+
29+
```dart
30+
CupertinoApp(
31+
title: 'FPS Monitor',
32+
theme: CupertinoThemeData(
33+
brightness: Brightness.light,
34+
),
35+
debugShowCheckedModeBanner: false,
36+
home: ShowFPS(
37+
alignment: Alignment.topRight,
38+
visible: true,
39+
showChart: false,
40+
borderRadius: BorderRadius.all(Radius.circular(11)),
41+
child: MyHomePage(title: 'FPS Monitor'),
42+
),
43+
);
44+
```

0 commit comments

Comments
 (0)