@@ -2,7 +2,7 @@ import 'package:arabic_learning/funcs/utili.dart';
22import 'package:arabic_learning/vars/statics_var.dart' ;
33import 'package:flutter/foundation.dart' ;
44import '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 ;
66import 'package:arabic_learning/package_replacement/storage.dart' ;
77import 'dart:convert' ;
88import '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) {
0 commit comments