diff --git a/functions_call_flutter/lib/functions_call_flutter.dart b/functions_call_flutter/lib/functions_call_flutter.dart index 0338f94..7eba210 100644 --- a/functions_call_flutter/lib/functions_call_flutter.dart +++ b/functions_call_flutter/lib/functions_call_flutter.dart @@ -1,5 +1,7 @@ library; +export 'package:tekartik_firebase_functions/firebase_functions.dart' + show regionBelgium, regionUsCentral1, regionFrankfurt; export 'src/functions_call.dart' show FirebaseFunctionsCallService, diff --git a/functions_call_flutter/lib/src/functions_call.dart b/functions_call_flutter/lib/src/functions_call.dart index 54173cd..0f5aaa0 100644 --- a/functions_call_flutter/lib/src/functions_call.dart +++ b/functions_call_flutter/lib/src/functions_call.dart @@ -14,6 +14,10 @@ class FirebaseFunctionsCallableOptions { /// Sets whether or not to use limited-use App Check tokens when invoking the associated function. bool limitedUseAppCheckToken; + + @override + String toString() => + 'FirebaseFunctionsCallableOptions(timeout: $timeout${limitedUseAppCheckToken == true ? ', limitedUseAppCheckToken: $limitedUseAppCheckToken' : ''})'; } /// Firebase functions call @@ -72,15 +76,16 @@ mixin FirebaseFunctionsCallDefaultMixin implements FirebaseFunctionsCall { /// Firebase functions call service abstract class FirebaseFunctionsCallService { /// Get the firebase functions call instance - FirebaseFunctionsCall functionsCall(App app); + FirebaseFunctionsCall functionsCall(App app, {required String region}); } /// Firebase functions call service default mixin mixin FirebaseFunctionsCallServiceDefaultMixin implements FirebaseFunctionsCallService { @override - FirebaseFunctionsCall functionsCall(App app) { - throw UnimplementedError('FirebaseFunctionsCallService.functionsCall'); + FirebaseFunctionsCall functionsCall(App app, {required String region}) { + throw UnimplementedError( + 'FirebaseFunctionsCallService.functionsCall(${app.name}, $region)'); } } diff --git a/functions_call_flutter/lib/src/functions_call_flutter.dart b/functions_call_flutter/lib/src/functions_call_flutter.dart index cd5caae..c01641f 100644 --- a/functions_call_flutter/lib/src/functions_call_flutter.dart +++ b/functions_call_flutter/lib/src/functions_call_flutter.dart @@ -1,4 +1,5 @@ import 'package:cloud_functions/cloud_functions.dart' as native; +import 'package:tekartik_common_utils/common_utils_import.dart'; import 'package:tekartik_firebase/firebase.dart'; // ignore: implementation_imports import 'package:tekartik_firebase_flutter/src/firebase_flutter.dart' @@ -16,22 +17,32 @@ FirebaseFunctionsCallService get firebaseFunctionsCallServiceFlutter => /// Firebase functions call service flutter class FirebaseFunctionsCallServiceFlutter - with FirebaseProductServiceMixin implements FirebaseFunctionsCallService { + /// Most implementation need a single instance, keep it in memory! + final _instances = {}; + + FirebaseFunctionsCallFlutter _getInstance(App app, String region, + FirebaseFunctionsCallFlutter Function() createIfNotFound) { + var key = '${app.name}_$region'; + var instance = _instances[key]; + if (instance == null) { + var newInstance = instance = createIfNotFound(); + _instances[key] = newInstance; + } + return instance; + } + @override - FirebaseFunctionsCallFlutter functionsCall(App app) { - return getInstance(app, () { + FirebaseFunctionsCallFlutter functionsCall(App app, + {required String region}) { + return _getInstance(app, region, () { assert(app is FirebaseAppFlutter, 'invalid firebase app type'); var appFlutter = app as FirebaseAppFlutter; - if (appFlutter.isDefault!) { - return FirebaseFunctionsCallFlutter( - this, native.FirebaseFunctions.instance); - } else { - return FirebaseFunctionsCallFlutter( - this, - native.FirebaseFunctions.instanceFor( - app: appFlutter.nativeInstance!)); - } + + return FirebaseFunctionsCallFlutter( + this, + native.FirebaseFunctions.instanceFor( + app: appFlutter.nativeInstance!, region: region)); }); } } diff --git a/functions_call_flutter/pubspec.yaml b/functions_call_flutter/pubspec.yaml index 434fcd9..c0caa2e 100644 --- a/functions_call_flutter/pubspec.yaml +++ b/functions_call_flutter/pubspec.yaml @@ -26,6 +26,15 @@ dependencies: url: https://github.com/tekartik/firebase.dart ref: dart3a path: firebase + tekartik_common_utils: + git: + url: https://github.com/tekartik/common_utils.dart + ref: dart3a + tekartik_firebase_functions: + git: + url: https://github.com/tekartik/firebase_functions.dart + ref: dart3a + path: firebase_functions dev_dependencies: flutter_test: sdk: flutter