Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 0 additions & 47 deletions example/android/app/google-services.json

This file was deleted.

41 changes: 1 addition & 40 deletions example/integration_test/dynamic_cached_fonts_example_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,6 @@ import 'dart:typed_data';

import 'package:dynamic_cached_fonts/dynamic_cached_fonts.dart';
import 'package:dynamic_cached_fonts_example/constants.dart';
import 'package:dynamic_cached_fonts_example/firebase_options.dart';
import 'package:firebase_core/firebase_core.dart' show Firebase;
import 'package:firebase_storage/firebase_storage.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart' show FontLoader;
import 'package:flutter_test/flutter_test.dart';
Expand All @@ -13,9 +10,7 @@ import 'package:integration_test/integration_test.dart' show IntegrationTestWidg
const String fontUrl = cascadiaCodeUrl,
fontName = cascadiaCode,
altFontUrl = notoSansUrl,
altFontName = notoSans,
firebaseFontUrl = firaCodeUrl,
firebaseFontName = firaCode;
altFontName = notoSans;

final String cacheKey = cacheKeyFromUrl(fontUrl);

Expand Down Expand Up @@ -214,40 +209,6 @@ void main() {
});
});

group('DynamicCachedFonts.fromFirebase', () {
late FileInfo font;
late Reference bucketRef;

setUp(() async {
await Firebase.initializeApp(options: DefaultFirebaseOptions.currentPlatform);

font = (await DynamicCachedFonts.fromFirebase(
bucketUrl: firebaseFontUrl,
fontFamily: firebaseFontName,
).load())
.first;

bucketRef = FirebaseStorage.instance.refFromURL(firebaseFontUrl);
});

testWidgets('should parse Firebase Bucket URL', (_) async {
expect(font.originalUrl, equals(await bucketRef.getDownloadURL()));
});

testWidgets('should load font into cache', (_) async {
expect(font, isNotNull);
});

testWidgets('should load valid font file from Firebase', (_) async {
expect(
font.file.readAsBytesSync(),
orderedEquals((await bucketRef.getData())!),
);
});
},
skip: ThemeData().platform == TargetPlatform.windows ||
ThemeData().platform == TargetPlatform.linux);

group('DynamicCachedFonts.cacheFont', () {
FileInfo? font;

Expand Down
7 changes: 0 additions & 7 deletions example/ios/firebase_app_id_file.json

This file was deleted.

75 changes: 0 additions & 75 deletions example/lib/firebase_options.dart

This file was deleted.

1 change: 0 additions & 1 deletion example/lib/src/demos.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,2 @@
export 'demos/download_use_delete_demo.dart';
export 'demos/download_use_demo.dart';
export 'demos/firebase_demo.dart';
54 changes: 0 additions & 54 deletions example/lib/src/demos/firebase_demo.dart

This file was deleted.

7 changes: 0 additions & 7 deletions example/macos/firebase_app_id_file.json

This file was deleted.

2 changes: 0 additions & 2 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,6 @@ dependencies:

dynamic_cached_fonts:
path: ../
firebase_core: ^3.0.0
firebase_storage: ^12.0.0
async: ^2.8.2

dev_dependencies:
Expand Down
68 changes: 3 additions & 65 deletions lib/dynamic_cached_fonts.dart
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,6 @@ part 'src/raw_dynamic_cached_fonts.dart';

/// Allows dynamically loading fonts from the given url.
///
/// Fetching fonts from Firebase Storage is also supported.
///
/// For ready to use, simple interface, initialize [DynamicCachedFonts] and call
/// the [load] method either in you `initState()` or just before `runApp()` itself.
///
Expand Down Expand Up @@ -102,7 +100,6 @@ class DynamicCachedFonts {
'url cannot be empty',
),
urls = <String>[url],
_isFirebaseURL = false,
_loaded = false;

/// Allows dynamically loading fonts from the given list of url and caching them.
Expand Down Expand Up @@ -152,59 +149,11 @@ class DynamicCachedFonts {
),
'url cannot be empty',
),
_isFirebaseURL = false,
_loaded = false;

/// Allows dynamically loading fonts from firebase storage with the given
/// firebase storage url, and caching them.
///
/// _**Firebase app must be initialized before loading the font!!**_
///
/// - **REQUIRED** The [bucketUrl] property is used to specify the download url
/// for the required font. It should be a valid Google Cloud Storage (gs://) url
/// which points to a font file.
/// Currently, only OpenType (OTF) and TrueType (TTF) fonts are supported.
///
/// - **REQUIRED** The [fontFamily] property is used to specify the name
/// of the font family which is to be used as [TextStyle.fontFamily].
///
/// - The [maxCacheObjects] property defines how large the cache is allowed to be.
/// If there are more files the files that haven't been used for the longest
/// time will be removed.
///
/// It is used to specify the cache configuration, [Config],
/// for [CacheManager].
///
/// - [cacheStalePeriod] is the time duration in which
/// a cache object is considered 'stale'. When a file is cached but
/// not being used for a certain time the file will be deleted
///
/// Defaults to 365 days.
///
/// It is used to specify the cache configuration, [Config],
/// for [CacheManager].
DynamicCachedFonts.fromFirebase({
required String bucketUrl,
required this.fontFamily,
this.maxCacheObjects = kDefaultMaxCacheObjects,
this.cacheStalePeriod = kDefaultCacheStalePeriod,
}) : assert(
fontFamily != '',
'fontFamily cannot be empty',
),
assert(
bucketUrl != '',
'bucketUrl cannot be empty',
),
urls = <String>[bucketUrl],
_isFirebaseURL = true,
_loaded = false;

/// Used to specify the download url(s) for the required font(s).
///
/// It should be a valid http/https url or a Google Cloud Storage (gs://) url,
/// when using [DynamicCachedFonts.fromFirebase], which points to
/// a font file.
/// It should be a valid http/https url which points to a font file.
///
/// Currently, only OpenType (OTF) and TrueType (TTF) fonts are supported.
///
Expand Down Expand Up @@ -234,9 +183,6 @@ class DynamicCachedFonts {
/// for [CacheManager].
final Duration cacheStalePeriod;

/// Determines whether [url] is a firebase storage bucket url.
final bool _isFirebaseURL;

/// Checks whether [load] has already been called.
bool _loaded;

Expand All @@ -251,11 +197,7 @@ class DynamicCachedFonts {

WidgetsFlutterBinding.ensureInitialized();

final List<String> downloadUrls = await Future.wait(
urls.map(
(String url) async => _isFirebaseURL ? await Utils.handleUrl(url) : url,
),
);
final List<String> downloadUrls = urls;

Iterable<FileInfo> fontFiles;

Expand Down Expand Up @@ -327,11 +269,7 @@ class DynamicCachedFonts {

WidgetsFlutterBinding.ensureInitialized();

final List<String> downloadUrls = await Future.wait(
urls.map(
(String url) async => _isFirebaseURL ? await Utils.handleUrl(url) : url,
),
);
final List<String> downloadUrls = urls;

final Stream<FileInfo> fontStream = loadCachedFamilyStream(
downloadUrls,
Expand Down
Loading
Loading