diff --git a/CHANGELOG.md b/CHANGELOG.md index c688b4f..6b78b92 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,8 @@ +## 0.0.4 + +* **Breaking Change**: Removed `dio` dependency and `SmartRatingDioInterceptor`. Applications should now manually report network activity or implement their own interceptor (see `lib/src/network/README.md` for examples). +* **Configuration**: Updated SDK constraints and project metadata. + ## 0.0.3 ### ✨ New Features diff --git a/example/lib/main.dart b/example/lib/main.dart index 6c80d7d..c4f7745 100644 --- a/example/lib/main.dart +++ b/example/lib/main.dart @@ -1,7 +1,5 @@ import 'package:flutter/material.dart'; import 'package:dt_flutter_smart_rating/dt_flutter_smart_rating.dart'; -import 'package:dt_flutter_smart_rating/src/network/smart_rating_dio_interceptor.dart'; -import 'package:dio/dio.dart'; void main() { runApp(const MyApp()); @@ -61,34 +59,24 @@ class HomePage extends StatefulWidget { } class _HomePageState extends State { - final Dio _dio = Dio(); - @override void initState() { super.initState(); - _dio.interceptors.add(SmartRatingDioInterceptor()); } // --- Simulation Methods --- Future _simulateSuccess() async { - try { - // Mocking a successful request - await _dio.get('https://mock.httpstatus.io/200'); - _showSnackbar('Request Success! (+1 Success)'); - } catch (e) { - debugPrint('Error: $e'); - } + // Manually reporting success + SmartRating().reportNetworkSuccess(); + _showSnackbar('Request Success Reported! (+1 Success)'); setState(() {}); // Update UI to show new stats } Future _simulateFailure() async { - try { - // Mocking a failed request - await _dio.get('https://mock.httpstatus.io/500'); - } catch (e) { - _showSnackbar('Request Failed! (+1 Failure, Success Reset)'); - } + // Manually reporting failure + SmartRating().reportNetworkFailure(); + _showSnackbar('Request Failure Reported! (+1 Failure, Success Reset)'); setState(() {}); // Update UI to show new stats } @@ -102,9 +90,6 @@ class _HomePageState extends State { Future _showOnlyIfNoFailures() async { await SmartRating().showRatingDialog(onlyIfNoFailures: true); - // Dialog handles its own display logic. If it doesn't show, it logs to console. - // We can't easily know if it showed or not without complex logic, - // but the user will see the dialog if conditions met. } Future _showIfMinSuccessReached() async { @@ -127,11 +112,13 @@ class _HomePageState extends State { await Future.delayed(const Duration(seconds: 1)); if (!mounted) return; Navigator.of(context).pop(); // Close the dialog - if (SmartRating().config != null) { + + final config = SmartRating().config; + if (config != null) { await showDialog( context: context, barrierDismissible: false, - builder: (context) => ThankYouDialog(config: SmartRating().config!), + builder: (context) => ThankYouDialog(config: config), ); } }, @@ -159,7 +146,7 @@ class _HomePageState extends State { return Scaffold( appBar: AppBar( - title: const Text('Smart Rating v0.0.2 Demo'), + title: const Text('Smart Rating Demo'), centerTitle: true, backgroundColor: Theme.of(context).colorScheme.inversePrimary, ), @@ -176,7 +163,7 @@ class _HomePageState extends State { child: Column( children: [ const Text( - '📊 Network Stats', + '📊 Manual Stats Simulation', style: TextStyle( fontSize: 18, fontWeight: FontWeight.bold, @@ -217,7 +204,7 @@ class _HomePageState extends State { // --- Simulation Controls --- const Text( - '1. Network Simulation', + '1. Manual Reporting Simulation', style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold), ), const SizedBox(height: 8), @@ -227,7 +214,7 @@ class _HomePageState extends State { child: FilledButton.icon( onPressed: _simulateSuccess, icon: const Icon(Icons.check_circle), - label: const Text('Success (+1)'), + label: const Text('Report Success'), style: FilledButton.styleFrom( backgroundColor: Colors.green, ), @@ -238,7 +225,7 @@ class _HomePageState extends State { child: FilledButton.icon( onPressed: _simulateFailure, icon: const Icon(Icons.error), - label: const Text('Failure (+1)'), + label: const Text('Report Failure'), style: FilledButton.styleFrom(backgroundColor: Colors.red), ), ), diff --git a/example/pubspec.lock b/example/pubspec.lock index 2f064e6..49160c5 100644 --- a/example/pubspec.lock +++ b/example/pubspec.lock @@ -49,29 +49,13 @@ packages: url: "https://pub.dev" source: hosted version: "1.0.8" - dio: - dependency: "direct main" - description: - name: dio - sha256: d90ee57923d1828ac14e492ca49440f65477f4bb1263575900be731a3dac66a9 - url: "https://pub.dev" - source: hosted - version: "5.9.0" - dio_web_adapter: - dependency: transitive - description: - name: dio_web_adapter - sha256: "7586e476d70caecaf1686d21eee7247ea43ef5c345eab9e0cc3583ff13378d78" - url: "https://pub.dev" - source: hosted - version: "2.1.1" dt_flutter_smart_rating: dependency: "direct main" description: path: ".." relative: true source: path - version: "0.0.2" + version: "0.0.4" fake_async: dependency: transitive description: @@ -119,38 +103,30 @@ packages: description: flutter source: sdk version: "0.0.0" - http_parser: - dependency: transitive - description: - name: http_parser - sha256: "178d74305e7866013777bab2c3d8726205dc5a4dd935297175b19a23a2e66571" - url: "https://pub.dev" - source: hosted - version: "4.1.2" leak_tracker: dependency: transitive description: name: leak_tracker - sha256: "6bb818ecbdffe216e81182c2f0714a2e62b593f4a4f13098713ff1685dfb6ab0" + sha256: "33e2e26bdd85a0112ec15400c8cbffea70d0f9c3407491f672a2fad47915e2de" url: "https://pub.dev" source: hosted - version: "10.0.9" + version: "11.0.2" leak_tracker_flutter_testing: dependency: transitive description: name: leak_tracker_flutter_testing - sha256: f8b613e7e6a13ec79cfdc0e97638fddb3ab848452eff057653abd3edba760573 + sha256: "1dbc140bb5a23c75ea9c4811222756104fbcd1a27173f0c34ca01e16bea473c1" url: "https://pub.dev" source: hosted - version: "3.0.9" + version: "3.0.10" leak_tracker_testing: dependency: transitive description: name: leak_tracker_testing - sha256: "6ba465d5d76e67ddf503e1161d1f4a6bc42306f9d66ca1e8f079a47290fb06d3" + sha256: "8d5a2d49f4a66b49744b23b018848400d23e54caf9463f4eb20df3eb8acb2eb1" url: "https://pub.dev" source: hosted - version: "3.0.1" + version: "3.0.2" lints: dependency: transitive description: @@ -179,18 +155,10 @@ packages: dependency: transitive description: name: meta - sha256: e3641ec5d63ebf0d9b41bd43201a66e3fc79a65db5f61fc181f04cd27aab950c - url: "https://pub.dev" - source: hosted - version: "1.16.0" - mime: - dependency: transitive - description: - name: mime - sha256: "41a20518f0cb1256669420fdba0cd90d21561e560ac240f26ef8322e45bb7ed6" + sha256: "23f08335362185a5ea2ad3a4e597f1375e78bce8a040df5c600c8d3552ef2394" url: "https://pub.dev" source: hosted - version: "2.0.0" + version: "1.17.0" path: dependency: transitive description: @@ -344,18 +312,10 @@ packages: dependency: transitive description: name: test_api - sha256: fb31f383e2ee25fbbfe06b40fe21e1e458d14080e3c67e7ba0acfde4df4e0bbd + sha256: ab2726c1a94d3176a45960b6234466ec367179b87dd74f1611adb1f3b5fb9d55 url: "https://pub.dev" source: hosted - version: "0.7.4" - typed_data: - dependency: transitive - description: - name: typed_data - sha256: f9049c039ebfeb4cf7a7104a675823cd72dba8297f264b6637062516699fa006 - url: "https://pub.dev" - source: hosted - version: "1.4.0" + version: "0.7.7" url_launcher: dependency: transitive description: @@ -424,10 +384,10 @@ packages: dependency: transitive description: name: vector_math - sha256: "80b3257d1492ce4d091729e3a67a60407d227c27241d6927be0130c98e741803" + sha256: d530bd74fea330e6e364cda7a85019c434070188383e1cd8d9777ee586914c5b url: "https://pub.dev" source: hosted - version: "2.1.4" + version: "2.2.0" vm_service: dependency: transitive description: diff --git a/example/pubspec.yaml b/example/pubspec.yaml index 1e39139..1af319a 100644 --- a/example/pubspec.yaml +++ b/example/pubspec.yaml @@ -32,10 +32,6 @@ dependencies: sdk: flutter dt_flutter_smart_rating: path: ../ - dio: ^5.4.1 - - # The following adds the Cupertino Icons font to your application. - # Use with the CupertinoIcons class for iOS style icons. cupertino_icons: ^1.0.8 dev_dependencies: diff --git a/lib/src/network/README.md b/lib/src/network/README.md index 012288c..e1b69d5 100644 --- a/lib/src/network/README.md +++ b/lib/src/network/README.md @@ -1,33 +1,48 @@ # Network Monitoring -## Dio Interceptor +To report network activity to `SmartRating`, simply call the manual reporting methods in your network layer: -The `SmartRatingDioInterceptor` is provided for convenience if your project uses Dio. +### Basic Usage -### Important: Optional Dependency - -**Dio is NOT a required dependency of this package.** If you want to use the Dio interceptor, you must add Dio to your app's `pubspec.yaml`: +```dart +// On successful response (2xx) +SmartRating().reportNetworkSuccess(); -```yaml -dependencies: - dio: ^5.4.1 # or your preferred version +// On error response +SmartRating().reportNetworkFailure(); ``` -### Usage +### Integration Examples + +#### Using Dio +If you use [Dio](https://pub.dev/packages/dio), you can add a simple interceptor in your own codebase: ```dart +class SmartRatingInterceptor extends Interceptor { + @override + void onResponse(Response response, ResponseInterceptorHandler handler) { + SmartRating().reportNetworkSuccess(); + super.onResponse(response, handler); + } + + @override + void onError(DioException err, ErrorInterceptorHandler handler) { + SmartRating().reportNetworkFailure(); + super.onError(err, handler); + } +} + +// Then add it to your dio instance: final dio = Dio(); -dio.interceptors.add(SmartRatingDioInterceptor()); +dio.interceptors.add(SmartRatingInterceptor()); ``` -### For Other HTTP Clients - -If you use a different HTTP client (http, chopper, etc.), simply call the manual reporting methods: - +#### Using http package ```dart -// On successful response (2xx) -SmartRating().reportNetworkSuccess(); - -// On error response -SmartRating().reportNetworkFailure(); +final response = await http.get(Uri.parse('https://example.com')); +if (response.statusCode >= 200 && response.statusCode < 300) { + SmartRating().reportNetworkSuccess(); +} else { + SmartRating().reportNetworkFailure(); +} ``` diff --git a/lib/src/network/smart_rating_dio_interceptor.dart b/lib/src/network/smart_rating_dio_interceptor.dart deleted file mode 100644 index 37773d0..0000000 --- a/lib/src/network/smart_rating_dio_interceptor.dart +++ /dev/null @@ -1,23 +0,0 @@ -import 'package:dio/dio.dart'; -import '../core/smart_rating.dart'; - -class SmartRatingDioInterceptor extends Interceptor { - @override - void onResponse(Response response, ResponseInterceptorHandler handler) { - // Check if response is successful (2xx) - if (response.statusCode != null && - response.statusCode! >= 200 && - response.statusCode! < 300) { - SmartRating().reportNetworkSuccess(); - } else { - SmartRating().reportNetworkFailure(); - } - super.onResponse(response, handler); - } - - @override - void onError(DioException err, ErrorInterceptorHandler handler) { - SmartRating().reportNetworkFailure(); - super.onError(err, handler); - } -} diff --git a/pubspec.yaml b/pubspec.yaml index b0d8f4e..dc3700e 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -1,10 +1,11 @@ name: dt_flutter_smart_rating description: "A smart rating dialog package for Flutter that shows rating prompts based on network success and user experience quality." version: 0.0.4 -homepage: +homepage: https://github.com/gitunes/dt_flutter_smart_rating +repository: https://github.com/gitunes/dt_flutter_smart_rating environment: - sdk: '>=2.17.0 <3.0.0' + sdk: '>=2.17.0 <4.0.0' flutter: ">=1.17.0" dependencies: