12345678910111213141516171819202122232425 |
- import 'dart:collection';
- import 'package:fis_common/logger/logger.dart';
- import 'package:flutter/services.dart';
- import 'resource.dart';
- class FFontLoader {
- static final HashSet<String> _loadedFonts = HashSet();
- /// 加载字体
- static Future<bool> load(String fontFamily, FResourceKey resourceKey) async {
- if (_loadedFonts.contains(fontFamily)) return true;
- var fontLoader = FontLoader(fontFamily);
- fontLoader.addFont(fRootBundle.load(resourceKey));
- try {
- await fontLoader.load();
- } catch (e) {
- logger.e("FFontLoader load [$fontFamily] error.", e);
- return false;
- }
- _loadedFonts.add(fontFamily);
- return true;
- }
- }
|