Skip to content

Commit f354bd8

Browse files
authored
Merge branch 'OctagonalStar:main' into main
2 parents a48b7c2 + 639016f commit f354bd8

File tree

6 files changed

+61
-25
lines changed

6 files changed

+61
-25
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## v?.?.?? - ????-??-?? - (??????)
4+
5+
### Improvement
6+
7+
- 优化了网页端字体加载逻辑
8+
39
## v0.1.11 - 2025-11-28 - (000111)
410

511
### Added

lib/pages/setting_page.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -110,6 +110,11 @@ class _SettingPage extends State<SettingPage> {
110110
DropdownMenuItem(value: 2, child: Text('中阿均使用备用字体')),
111111
],
112112
onChanged: (value) {
113+
if(value == 2 && kIsWeb) {
114+
ScaffoldMessenger.of(context).showSnackBar(
115+
SnackBar(content: Text("网页版加载中文字体需要较长时间,请先耐心等待"), duration: Duration(seconds: 3),),
116+
);
117+
}
113118
setting['regular']['font'] = value;
114119
Provider.of<Global>(context, listen: false).updateSetting();
115120
},

lib/vars/global.dart

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ import 'package:arabic_learning/funcs/utili.dart';
22
import 'package:arabic_learning/vars/statics_var.dart';
33
import 'package:flutter/foundation.dart';
44
import 'package:path_provider/path_provider.dart' as path_provider;
5-
import 'package:flutter/services.dart' show rootBundle;
5+
import 'package:flutter/services.dart' show rootBundle, FontLoader;
66
import 'package:arabic_learning/package_replacement/storage.dart';
77
import 'dart:convert';
88
import 'package:flutter/material.dart';
@@ -15,7 +15,7 @@ class Global with ChangeNotifier {
1515
late bool updateLogRequire; //是否需要显示更新日志
1616
late bool isWideScreen; // 设备是否是宽屏幕
1717
late final SharedPreferences prefs; // 储存实例
18-
18+
bool backupFontLoaded = false;
1919
late bool modelTTSDownloaded = false;
2020

2121
/// the setting data
@@ -239,6 +239,19 @@ class Global with ChangeNotifier {
239239
if(refresh) await postInit();
240240
}
241241

242+
void loadFont() async {
243+
if(backupFontLoaded) return;
244+
backupFontLoaded = true;
245+
try{
246+
final ByteData bundle = await rootBundle.load("assets/fonts/zh/NotoSansSC-Medium.ttf");
247+
final FontLoader loader = FontLoader(StaticsVar.zhBackupFont)..addFont(Future.value(bundle));
248+
loader.load();
249+
} catch (e) {
250+
backupFontLoaded = false;
251+
}
252+
notifyListeners();
253+
}
254+
242255
Future<void> postInit() async {
243256
await loadTTS();
244257
await loadEggs();
@@ -285,24 +298,25 @@ class Global with ChangeNotifier {
285298
}
286299

287300
void updateTheme() {
288-
_themeData = ThemeData(
289-
useMaterial3: true,
290-
colorScheme: ColorScheme.fromSeed(
291-
seedColor: _themeList[settingData["regular"]["theme"]],
292-
brightness: settingData["regular"]["darkMode"] ? Brightness.dark : Brightness.light,
293-
),
294-
fontFamily: settingData["regular"]["font"] == 2 ? "NotoSansSC" : null,
295-
);
296301
if(settingData["regular"]["font"] == 2) {
297302
arFont = StaticsVar.arBackupFont;
298303
zhFont = StaticsVar.zhBackupFont;
304+
loadFont();
299305
} else if(settingData["regular"]["font"] == 1) {
300306
arFont = StaticsVar.arBackupFont;
301307
zhFont = null;
302308
} else {
303309
arFont = null;
304310
zhFont = null;
305311
}
312+
_themeData = ThemeData(
313+
useMaterial3: true,
314+
colorScheme: ColorScheme.fromSeed(
315+
seedColor: _themeList[settingData["regular"]["theme"]],
316+
brightness: settingData["regular"]["darkMode"] ? Brightness.dark : Brightness.light,
317+
),
318+
fontFamily: zhFont,
319+
);
306320
}
307321

308322
void acceptAggrement(String name) {

pubspec.yaml

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -83,13 +83,14 @@ flutter:
8383
assets:
8484
- CHANGELOG.md
8585
- assets/eggs/s.txt
86+
- assets/fonts/zh/NotoSansSC-Medium.ttf
8687
fonts:
8788
- family: Vazirmatn
8889
fonts:
8990
- asset: assets/fonts/ar/Vazirmatn-VariableFont_wght.ttf
9091
- family: NotoSansSC
91-
fonts:
92-
- asset: assets/fonts/zh/NotoSansSC-Medium.ttf
92+
# fonts:
93+
# - asset: assets/fonts/zh/NotoSansSC-Medium.ttf
9394
flutter_launcher_icons:
9495
android: "launcher_icon"
9596
ios: true

web/flutter_bootstrap.js

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
{{flutter_js}}
2+
{{flutter_build_config}}
3+
4+
const loading = document.createElement('div');
5+
document.body.appendChild(loading);
6+
loading.textContent = "正在加载中(Step 1)...\n若长时间无响应请尝试更换网络";
7+
_flutter.loader.load({
8+
config: {
9+
'canvasKitBaseUrl': '/arabic_learning/canvaskit/',
10+
},
11+
serviceWorkerSettings: {
12+
serviceWorkerVersion: {{flutter_service_worker_version}},
13+
},
14+
onEntrypointLoaded: async function (engineInitializer) {
15+
loading.textContent = "正在加载中(Step 2)...长时间无响应请尝试删除缓存或更换浏览器";
16+
const appRunner = await engineInitializer.initializeEngine({
17+
'fontFallbackBaseUrl': 'https://fonts.gstatic.cn/s/',
18+
});
19+
20+
loading.textContent = "加载完成正在进入...";
21+
await appRunner.runApp();
22+
},
23+
});

web/index.html

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,6 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<!--
5-
If you are serving your web app in a path other than the root, change the
6-
href value below to reflect the base path you are serving from.
7-
8-
The path provided below has to start and end with a slash "/" in order for
9-
it to work correctly.
10-
11-
For more details:
12-
* https://developer.mozilla.org/en-US/docs/Web/HTML/Element/base
13-
14-
This is a placeholder for base href that will be replaced by the value of
15-
the `--base-href` argument provided to `flutter build`.
16-
-->
174
<base href="$FLUTTER_BASE_HREF">
185

196
<meta charset="UTF-8">

0 commit comments

Comments
 (0)