@@ -7,7 +7,7 @@ class CustomFontLoader {
77 static final Map <String , String > _loadedFonts = {};
88 static final Set <String > _customFonts = {};
99 static final Set <String > _customFonts2 = {};
10-
10+
1111 static List <String > get loadedFonts => _loadedFonts.keys.toList ()..sort ();
1212 static List <String > get customFonts => _customFonts.toList ()..sort ();
1313 static List <String > get customFonts2 => _customFonts2.toList ()..sort ();
@@ -29,7 +29,7 @@ class CustomFontLoader {
2929 try {
3030 final dir = Directory (directory);
3131 final fontFiles = < File > [];
32-
32+
3333 await for (final entity in dir.list (recursive: true )) {
3434 if (entity is File ) {
3535 final ext = path.extension (entity.path).toLowerCase ();
@@ -38,38 +38,38 @@ class CustomFontLoader {
3838 }
3939 }
4040 }
41-
41+
4242 for (final fontFile in fontFiles) {
4343 try {
4444 final fontName = _extractFontName (fontFile.path);
45-
45+
4646 if (_loadedFonts.containsKey (fontName)) {
4747 continue ;
4848 }
49-
49+
5050 final fontLoader = FontLoader (fontName);
5151 final bytes = await fontFile.readAsBytes ();
5252 fontLoader.addFont (Future .value (ByteData .view (bytes.buffer)));
5353 await fontLoader.load ();
54-
54+
5555 _loadedFonts[fontName] = fontFile.path;
5656 if (slot == 2 ) {
5757 _customFonts2.add (fontName);
5858 } else {
5959 _customFonts.add (fontName);
6060 }
61-
61+
6262 } catch (e) {
6363 print ('Error loading ${path .basename (fontFile .path )}: $e ' );
6464 }
6565 }
66-
66+
6767 } catch (e) {
6868 print ('Error loading custom fonts: $e ' );
6969 rethrow ;
7070 }
7171 }
72-
72+
7373 static void clearCustomFonts ({int slot = 1 }) {
7474 if (slot == 2 ) {
7575 for (final fontName in _customFonts2) {
@@ -88,43 +88,43 @@ class CustomFontLoader {
8888 try {
8989 final String manifestJson = await rootBundle.loadString ('AssetManifest.bin.json' );
9090 final Map <String , dynamic > manifest = json.decode (manifestJson);
91-
91+
9292 final fontPaths = < String > [];
93-
93+
9494 for (final key in manifest.keys) {
95- if (key.startsWith ('assets/fonts/' ) &&
95+ if (key.startsWith ('assets/fonts/' ) &&
9696 (key.endsWith ('.ttf' ) || key.endsWith ('.otf' ) || key.endsWith ('.ttc' ))) {
9797 fontPaths.add (key);
9898 }
9999 }
100-
100+
101101 print ('Found ${fontPaths .length } font files in assets' );
102-
102+
103103 int loaded = 0 ;
104104 for (final fontPath in fontPaths) {
105105 try {
106106 final fontName = _extractFontName (fontPath);
107-
107+
108108 if (_loadedFonts.containsKey (fontName)) {
109109 continue ;
110110 }
111-
111+
112112 final fontLoader = FontLoader (fontName);
113113 final fontData = await rootBundle.load (fontPath);
114114 fontLoader.addFont (Future .value (fontData.buffer.asByteData ()));
115115 await fontLoader.load ();
116-
116+
117117 _loadedFonts[fontName] = fontPath;
118118 loaded++ ;
119-
119+
120120 if (loaded % 100 == 0 ) {
121121 print ('Loaded $loaded fonts...' );
122122 }
123123 } catch (e) {
124124 print ('Error loading font $fontPath : $e ' );
125125 }
126126 }
127-
127+
128128 print ('Successfully loaded $loaded fonts from assets' );
129129 } catch (e) {
130130 print ('Error loading fonts from assets: $e ' );
@@ -133,17 +133,17 @@ class CustomFontLoader {
133133
134134 static Future <void > _loadFontsFromFileSystem () async {
135135 String ? fontsPath = await _getFontsPath ();
136-
136+
137137 if (fontsPath == null ) {
138138 print ('Fonts directory not found in app bundle' );
139139 return ;
140140 }
141-
142- print ('Loading fonts from: $fontsPath ' );
143-
141+
142+ // print('Loading fonts from: $fontsPath');
143+
144144 final fontsDir = Directory (fontsPath);
145145 final fontFiles = < File > [];
146-
146+
147147 await for (final entity in fontsDir.list (recursive: false )) {
148148 if (entity is File ) {
149149 final ext = path.extension (entity.path).toLowerCase ();
@@ -152,42 +152,42 @@ class CustomFontLoader {
152152 }
153153 }
154154 }
155-
155+
156156 int loaded = 0 ;
157157 int skipped = 0 ;
158-
158+
159159 for (final fontFile in fontFiles) {
160160 try {
161161 final fontName = _extractFontName (fontFile.path);
162-
162+
163163 if (_loadedFonts.containsKey (fontName)) {
164164 skipped++ ;
165165 continue ;
166166 }
167-
167+
168168 final fontLoader = FontLoader (fontName);
169169 final bytes = await fontFile.readAsBytes ();
170170 fontLoader.addFont (Future .value (ByteData .view (bytes.buffer)));
171171 await fontLoader.load ();
172-
172+
173173 _loadedFonts[fontName] = fontFile.path;
174174 loaded++ ;
175-
175+
176176 if (loaded % 500 == 0 ) {
177177 }
178178 } catch (e) {
179179 print ('Error loading ${path .basename (fontFile .path )}: $e ' );
180180 }
181181 }
182-
183- print ('Loaded $loaded fonts (skipped $skipped duplicates)' );
182+
183+ // print('Loaded $loaded fonts (skipped $skipped duplicates)');
184184 }
185185
186186 static Future <String ?> _getFontsPath () async {
187187 if (Platform .isMacOS) {
188188 final executablePath = Platform .resolvedExecutable;
189189 final appDir = Directory (path.dirname (executablePath));
190-
190+
191191 final flutterAssetsDir = Directory (path.join (
192192 appDir.parent.path,
193193 'Frameworks' ,
@@ -199,70 +199,70 @@ class CustomFontLoader {
199199 'assets' ,
200200 'fonts'
201201 ));
202-
203- print ('DEBUG: Looking for fonts at: ${flutterAssetsDir .path }' );
204- print ('DEBUG: Directory exists: ${await flutterAssetsDir .exists ()}' );
205-
202+
203+ // print('DEBUG: Looking for fonts at: ${flutterAssetsDir.path}');
204+ // print('DEBUG: Directory exists: ${await flutterAssetsDir.exists()}');
205+
206206 if (await flutterAssetsDir.exists ()) {
207207 final files = await flutterAssetsDir.list ().toList ();
208- print ('DEBUG: Found ${files .length } files in fonts directory' );
208+ // print('DEBUG: Found ${files.length} files in fonts directory');
209209 return flutterAssetsDir.path;
210210 } else {
211211 print ('DEBUG: Fonts directory NOT found!' );
212212 }
213213 } else if (Platform .isLinux) {
214214 final executablePath = Platform .resolvedExecutable;
215215 final appDir = path.dirname (executablePath);
216-
216+
217217 var fontsDir = Directory (path.join (appDir, 'data' , 'flutter_assets' , 'assets' , 'fonts' ));
218218 if (await fontsDir.exists ()) {
219219 return fontsDir.path;
220220 }
221-
221+
222222 fontsDir = Directory (path.join (appDir, 'data' , 'flutter_assets' , 'fonts' ));
223223 if (await fontsDir.exists ()) {
224224 return fontsDir.path;
225225 }
226-
226+
227227 fontsDir = Directory (path.join (appDir, '..' , 'data' , 'fonts' ));
228228 if (await fontsDir.exists ()) {
229229 return fontsDir.path;
230230 }
231-
231+
232232 fontsDir = Directory (path.join (appDir, 'data' , 'fonts' ));
233233 if (await fontsDir.exists ()) {
234234 return fontsDir.path;
235235 }
236236 } else if (Platform .isWindows) {
237237 final executablePath = Platform .resolvedExecutable;
238238 final appDir = path.dirname (executablePath);
239-
239+
240240 final fontsDir = Directory (path.join (appDir, 'data' , 'flutter_assets' , 'assets' , 'fonts' ));
241-
241+
242242 print ('Windows fonts path: ${fontsDir .path }' );
243243 print ('Fonts directory exists: ${await fontsDir .exists ()}' );
244-
244+
245245 if (await fontsDir.exists ()) {
246246 return fontsDir.path;
247247 }
248-
248+
249249 print ('ERROR: Fonts directory not found at expected location' );
250250 }
251-
251+
252252 return null ;
253253 }
254254
255255 static String _extractFontName (String fontPath) {
256256 final fileName = path.basenameWithoutExtension (fontPath);
257-
257+
258258 final decoded = Uri .decodeComponent (fileName);
259-
259+
260260 final cleaned = decoded.trim ();
261-
261+
262262 return cleaned.isNotEmpty ? cleaned : fileName;
263263 }
264264
265265 static List <String > getAvailableFonts () {
266266 return loadedFonts;
267267 }
268- }
268+ }
0 commit comments