Don't load font if loaded

This commit is contained in:
Gregory
2024-01-01 18:42:38 +03:00
parent 0f74195255
commit 76a91b7fe0
2 changed files with 4 additions and 1 deletions

View File

@@ -37,7 +37,7 @@ List<MapEntry<Locale, String>> supportedLocales = const [
MapEntry(Locale('fr'), 'Français'),
MapEntry(Locale('es'), 'Español'),
MapEntry(Locale('pl'), 'Polski'),
MapEntry(Locale('ru'), 'Русский язык'),
MapEntry(Locale('ru'), 'Русский'),
MapEntry(Locale('bs'), 'Bosanski'),
MapEntry(Locale('pt'), 'Brasileiro'),
MapEntry(Locale('cs'), 'Česky'),

View File

@@ -5,6 +5,7 @@ import 'package:flutter/services.dart';
class NativeFeatures {
static const MethodChannel _channel = MethodChannel('native');
static bool _callbacksApplied = false;
static bool _systemFontLoaded = false;
static int _resPermShizuku = -2; // not set
static Future<ByteData> _readFileBytes(String path) async {
@@ -34,11 +35,13 @@ class NativeFeatures {
}
static Future<bool> tryLoadSystemFont() async {
if (_systemFontLoaded) { return true; }
var font = await _channel.invokeMethod('getSystemFont');
if (font == null) { return false; }
var fontLoader = FontLoader('SystemFont');
fontLoader.addFont(_readFileBytes(font));
await fontLoader.load();
_systemFontLoaded = true;
return true;
}