From e566e5ebfe85360e0d38cba6116bb1c9188b7622 Mon Sep 17 00:00:00 2001 From: Dung Nguyen Minh <63831488+dungngminh@users.noreply.github.com> Date: Thu, 7 Nov 2024 23:03:57 +0700 Subject: [PATCH] feat: add support web (#4) --- CHANGELOG.md | 7 ++++++- lib/src/simple_remote_config.dart | 6 ++---- pubspec.lock | 2 +- pubspec.yaml | 2 +- test/simple_remote_config_test.dart | 19 +++++++++---------- 5 files changed, 19 insertions(+), 17 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 2834dbd..863b5e9 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,4 +1,9 @@ -## 1.0.3 (2024-11-06) +## 1.1.0 (2024-11-07) + +- Remove `dart:io` dependency to support web. +- Update more test. + +## 1.0.3 (2024-11-07) - Return `null` when provided `T` is incorrect. - Update more test. diff --git a/lib/src/simple_remote_config.dart b/lib/src/simple_remote_config.dart index c99b49e..bf56800 100644 --- a/lib/src/simple_remote_config.dart +++ b/lib/src/simple_remote_config.dart @@ -1,8 +1,7 @@ import 'dart:convert'; -import 'dart:io'; import 'package:http/http.dart'; -import 'package:simple_remote_config/src/simple_remote_config_exception.dart'; +import 'package:simple_remote_config/simple_remote_config.dart'; /// A [SimpleRemoteConfig] class that fetches a JSON config from a URL and /// provides a way to access the config values. @@ -43,8 +42,7 @@ class SimpleRemoteConfig { } catch (e) { throw SimpleRemoteConfigException( message: switch (e) { - SocketException() => 'No internet connection', - FormatException() => 'Invalid remote config format', + FormatException() => 'Invalid remote config', _ => 'Error when handling: $e', }); } diff --git a/pubspec.lock b/pubspec.lock index 540acaa..9301dd2 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -394,4 +394,4 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.4.0 <4.0.0" + dart: ">=3.5.0 <4.0.0" diff --git a/pubspec.yaml b/pubspec.yaml index e4b2467..f7500c8 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,6 +1,6 @@ name: simple_remote_config description: A simple plugin for helping you to change your application's behaviors, settings,.. without updating the application via network JSON. -version: 1.0.3 +version: 1.1.0 topics: [remote, config] issue_tracker: https://github.com/TheQuantumCrew/simple_remote_config/issues repository: https://github.com/TheQuantumCrew/simple_remote_config diff --git a/test/simple_remote_config_test.dart b/test/simple_remote_config_test.dart index 367165d..4346b6c 100644 --- a/test/simple_remote_config_test.dart +++ b/test/simple_remote_config_test.dart @@ -1,5 +1,3 @@ -import 'dart:io'; - import 'package:http/http.dart' as http; import 'package:http/testing.dart'; import 'package:simple_remote_config/src/simple_remote_config.dart'; @@ -90,10 +88,11 @@ void main() { ); }); - test('initialize throws SimpleRemoteConfigException on SocketException', + test( + 'initialize with invalid network JSON throws SimpleRemoteConfigException on FormatException', () async { final mockClient = MockClient((request) async { - throw SocketException('No internet connection'); + return http.Response('Invalid JSON', 200); }); final config = SimpleRemoteConfig(client: mockClient); @@ -101,11 +100,12 @@ void main() { () async => await config.initilize(configUrl: 'http://example.com/config'), throwsA(isA() - .having((e) => e.message, 'message', 'No internet connection')), + .having((e) => e.message, 'message', 'Invalid remote config')), ); }); - test('initialize throws SimpleRemoteConfigException on FormatException', + test( + 'initialize with invalid config url throws SimpleRemoteConfigException on FormatException', () async { final mockClient = MockClient((request) async { return http.Response('Invalid JSON', 200); @@ -113,10 +113,9 @@ void main() { final config = SimpleRemoteConfig(client: mockClient); expect( - () async => - await config.initilize(configUrl: 'http://example.com/config'), - throwsA(isA().having( - (e) => e.message, 'message', 'Invalid remote config format')), + () async => await config.initilize(configUrl: 'example.com/config'), + throwsA(isA() + .having((e) => e.message, 'message', 'Invalid remote config')), ); }); });