From f9c8d4aabdffbf3fc1493d7c1eabffc35dbc64c0 Mon Sep 17 00:00:00 2001 From: daniloadorno Date: Wed, 7 Apr 2021 08:07:55 -0300 Subject: [PATCH 1/8] fix --- .../lib/firebase_remote_config.dart | 2 - .../lib/src/remote_config.dart | 32 ++------- ...base_remote_config_platform_interface.dart | 2 - ...method_channel_firebase_remote_config.dart | 67 +++++++++---------- .../src/method_channel/utils/exception.dart | 14 ++-- ...form_interface_firebase_remote_config.dart | 19 +++--- .../lib/src/remote_config_settings.dart | 8 +-- .../lib/src/remote_config_value.dart | 14 ++-- 8 files changed, 61 insertions(+), 97 deletions(-) diff --git a/packages/firebase_remote_config/firebase_remote_config/lib/firebase_remote_config.dart b/packages/firebase_remote_config/firebase_remote_config/lib/firebase_remote_config.dart index 0af32baaf3c6..34ad0b54cafb 100644 --- a/packages/firebase_remote_config/firebase_remote_config/lib/firebase_remote_config.dart +++ b/packages/firebase_remote_config/firebase_remote_config/lib/firebase_remote_config.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart=2.9 - library firebase_remote_config; import 'dart:async'; diff --git a/packages/firebase_remote_config/firebase_remote_config/lib/src/remote_config.dart b/packages/firebase_remote_config/firebase_remote_config/lib/src/remote_config.dart index 20865be8d732..99b9ecab3fd2 100644 --- a/packages/firebase_remote_config/firebase_remote_config/lib/src/remote_config.dart +++ b/packages/firebase_remote_config/firebase_remote_config/lib/src/remote_config.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart=2.9 - part of firebase_remote_config; /// The entry point for accessing Remote Config. @@ -13,7 +11,7 @@ part of firebase_remote_config; // ignore: prefer_mixin class RemoteConfig extends FirebasePluginPlatform with ChangeNotifier { RemoteConfig._({this.app}) - : super(app.name, 'plugins.flutter.io/firebase_remote_config'); + : super(app?.name ?? '', 'plugins.flutter.io/firebase_remote_config'); // Cached instances of [FirebaseRemoteConfig]. static final Map _firebaseRemoteConfigInstances = {}; @@ -22,7 +20,7 @@ class RemoteConfig extends FirebasePluginPlatform with ChangeNotifier { // to avoid creating a [MethodChannelFirebaseRemoteConfig] when not needed // or creating an instance with the default app before a user specifies an // app. - FirebaseRemoteConfigPlatform _delegatePackingProperty; + FirebaseRemoteConfigPlatform? _delegatePackingProperty; /// Returns the underlying delegate implementation. /// @@ -37,7 +35,7 @@ class RemoteConfig extends FirebasePluginPlatform with ChangeNotifier { } /// The [FirebaseApp] this instance was initialized with. - final FirebaseApp app; + final FirebaseApp? app; /// Returns an instance using the default [FirebaseApp]. static RemoteConfig get instance { @@ -45,17 +43,10 @@ class RemoteConfig extends FirebasePluginPlatform with ChangeNotifier { } /// Returns an instance using the specified [FirebaseApp]. - static RemoteConfig instanceFor({@required FirebaseApp app}) { - assert(app != null); - - if (_firebaseRemoteConfigInstances.containsKey(app.name)) { - return _firebaseRemoteConfigInstances[app.name]; - } - - RemoteConfig newInstance = RemoteConfig._(app: app); - _firebaseRemoteConfigInstances[app.name] = newInstance; - - return newInstance; + static RemoteConfig instanceFor({required FirebaseApp app}) { + return _firebaseRemoteConfigInstances.putIfAbsent(app.name, () { + return RemoteConfig._(app: app); + }); } /// Returns the [DateTime] of the last successful fetch. @@ -113,39 +104,31 @@ class RemoteConfig extends FirebasePluginPlatform with ChangeNotifier { /// Gets the value for a given key as a bool. bool getBool(String key) { - assert(key != null); return _delegate.getBool(key); } /// Gets the value for a given key as an int. int getInt(String key) { - assert(key != null); return _delegate.getInt(key); } /// Gets the value for a given key as a double. double getDouble(String key) { - assert(key != null); return _delegate.getDouble(key); } /// Gets the value for a given key as a String. String getString(String key) { - assert(key != null); return _delegate.getString(key); } /// Gets the [RemoteConfigValue] for a given key. RemoteConfigValue getValue(String key) { - assert(key != null); return _delegate.getValue(key); } /// Sets the [RemoteConfigSettings] for the current instance. Future setConfigSettings(RemoteConfigSettings remoteConfigSettings) { - assert(remoteConfigSettings != null); - assert(remoteConfigSettings.fetchTimeout != null); - assert(remoteConfigSettings.minimumFetchInterval != null); assert(!remoteConfigSettings.fetchTimeout.isNegative); assert(!remoteConfigSettings.minimumFetchInterval.isNegative); // To be consistent with iOS fetchTimeout is set to the default @@ -158,7 +141,6 @@ class RemoteConfig extends FirebasePluginPlatform with ChangeNotifier { /// Sets the default parameter values for the current instance. Future setDefaults(Map defaultParameters) { - assert(defaultParameters != null); return _delegate.setDefaults(defaultParameters); } } diff --git a/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/firebase_remote_config_platform_interface.dart b/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/firebase_remote_config_platform_interface.dart index bacea2be65d2..7820ca94dc4d 100644 --- a/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/firebase_remote_config_platform_interface.dart +++ b/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/firebase_remote_config_platform_interface.dart @@ -1,5 +1,3 @@ -// @dart=2.9 - library firebase_remote_config_platform_interface; export 'src/platform_interface/platform_interface_firebase_remote_config.dart'; diff --git a/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/method_channel/method_channel_firebase_remote_config.dart b/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/method_channel/method_channel_firebase_remote_config.dart index 3b94e18ac67b..bb1463a72845 100644 --- a/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/method_channel/method_channel_firebase_remote_config.dart +++ b/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/method_channel/method_channel_firebase_remote_config.dart @@ -1,10 +1,7 @@ -// @dart=2.9 - import 'dart:async'; import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/services.dart'; -import 'package:meta/meta.dart'; import '../../firebase_remote_config_platform_interface.dart'; import 'utils/exception.dart'; @@ -12,7 +9,7 @@ import 'utils/exception.dart'; /// Method Channel delegate for [FirebaseRemoteConfigPlatform]. class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { /// Creates a new instance for a given [FirebaseApp]. - MethodChannelFirebaseRemoteConfig({@required FirebaseApp app}) + MethodChannelFirebaseRemoteConfig({required FirebaseApp app}) : super(appInstance: app); /// Internal stub class initializer. @@ -41,29 +38,29 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { return MethodChannelFirebaseRemoteConfig._(); } - Map _activeParameters; - RemoteConfigSettings _settings; - DateTime _lastFetchTime; - RemoteConfigFetchStatus _lastFetchStatus; + late Map _activeParameters; + late RemoteConfigSettings _settings; + late DateTime _lastFetchTime; + late RemoteConfigFetchStatus _lastFetchStatus; /// Gets a [FirebaseRemoteConfigPlatform] instance for a specific /// [FirebaseApp]. /// /// Instances are cached and reused for incoming event handlers. @override - FirebaseRemoteConfigPlatform delegateFor({FirebaseApp app}) { + FirebaseRemoteConfigPlatform delegateFor({required FirebaseApp app}) { if (_methodChannelFirebaseRemoteConfigInstances.containsKey(app.name)) { - return _methodChannelFirebaseRemoteConfigInstances[app.name]; + return _methodChannelFirebaseRemoteConfigInstances[app.name]!; } _methodChannelFirebaseRemoteConfigInstances[app.name] = MethodChannelFirebaseRemoteConfig(app: app); - return _methodChannelFirebaseRemoteConfigInstances[app.name]; + return _methodChannelFirebaseRemoteConfigInstances[app.name]!; } @override FirebaseRemoteConfigPlatform setInitialValues( - {Map remoteConfigValues}) { + {required Map remoteConfigValues}) { final fetchTimeout = Duration(seconds: remoteConfigValues['fetchTimeout']); final minimumFetchInterval = Duration(seconds: remoteConfigValues['minimumFetchInterval']); @@ -80,7 +77,7 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { return this; } - RemoteConfigFetchStatus _parseFetchStatus(String status) { + RemoteConfigFetchStatus _parseFetchStatus(String? status) { switch (status) { case 'noFetchYet': return RemoteConfigFetchStatus.noFetchYet; @@ -109,7 +106,7 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { try { await channel.invokeMethod( 'RemoteConfig#ensureInitialized', { - 'appName': app.name, + 'appName': app!.name, }); } catch (exception, stackTrace) { throw convertPlatformException(exception, stackTrace); @@ -119,12 +116,12 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { @override Future activate() async { try { - bool configChanged = await channel + bool? configChanged = await channel .invokeMethod('RemoteConfig#activate', { - 'appName': app.name, + 'appName': app!.name, }); await _updateConfigParameters(); - return configChanged; + return configChanged!; } catch (exception, stackTrace) { throw convertPlatformException(exception, stackTrace); } @@ -134,7 +131,7 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { Future fetch() async { try { await channel.invokeMethod('RemoteConfig#fetch', { - 'appName': app.name, + 'appName': app!.name, }); await _updateConfigProperties(); } catch (exception, stackTrace) { @@ -147,13 +144,13 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { @override Future fetchAndActivate() async { try { - bool configChanged = await channel.invokeMethod( + bool? configChanged = await channel.invokeMethod( 'RemoteConfig#fetchAndActivate', { - 'appName': app.name, + 'appName': app!.name, }); await _updateConfigParameters(); await _updateConfigProperties(); - return configChanged; + return configChanged!; } catch (exception, stackTrace) { // Ensure that fetch status is updated. await _updateConfigProperties(); @@ -171,7 +168,7 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { if (!_activeParameters.containsKey(key)) { return RemoteConfigValue.defaultValueForBool; } - return _activeParameters[key].asBool(); + return _activeParameters[key]!.asBool(); } @override @@ -179,7 +176,7 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { if (!_activeParameters.containsKey(key)) { return RemoteConfigValue.defaultValueForInt; } - return _activeParameters[key].asInt(); + return _activeParameters[key]!.asInt(); } @override @@ -187,7 +184,7 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { if (!_activeParameters.containsKey(key)) { return RemoteConfigValue.defaultValueForDouble; } - return _activeParameters[key].asDouble(); + return _activeParameters[key]!.asDouble(); } @override @@ -195,7 +192,7 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { if (!_activeParameters.containsKey(key)) { return RemoteConfigValue.defaultValueForString; } - return _activeParameters[key].asString(); + return _activeParameters[key]!.asString(); } @override @@ -203,7 +200,7 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { if (!_activeParameters.containsKey(key)) { return RemoteConfigValue(null, ValueSource.valueStatic); } - return _activeParameters[key]; + return _activeParameters[key]!; } @override @@ -212,7 +209,7 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { try { await channel .invokeMethod('RemoteConfig#setConfigSettings', { - 'appName': app.name, + 'appName': app!.name, 'fetchTimeout': remoteConfigSettings.fetchTimeout.inSeconds, 'minimumFetchInterval': remoteConfigSettings.minimumFetchInterval.inSeconds, @@ -227,7 +224,7 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { Future setDefaults(Map defaultParameters) async { try { await channel.invokeMethod('RemoteConfig#setDefaults', { - 'appName': app.name, + 'appName': app!.name, 'defaults': defaultParameters }); await _updateConfigParameters(); @@ -237,21 +234,21 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { } Future _updateConfigParameters() async { - Map parameters = await channel + Map? parameters = await channel .invokeMapMethod( 'RemoteConfig#getAll', { - 'appName': app.name, + 'appName': app!.name, }); - _activeParameters = _parseParameters(parameters); + _activeParameters = _parseParameters(parameters!); } Future _updateConfigProperties() async { - Map properties = await channel + Map? properties = await channel .invokeMapMethod( 'RemoteConfig#getProperties', { - 'appName': app.name, + 'appName': app!.name, }); - final fetchTimeout = Duration(seconds: properties['fetchTimeout']); + final fetchTimeout = Duration(seconds: properties!['fetchTimeout']); final minimumFetchInterval = Duration(seconds: properties['minimumFetchInterval']); final lastFetchMillis = properties['lastFetchTime']; @@ -276,7 +273,7 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { return parameters; } - ValueSource _parseValueSource(String sourceStr) { + ValueSource _parseValueSource(String? sourceStr) { switch (sourceStr) { case 'static': return ValueSource.valueStatic; diff --git a/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/method_channel/utils/exception.dart b/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/method_channel/utils/exception.dart index 5cb067e71ac2..5000167db095 100644 --- a/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/method_channel/utils/exception.dart +++ b/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/method_channel/utils/exception.dart @@ -1,18 +1,16 @@ -// @dart=2.9 - import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/services.dart'; /// Catches a [PlatformException] and converts it into a [FirebaseException] if /// it was intentionally caught on the native platform. -Exception convertPlatformException(Object exception, [StackTrace stackTrace]) { +Exception convertPlatformException(Object exception, [StackTrace? stackTrace]) { if (exception is! Exception || exception is! PlatformException) { // ignore: only_throw_errors throw exception; } return platformExceptionToFirebaseException( - exception as PlatformException, + exception, stackTrace, ); } @@ -24,13 +22,13 @@ Exception convertPlatformException(Object exception, [StackTrace stackTrace]) { /// which can be converted into user friendly exceptions. FirebaseException platformExceptionToFirebaseException( PlatformException platformException, - [StackTrace stackTrace]) { - Map details = platformException.details != null - ? Map.from(platformException.details) + [StackTrace? stackTrace]) { + Map? details = platformException.details != null + ? Map.from(platformException.details) : null; String code = 'unknown'; - String message = platformException.message; + String? message = platformException.message; if (details != null) { code = details['code'] ?? code; diff --git a/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/platform_interface/platform_interface_firebase_remote_config.dart b/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/platform_interface/platform_interface_firebase_remote_config.dart index afc856d9e0c1..6824a85e941f 100644 --- a/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/platform_interface/platform_interface_firebase_remote_config.dart +++ b/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/platform_interface/platform_interface_firebase_remote_config.dart @@ -1,5 +1,3 @@ -// @dart=2.9 - import 'dart:async'; import 'package:firebase_core/firebase_core.dart'; @@ -25,11 +23,11 @@ abstract class FirebaseRemoteConfigPlatform extends PlatformInterface { /// Create instance using [app] using the existing implementation. factory FirebaseRemoteConfigPlatform.instanceFor({ - FirebaseApp app, - Map pluginConstants, + FirebaseApp? app, + Map? pluginConstants, }) { return FirebaseRemoteConfigPlatform.instance - .delegateFor(app: app) + .delegateFor(app: app!) .setInitialValues( remoteConfigValues: pluginConstants ?? {}, ); @@ -39,17 +37,17 @@ abstract class FirebaseRemoteConfigPlatform extends PlatformInterface { /// The [FirebaseApp] this instance was initialized with. @protected - final FirebaseApp appInstance; + final FirebaseApp? appInstance; /// Returns the [FirebaseApp] for the current instance. - FirebaseApp get app { + FirebaseApp? get app { if (appInstance == null) { return Firebase.app(); } return appInstance; } - static FirebaseRemoteConfigPlatform _instance; + static FirebaseRemoteConfigPlatform? _instance; /// The current default [FirebaseRemoteConfigPlatform] instance. /// @@ -61,7 +59,6 @@ abstract class FirebaseRemoteConfigPlatform extends PlatformInterface { /// Sets the [FirebaseRemoteConfigPlatform] instance. static set instance(FirebaseRemoteConfigPlatform instance) { - assert(instance != null); PlatformInterface.verifyToken(instance, _token); _instance = instance; } @@ -69,7 +66,7 @@ abstract class FirebaseRemoteConfigPlatform extends PlatformInterface { /// Enables delegates to create new instances of themselves if a none /// default [FirebaseApp] instance is required by the user. @protected - FirebaseRemoteConfigPlatform delegateFor({FirebaseApp app}) { + FirebaseRemoteConfigPlatform delegateFor({required FirebaseApp app}) { throw UnimplementedError('delegateFor() is not implemented'); } @@ -80,7 +77,7 @@ abstract class FirebaseRemoteConfigPlatform extends PlatformInterface { /// async calls. @protected FirebaseRemoteConfigPlatform setInitialValues( - {Map remoteConfigValues}) { + {required Map remoteConfigValues}) { throw UnimplementedError('setInitialValues() is not implemented'); } diff --git a/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/remote_config_settings.dart b/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/remote_config_settings.dart index 2f9fd12d60b6..b7706fa50111 100644 --- a/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/remote_config_settings.dart +++ b/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/remote_config_settings.dart @@ -1,14 +1,10 @@ -// @dart=2.9 - -import 'package:meta/meta.dart'; - /// Defines the options for the corresponding Remote Config instance. class RemoteConfigSettings { /// Constructs an instance of [RemoteConfigSettings] with given [fetchTimeout] /// and [minimumFetchInterval]. RemoteConfigSettings({ - @required this.fetchTimeout, - @required this.minimumFetchInterval, + required this.fetchTimeout, + required this.minimumFetchInterval, }); /// Maximum Duration to wait for a response when fetching configuration from diff --git a/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/remote_config_value.dart b/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/remote_config_value.dart index 3eeb23f5e58d..cd47eafaeeec 100644 --- a/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/remote_config_value.dart +++ b/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/remote_config_value.dart @@ -1,5 +1,3 @@ -// @dart=2.9 - import 'dart:convert'; import 'package:flutter/foundation.dart'; @@ -21,7 +19,7 @@ enum ValueSource { class RemoteConfigValue { /// Wraps a value with metadata and type-safe getters. @protected - RemoteConfigValue(this._value, this.source) : assert(source != null); + RemoteConfigValue(this._value, this.source); /// Default value for String static const String defaultValueForString = ''; @@ -35,7 +33,7 @@ class RemoteConfigValue { /// Default value for Bool static const bool defaultValueForBool = false; - List _value; + List? _value; /// Indicates at which source this value came from. final ValueSource source; @@ -43,14 +41,14 @@ class RemoteConfigValue { /// Decode value to string. String asString() { return _value != null - ? const Utf8Codec().decode(_value) + ? const Utf8Codec().decode(_value!) : defaultValueForString; } /// Decode value to int. int asInt() { if (_value != null) { - final String strValue = const Utf8Codec().decode(_value); + final String strValue = const Utf8Codec().decode(_value!); final int intValue = int.tryParse(strValue) ?? defaultValueForInt; return intValue; } else { @@ -61,7 +59,7 @@ class RemoteConfigValue { /// Decode value to double. double asDouble() { if (_value != null) { - final String strValue = const Utf8Codec().decode(_value); + final String strValue = const Utf8Codec().decode(_value!); final double doubleValue = double.tryParse(strValue) ?? defaultValueForDouble; return doubleValue; @@ -73,7 +71,7 @@ class RemoteConfigValue { /// Decode value to bool. bool asBool() { if (_value != null) { - final String strValue = const Utf8Codec().decode(_value); + final String strValue = const Utf8Codec().decode(_value!); final lowerCase = strValue.toLowerCase(); return lowerCase == 'true' || lowerCase == '1'; } else { From 72add6d24a4b62439cc33cf1d972e4024a2209cd Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Wed, 7 Apr 2021 15:01:39 +0100 Subject: [PATCH 2/8] review --- .../lib/src/remote_config.dart | 23 +- .../test/firebase_remote_config_test.dart | 221 ++++++++++++++---- .../firebase_remote_config/test/mock.dart | 4 +- ...method_channel_firebase_remote_config.dart | 35 ++- .../src/method_channel/utils/exception.dart | 5 +- ...form_interface_firebase_remote_config.dart | 28 +-- .../lib/src/remote_config_value.dart | 20 +- 7 files changed, 227 insertions(+), 109 deletions(-) diff --git a/packages/firebase_remote_config/firebase_remote_config/lib/src/remote_config.dart b/packages/firebase_remote_config/firebase_remote_config/lib/src/remote_config.dart index 99b9ecab3fd2..719fb6ad5945 100644 --- a/packages/firebase_remote_config/firebase_remote_config/lib/src/remote_config.dart +++ b/packages/firebase_remote_config/firebase_remote_config/lib/src/remote_config.dart @@ -10,32 +10,23 @@ part of firebase_remote_config; /// [RemoteConfig.instance] is async. // ignore: prefer_mixin class RemoteConfig extends FirebasePluginPlatform with ChangeNotifier { - RemoteConfig._({this.app}) - : super(app?.name ?? '', 'plugins.flutter.io/firebase_remote_config'); + RemoteConfig._({required this.app}) + : super(app.name, 'plugins.flutter.io/firebase_remote_config'); // Cached instances of [FirebaseRemoteConfig]. static final Map _firebaseRemoteConfigInstances = {}; - // Cached and lazily loaded instance of [FirebaseRemoteConfigPlatform] - // to avoid creating a [MethodChannelFirebaseRemoteConfig] when not needed - // or creating an instance with the default app before a user specifies an - // app. - FirebaseRemoteConfigPlatform? _delegatePackingProperty; - /// Returns the underlying delegate implementation. /// /// If called and no [_delegatePackingProperty] exists, it will first be /// created and assigned before returning the delegate. - FirebaseRemoteConfigPlatform get _delegate { - return _delegatePackingProperty ??= - FirebaseRemoteConfigPlatform.instanceFor( - app: app, - pluginConstants: pluginConstants, - ); - } + late final _delegate = FirebaseRemoteConfigPlatform.instanceFor( + app: app, + pluginConstants: pluginConstants, + ); /// The [FirebaseApp] this instance was initialized with. - final FirebaseApp? app; + final FirebaseApp app; /// Returns an instance using the default [FirebaseApp]. static RemoteConfig get instance { diff --git a/packages/firebase_remote_config/firebase_remote_config/test/firebase_remote_config_test.dart b/packages/firebase_remote_config/firebase_remote_config/test/firebase_remote_config_test.dart index bbf4ca650af0..64bc1784ce19 100644 --- a/packages/firebase_remote_config/firebase_remote_config/test/firebase_remote_config_test.dart +++ b/packages/firebase_remote_config/firebase_remote_config/test/firebase_remote_config_test.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart=2.9 - import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_remote_config/firebase_remote_config.dart'; import 'package:firebase_remote_config_platform_interface/firebase_remote_config_platform_interface.dart'; @@ -19,14 +17,13 @@ MockFirebaseRemoteConfig mockRemoteConfigPlatform = MockFirebaseRemoteConfig(); void main() { setupFirebaseRemoteConfigMocks(); - RemoteConfig remoteConfig; - - DateTime mockLastFetchTime; - RemoteConfigFetchStatus mockLastFetchStatus; - RemoteConfigSettings mockRemoteConfigSettings; - Map mockParameters; - Map mockDefaultParameters; - RemoteConfigValue mockRemoteConfigValue; + late RemoteConfig remoteConfig; + late DateTime mockLastFetchTime; + late RemoteConfigFetchStatus mockLastFetchStatus; + late RemoteConfigSettings mockRemoteConfigSettings; + late Map mockParameters; + late Map mockDefaultParameters; + late RemoteConfigValue mockRemoteConfigValue; group('$RemoteConfig', () { FirebaseRemoteConfigPlatform.instance = mockRemoteConfigPlatform; @@ -71,7 +68,7 @@ void main() { .thenReturn(mockRemoteConfigSettings); when(mockRemoteConfigPlatform.setConfigSettings(any)) - .thenAnswer((_) => null); + .thenAnswer((_) => Future.value()); when(mockRemoteConfigPlatform.activate()) .thenAnswer((_) => Future.value(true)); @@ -138,13 +135,6 @@ void main() { verify( mockRemoteConfigPlatform.setConfigSettings(remoteConfigSettings)); }); - - test('should throw if settings is null', () async { - expect( - () => remoteConfig.setConfigSettings(null), - throwsAssertionError, - ); - }); }); group('activate()', () { @@ -187,10 +177,6 @@ void main() { remoteConfig.getBool('foo'); verify(mockRemoteConfigPlatform.getBool('foo')); }); - - test('should throw if key is null', () { - expect(() => remoteConfig.getBool(null), throwsAssertionError); - }); }); group('getInt()', () { @@ -198,10 +184,6 @@ void main() { remoteConfig.getInt('foo'); verify(mockRemoteConfigPlatform.getInt('foo')); }); - - test('should throw if key is null', () { - expect(() => remoteConfig.getInt(null), throwsAssertionError); - }); }); group('getDouble()', () { @@ -209,10 +191,6 @@ void main() { remoteConfig.getDouble('foo'); verify(mockRemoteConfigPlatform.getDouble('foo')); }); - - test('should throw if key is null', () { - expect(() => remoteConfig.getDouble(null), throwsAssertionError); - }); }); group('getString()', () { @@ -220,10 +198,6 @@ void main() { remoteConfig.getString('foo'); verify(mockRemoteConfigPlatform.getString('foo')); }); - - test('should throw if key is null', () { - expect(() => remoteConfig.getString(null), throwsAssertionError); - }); }); group('getValue()', () { @@ -231,10 +205,6 @@ void main() { remoteConfig.getValue('foo'); verify(mockRemoteConfigPlatform.getValue('foo')); }); - - test('should throw if key is null', () { - expect(() => remoteConfig.getValue(null), throwsAssertionError); - }); }); group('setDefaults()', () { @@ -242,10 +212,6 @@ void main() { remoteConfig.setDefaults(mockParameters); verify(mockRemoteConfigPlatform.setDefaults(mockDefaultParameters)); }); - - test('should throw if parameters are null', () { - expect(() => remoteConfig.setDefaults(null), throwsAssertionError); - }); }); }); } @@ -256,22 +222,185 @@ class MockFirebaseRemoteConfig extends Mock MockPlatformInterfaceMixin implements TestFirebaseRemoteConfigPlatform { - MockFirebaseRemoteConfig(); + MockFirebaseRemoteConfig() { + TestFirebaseRemoteConfigPlatform(); + } + + @override + FirebaseRemoteConfigPlatform delegateFor({FirebaseApp? app}) { + return super.noSuchMethod( + Invocation.method(#delegateFor, [], {#app: app}), + returnValue: TestFirebaseRemoteConfigPlatform(), + returnValueForMissingStub: TestFirebaseRemoteConfigPlatform(), + ); + } + + @override + FirebaseRemoteConfigPlatform setInitialValues({Map? remoteConfigValues}) { + return super.noSuchMethod( + Invocation.method( + #setInitialValues, [], {#remoteConfigValues: remoteConfigValues}), + returnValue: TestFirebaseRemoteConfigPlatform(), + returnValueForMissingStub: TestFirebaseRemoteConfigPlatform(), + ); + } + + @override + Future activate() { + return super.noSuchMethod(Invocation.method(#activate, []), + returnValue: Future.value(true), + returnValueForMissingStub: Future.value(true)); + } + + @override + Future ensureInitialized() { + return super.noSuchMethod(Invocation.method(#ensureInitialized, []), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()); + } + + @override + Future fetch() { + return super.noSuchMethod(Invocation.method(#fetch, []), + returnValue: Future.value(), + returnValueForMissingStub: Future.value()); + } + + @override + Future fetchAndActivate() { + return super.noSuchMethod(Invocation.method(#fetchAndActivate, []), + returnValue: Future.value(true), + returnValueForMissingStub: Future.value(true)); + } + + @override + Future setConfigSettings(RemoteConfigSettings? remoteConfigSettings) { + return super.noSuchMethod( + Invocation.method(#setConfigSettings, [remoteConfigSettings]), + returnValue: Future.value(), + returnValueForMissingStub: Future.value(), + ); + } + + @override + Future setDefaults(Map? defaultParameters) { + return super.noSuchMethod( + Invocation.method(#setDefaults, [defaultParameters]), + returnValue: Future.value(), + returnValueForMissingStub: Future.value(), + ); + } + + @override + Map getAll() { + return super.noSuchMethod( + Invocation.method(#getAll, []), + returnValue: {}, + returnValueForMissingStub: {}, + ); + } + + @override + bool getBool(String key) { + return super.noSuchMethod( + Invocation.method(#getBool, [key]), + returnValue: true, + returnValueForMissingStub: true, + ); + } + + @override + int getInt(String key) { + return super.noSuchMethod( + Invocation.method(#getInt, [key]), + returnValue: 8, + returnValueForMissingStub: 8, + ); + } + + @override + String getString(String key) { + return super.noSuchMethod( + Invocation.method(#getString, [key]), + returnValue: 'foo', + returnValueForMissingStub: 'foo', + ); + } + + @override + double getDouble(String key) { + return super.noSuchMethod( + Invocation.method(#getDouble, [key]), + returnValue: 8.8, + returnValueForMissingStub: 8.8, + ); + } + + @override + RemoteConfigValue getValue(String key) { + return super.noSuchMethod( + Invocation.method(#getValue, [key]), + returnValue: RemoteConfigValue( + [], + ValueSource.valueStatic, + ), + returnValueForMissingStub: RemoteConfigValue( + [], + ValueSource.valueStatic, + ), + ); + } + + @override + RemoteConfigFetchStatus get lastFetchStatus { + return super.noSuchMethod( + Invocation.getter(#lastFetchStatus), + returnValue: RemoteConfigFetchStatus.success, + returnValueForMissingStub: RemoteConfigFetchStatus.success, + ); + } + + @override + DateTime get lastFetchTime { + return super.noSuchMethod( + Invocation.getter(#lastFetchTime), + returnValue: DateTime(2020), + returnValueForMissingStub: DateTime(2020), + ); + } + + @override + RemoteConfigSettings get settings { + return super.noSuchMethod( + Invocation.getter(#settings), + returnValue: RemoteConfigSettings( + fetchTimeout: const Duration(seconds: 10), + minimumFetchInterval: const Duration(hours: 1), + ), + returnValueForMissingStub: RemoteConfigSettings( + fetchTimeout: const Duration(seconds: 10), + minimumFetchInterval: const Duration(hours: 1), + ), + ); + } } class TestFirebaseRemoteConfigPlatform extends FirebaseRemoteConfigPlatform { TestFirebaseRemoteConfigPlatform() : super(); - void instanceFor({FirebaseApp app, Map pluginConstants}) {} + void instanceFor({ + FirebaseApp? app, + Map? pluginConstants, + }) {} @override - FirebaseRemoteConfigPlatform delegateFor({FirebaseApp app}) { + FirebaseRemoteConfigPlatform delegateFor({FirebaseApp? app}) { return this; } @override FirebaseRemoteConfigPlatform setInitialValues( - {Map remoteConfigValues}) { + {Map? remoteConfigValues}) { return this; } } diff --git a/packages/firebase_remote_config/firebase_remote_config/test/mock.dart b/packages/firebase_remote_config/firebase_remote_config/test/mock.dart index 0c668dd45897..e175ebd132fd 100644 --- a/packages/firebase_remote_config/firebase_remote_config/test/mock.dart +++ b/packages/firebase_remote_config/firebase_remote_config/test/mock.dart @@ -1,12 +1,10 @@ -// @dart=2.9 - import 'package:firebase_core_platform_interface/firebase_core_platform_interface.dart'; import 'package:flutter/services.dart'; import 'package:flutter_test/flutter_test.dart'; typedef Callback = Function(MethodCall call); -void setupFirebaseRemoteConfigMocks([Callback customHandlers]) { +void setupFirebaseRemoteConfigMocks([Callback? customHandlers]) { TestWidgetsFlutterBinding.ensureInitialized(); MethodChannelFirebase.channel.setMockMethodCallHandler((call) async { diff --git a/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/method_channel/method_channel_firebase_remote_config.dart b/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/method_channel/method_channel_firebase_remote_config.dart index bb1463a72845..d69c7841a19f 100644 --- a/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/method_channel/method_channel_firebase_remote_config.dart +++ b/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/method_channel/method_channel_firebase_remote_config.dart @@ -49,18 +49,16 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { /// Instances are cached and reused for incoming event handlers. @override FirebaseRemoteConfigPlatform delegateFor({required FirebaseApp app}) { - if (_methodChannelFirebaseRemoteConfigInstances.containsKey(app.name)) { - return _methodChannelFirebaseRemoteConfigInstances[app.name]!; - } - - _methodChannelFirebaseRemoteConfigInstances[app.name] = - MethodChannelFirebaseRemoteConfig(app: app); - return _methodChannelFirebaseRemoteConfigInstances[app.name]!; + return _methodChannelFirebaseRemoteConfigInstances.putIfAbsent( + app.name, + () => MethodChannelFirebaseRemoteConfig(app: app), + ); } @override - FirebaseRemoteConfigPlatform setInitialValues( - {required Map remoteConfigValues}) { + FirebaseRemoteConfigPlatform setInitialValues({ + required Map remoteConfigValues, + }) { final fetchTimeout = Duration(seconds: remoteConfigValues['fetchTimeout']); final minimumFetchInterval = Duration(seconds: remoteConfigValues['minimumFetchInterval']); @@ -106,7 +104,7 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { try { await channel.invokeMethod( 'RemoteConfig#ensureInitialized', { - 'appName': app!.name, + 'appName': app.name, }); } catch (exception, stackTrace) { throw convertPlatformException(exception, stackTrace); @@ -118,7 +116,7 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { try { bool? configChanged = await channel .invokeMethod('RemoteConfig#activate', { - 'appName': app!.name, + 'appName': app.name, }); await _updateConfigParameters(); return configChanged!; @@ -131,7 +129,7 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { Future fetch() async { try { await channel.invokeMethod('RemoteConfig#fetch', { - 'appName': app!.name, + 'appName': app.name, }); await _updateConfigProperties(); } catch (exception, stackTrace) { @@ -146,7 +144,7 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { try { bool? configChanged = await channel.invokeMethod( 'RemoteConfig#fetchAndActivate', { - 'appName': app!.name, + 'appName': app.name, }); await _updateConfigParameters(); await _updateConfigProperties(); @@ -205,11 +203,12 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { @override Future setConfigSettings( - RemoteConfigSettings remoteConfigSettings) async { + RemoteConfigSettings remoteConfigSettings, + ) async { try { await channel .invokeMethod('RemoteConfig#setConfigSettings', { - 'appName': app!.name, + 'appName': app.name, 'fetchTimeout': remoteConfigSettings.fetchTimeout.inSeconds, 'minimumFetchInterval': remoteConfigSettings.minimumFetchInterval.inSeconds, @@ -224,7 +223,7 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { Future setDefaults(Map defaultParameters) async { try { await channel.invokeMethod('RemoteConfig#setDefaults', { - 'appName': app!.name, + 'appName': app.name, 'defaults': defaultParameters }); await _updateConfigParameters(); @@ -237,7 +236,7 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { Map? parameters = await channel .invokeMapMethod( 'RemoteConfig#getAll', { - 'appName': app!.name, + 'appName': app.name, }); _activeParameters = _parseParameters(parameters!); } @@ -246,7 +245,7 @@ class MethodChannelFirebaseRemoteConfig extends FirebaseRemoteConfigPlatform { Map? properties = await channel .invokeMapMethod( 'RemoteConfig#getProperties', { - 'appName': app!.name, + 'appName': app.name, }); final fetchTimeout = Duration(seconds: properties!['fetchTimeout']); final minimumFetchInterval = diff --git a/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/method_channel/utils/exception.dart b/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/method_channel/utils/exception.dart index 5000167db095..63f6a6f4ab50 100644 --- a/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/method_channel/utils/exception.dart +++ b/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/method_channel/utils/exception.dart @@ -21,8 +21,9 @@ Exception convertPlatformException(Object exception, [StackTrace? stackTrace]) { /// `details` of the exception exist. Firebase returns specific codes and messages /// which can be converted into user friendly exceptions. FirebaseException platformExceptionToFirebaseException( - PlatformException platformException, - [StackTrace? stackTrace]) { + PlatformException platformException, [ + StackTrace? stackTrace, +]) { Map? details = platformException.details != null ? Map.from(platformException.details) : null; diff --git a/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/platform_interface/platform_interface_firebase_remote_config.dart b/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/platform_interface/platform_interface_firebase_remote_config.dart index 6824a85e941f..cf03ac9e91f8 100644 --- a/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/platform_interface/platform_interface_firebase_remote_config.dart +++ b/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/platform_interface/platform_interface_firebase_remote_config.dart @@ -23,11 +23,11 @@ abstract class FirebaseRemoteConfigPlatform extends PlatformInterface { /// Create instance using [app] using the existing implementation. factory FirebaseRemoteConfigPlatform.instanceFor({ - FirebaseApp? app, + required FirebaseApp app, Map? pluginConstants, }) { return FirebaseRemoteConfigPlatform.instance - .delegateFor(app: app!) + .delegateFor(app: app) .setInitialValues( remoteConfigValues: pluginConstants ?? {}, ); @@ -35,18 +35,6 @@ abstract class FirebaseRemoteConfigPlatform extends PlatformInterface { static final Object _token = Object(); - /// The [FirebaseApp] this instance was initialized with. - @protected - final FirebaseApp? appInstance; - - /// Returns the [FirebaseApp] for the current instance. - FirebaseApp? get app { - if (appInstance == null) { - return Firebase.app(); - } - return appInstance; - } - static FirebaseRemoteConfigPlatform? _instance; /// The current default [FirebaseRemoteConfigPlatform] instance. @@ -63,6 +51,13 @@ abstract class FirebaseRemoteConfigPlatform extends PlatformInterface { _instance = instance; } + /// The [FirebaseApp] this instance was initialized with. + @protected + final FirebaseApp? appInstance; + + /// Returns the [FirebaseApp] for the current instance. + late final FirebaseApp app = appInstance ?? Firebase.app(); + /// Enables delegates to create new instances of themselves if a none /// default [FirebaseApp] instance is required by the user. @protected @@ -76,8 +71,9 @@ abstract class FirebaseRemoteConfigPlatform extends PlatformInterface { /// available before the instance has initialized to prevent unnecessary /// async calls. @protected - FirebaseRemoteConfigPlatform setInitialValues( - {required Map remoteConfigValues}) { + FirebaseRemoteConfigPlatform setInitialValues({ + required Map remoteConfigValues, + }) { throw UnimplementedError('setInitialValues() is not implemented'); } diff --git a/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/remote_config_value.dart b/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/remote_config_value.dart index cd47eafaeeec..b6c3f140e308 100644 --- a/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/remote_config_value.dart +++ b/packages/firebase_remote_config/firebase_remote_config_platform_interface/lib/src/remote_config_value.dart @@ -40,15 +40,17 @@ class RemoteConfigValue { /// Decode value to string. String asString() { - return _value != null - ? const Utf8Codec().decode(_value!) + final value = _value; + return value != null + ? const Utf8Codec().decode(value) : defaultValueForString; } /// Decode value to int. int asInt() { - if (_value != null) { - final String strValue = const Utf8Codec().decode(_value!); + final value = _value; + if (value != null) { + final String strValue = const Utf8Codec().decode(value); final int intValue = int.tryParse(strValue) ?? defaultValueForInt; return intValue; } else { @@ -58,8 +60,9 @@ class RemoteConfigValue { /// Decode value to double. double asDouble() { - if (_value != null) { - final String strValue = const Utf8Codec().decode(_value!); + final value = _value; + if (value != null) { + final String strValue = const Utf8Codec().decode(value); final double doubleValue = double.tryParse(strValue) ?? defaultValueForDouble; return doubleValue; @@ -70,8 +73,9 @@ class RemoteConfigValue { /// Decode value to bool. bool asBool() { - if (_value != null) { - final String strValue = const Utf8Codec().decode(_value!); + final value = _value; + if (value != null) { + final String strValue = const Utf8Codec().decode(value); final lowerCase = strValue.toLowerCase(); return lowerCase == 'true' || lowerCase == '1'; } else { From bd27c086284e7acf7a114304f240eb3c915510eb Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Wed, 7 Apr 2021 15:10:21 +0100 Subject: [PATCH 3/8] migrate example to nnbd --- .../firebase_remote_config/example/lib/main.dart | 8 ++++---- .../firebase_remote_config/example/pubspec.yaml | 5 +++-- .../example/test_driver/firebase_remote_config_e2e.dart | 8 +++----- .../test_driver/firebase_remote_config_e2e_test.dart | 6 ++---- 4 files changed, 12 insertions(+), 15 deletions(-) diff --git a/packages/firebase_remote_config/firebase_remote_config/example/lib/main.dart b/packages/firebase_remote_config/firebase_remote_config/example/lib/main.dart index 1165a2f0a502..3eed2cd3ffb7 100644 --- a/packages/firebase_remote_config/firebase_remote_config/example/lib/main.dart +++ b/packages/firebase_remote_config/firebase_remote_config/example/lib/main.dart @@ -2,8 +2,6 @@ // Use of this source code is governed by a BSD-style license that can be // found in the LICENSE file. -// @dart=2.9 - import 'dart:async'; import 'package:firebase_core/firebase_core.dart'; @@ -19,14 +17,16 @@ void main() { future: setupRemoteConfig(), builder: (BuildContext context, AsyncSnapshot snapshot) { return snapshot.hasData - ? WelcomeWidget(remoteConfig: snapshot.data) + ? WelcomeWidget(remoteConfig: snapshot.requireData) : Container(); }, ))); } class WelcomeWidget extends AnimatedWidget { - WelcomeWidget({this.remoteConfig}) : super(listenable: remoteConfig); + WelcomeWidget({ + required this.remoteConfig, + }) : super(listenable: remoteConfig); final RemoteConfig remoteConfig; diff --git a/packages/firebase_remote_config/firebase_remote_config/example/pubspec.yaml b/packages/firebase_remote_config/firebase_remote_config/example/pubspec.yaml index 95ec77de1f13..a3dc76174690 100644 --- a/packages/firebase_remote_config/firebase_remote_config/example/pubspec.yaml +++ b/packages/firebase_remote_config/firebase_remote_config/example/pubspec.yaml @@ -27,13 +27,14 @@ dependency_overrides: path: ../../firebase_remote_config_platform_interface dev_dependencies: - pedantic: ^1.8.0 + integration_test: + sdk: flutter flutter_test: sdk: flutter flutter_driver: sdk: flutter + pedantic: ^1.8.0 test: any - e2e: ^0.6.1 flutter: uses-material-design: true diff --git a/packages/firebase_remote_config/firebase_remote_config/example/test_driver/firebase_remote_config_e2e.dart b/packages/firebase_remote_config/firebase_remote_config/example/test_driver/firebase_remote_config_e2e.dart index 680665ce11ff..e38460ba2238 100644 --- a/packages/firebase_remote_config/firebase_remote_config/example/test_driver/firebase_remote_config_e2e.dart +++ b/packages/firebase_remote_config/firebase_remote_config/example/test_driver/firebase_remote_config_e2e.dart @@ -1,15 +1,13 @@ -// @dart=2.9 - import 'package:flutter_test/flutter_test.dart'; -import 'package:e2e/e2e.dart'; +import 'package:integration_test/integration_test_driver.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_remote_config/firebase_remote_config.dart'; void main() { - E2EWidgetsFlutterBinding.ensureInitialized(); + IntegrationTestWidgetsFlutterBinding.ensureInitialized(); group('$RemoteConfig', () { - RemoteConfig remoteConfig; + late RemoteConfig remoteConfig; setUp(() async { await Firebase.initializeApp(); diff --git a/packages/firebase_remote_config/firebase_remote_config/example/test_driver/firebase_remote_config_e2e_test.dart b/packages/firebase_remote_config/firebase_remote_config/example/test_driver/firebase_remote_config_e2e_test.dart index 6c140ccf7fe0..59f40c3b50a1 100644 --- a/packages/firebase_remote_config/firebase_remote_config/example/test_driver/firebase_remote_config_e2e_test.dart +++ b/packages/firebase_remote_config/firebase_remote_config/example/test_driver/firebase_remote_config_e2e_test.dart @@ -2,8 +2,6 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. -// @dart=2.9 +import 'package:integration_test/integration_test_driver.dart'; -import 'package:e2e/e2e_driver.dart' as e2e; - -void main() => e2e.main(); +Future main() => integrationDriver(); From 35a3229a69eeab3244896d2a372b8cbf635e8d7f Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Wed, 7 Apr 2021 15:23:21 +0100 Subject: [PATCH 4/8] fix import --- .../example/test_driver/firebase_remote_config_e2e.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase_remote_config/firebase_remote_config/example/test_driver/firebase_remote_config_e2e.dart b/packages/firebase_remote_config/firebase_remote_config/example/test_driver/firebase_remote_config_e2e.dart index e38460ba2238..84e1d81cec2e 100644 --- a/packages/firebase_remote_config/firebase_remote_config/example/test_driver/firebase_remote_config_e2e.dart +++ b/packages/firebase_remote_config/firebase_remote_config/example/test_driver/firebase_remote_config_e2e.dart @@ -1,5 +1,5 @@ import 'package:flutter_test/flutter_test.dart'; -import 'package:integration_test/integration_test_driver.dart'; +import 'package:integration_test/integration_test.dart'; import 'package:firebase_core/firebase_core.dart'; import 'package:firebase_remote_config/firebase_remote_config.dart'; From 509f0a41f002750145e48054834662fd265df31a Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Thu, 8 Apr 2021 01:39:23 +0100 Subject: [PATCH 5/8] remove e2e in java files --- .../EmbeddingV1Activity.java | 2 -- .../EmbeddingV1ActivityTest.java | 17 ----------------- 2 files changed, 19 deletions(-) delete mode 100644 packages/firebase_remote_config/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1ActivityTest.java diff --git a/packages/firebase_remote_config/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java b/packages/firebase_remote_config/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java index 31cff2e8415b..bdbb90107a9d 100644 --- a/packages/firebase_remote_config/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java +++ b/packages/firebase_remote_config/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1Activity.java @@ -5,7 +5,6 @@ package io.flutter.plugins.firebase.firebaseremoteconfigexample; import android.os.Bundle; -import dev.flutter.plugins.e2e.E2EPlugin; import io.flutter.app.FlutterActivity; import io.flutter.plugins.firebase.core.FlutterFirebaseCorePlugin; import io.flutter.plugins.firebase.firebaseremoteconfig.FirebaseRemoteConfigPlugin; @@ -19,6 +18,5 @@ protected void onCreate(Bundle savedInstanceState) { FirebaseRemoteConfigPlugin.registerWith( registrarFor( "io.flutter.plugins.firebase.firebaseremoteconfig.FirebaseRemoteConfigPlugin")); - E2EPlugin.registerWith(registrarFor("dev.flutter.plugins.e2e.E2EPlugin")); } } diff --git a/packages/firebase_remote_config/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1ActivityTest.java b/packages/firebase_remote_config/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1ActivityTest.java deleted file mode 100644 index 1b7b2032ea2f..000000000000 --- a/packages/firebase_remote_config/firebase_remote_config/example/android/app/src/main/java/io/flutter/plugins/firebase/firebaseremoteconfigexample/EmbeddingV1ActivityTest.java +++ /dev/null @@ -1,17 +0,0 @@ -// Copyright 2019 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -package io.flutter.plugins.firebase.firebaseremoteconfigexample; - -import androidx.test.rule.ActivityTestRule; -import dev.flutter.plugins.e2e.FlutterTestRunner; -import org.junit.Rule; -import org.junit.runner.RunWith; - -@RunWith(FlutterTestRunner.class) -public class EmbeddingV1ActivityTest { - @Rule - public ActivityTestRule rule = - new ActivityTestRule<>(EmbeddingV1Activity.class); -} From d0534bbba5e40a30a18de33c15343a60af707b5f Mon Sep 17 00:00:00 2001 From: Remi Rousselet Date: Mon, 12 Apr 2021 14:51:19 +0100 Subject: [PATCH 6/8] return valid boolean for fetchAndActivate --- .../ios/Classes/FLTFirebaseRemoteConfigPlugin.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase_remote_config/firebase_remote_config/ios/Classes/FLTFirebaseRemoteConfigPlugin.m b/packages/firebase_remote_config/firebase_remote_config/ios/Classes/FLTFirebaseRemoteConfigPlugin.m index 7398e9fbf490..ab62956bce34 100644 --- a/packages/firebase_remote_config/firebase_remote_config/ios/Classes/FLTFirebaseRemoteConfigPlugin.m +++ b/packages/firebase_remote_config/firebase_remote_config/ios/Classes/FLTFirebaseRemoteConfigPlugin.m @@ -163,7 +163,7 @@ - (void)fetchAndActivate:(id)arguments withMethodCallResult:(FLTFirebaseMethodCa if (error != nil) { result.error(nil, nil, nil, error); } else { - result.success(nil); + result.success(status == FIRRemoteConfigFetchAndActivateStatusSuccessFetchedFromRemote); } }]; } From 46e2291b05c24bb9058808e4b78e94032cbe14f4 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Tue, 13 Apr 2021 11:33:16 +0100 Subject: [PATCH 7/8] fix(remote_config, ios): conditional result update --- .../ios/Classes/FLTFirebaseRemoteConfigPlugin.m | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/packages/firebase_remote_config/firebase_remote_config/ios/Classes/FLTFirebaseRemoteConfigPlugin.m b/packages/firebase_remote_config/firebase_remote_config/ios/Classes/FLTFirebaseRemoteConfigPlugin.m index ab62956bce34..a25103db2dd9 100644 --- a/packages/firebase_remote_config/firebase_remote_config/ios/Classes/FLTFirebaseRemoteConfigPlugin.m +++ b/packages/firebase_remote_config/firebase_remote_config/ios/Classes/FLTFirebaseRemoteConfigPlugin.m @@ -163,7 +163,11 @@ - (void)fetchAndActivate:(id)arguments withMethodCallResult:(FLTFirebaseMethodCa if (error != nil) { result.error(nil, nil, nil, error); } else { - result.success(status == FIRRemoteConfigFetchAndActivateStatusSuccessFetchedFromRemote); + if(status == FIRRemoteConfigFetchAndActivateStatusSuccessFetchedFromRemote) { + result.success(@(YES)); + } else { + result.success(@(NO)); + } } }]; } From d72e7877db25a5dfeeecfe926fece679125d4300 Mon Sep 17 00:00:00 2001 From: russellwheatley Date: Tue, 13 Apr 2021 11:42:59 +0100 Subject: [PATCH 8/8] format code --- .../ios/Classes/FLTFirebaseRemoteConfigPlugin.m | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/packages/firebase_remote_config/firebase_remote_config/ios/Classes/FLTFirebaseRemoteConfigPlugin.m b/packages/firebase_remote_config/firebase_remote_config/ios/Classes/FLTFirebaseRemoteConfigPlugin.m index a25103db2dd9..cd6a71227473 100644 --- a/packages/firebase_remote_config/firebase_remote_config/ios/Classes/FLTFirebaseRemoteConfigPlugin.m +++ b/packages/firebase_remote_config/firebase_remote_config/ios/Classes/FLTFirebaseRemoteConfigPlugin.m @@ -163,7 +163,7 @@ - (void)fetchAndActivate:(id)arguments withMethodCallResult:(FLTFirebaseMethodCa if (error != nil) { result.error(nil, nil, nil, error); } else { - if(status == FIRRemoteConfigFetchAndActivateStatusSuccessFetchedFromRemote) { + if (status == FIRRemoteConfigFetchAndActivateStatusSuccessFetchedFromRemote) { result.success(@(YES)); } else { result.success(@(NO));