Skip to content
Merged
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
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -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
Expand Down
43 changes: 15 additions & 28 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -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());
Expand Down Expand Up @@ -61,34 +59,24 @@ class HomePage extends StatefulWidget {
}

class _HomePageState extends State<HomePage> {
final Dio _dio = Dio();

@override
void initState() {
super.initState();
_dio.interceptors.add(SmartRatingDioInterceptor());
}

// --- Simulation Methods ---

Future<void> _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<void> _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
}

Expand All @@ -102,9 +90,6 @@ class _HomePageState extends State<HomePage> {

Future<void> _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<void> _showIfMinSuccessReached() async {
Expand All @@ -127,11 +112,13 @@ class _HomePageState extends State<HomePage> {
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),
);
}
},
Expand Down Expand Up @@ -159,7 +146,7 @@ class _HomePageState extends State<HomePage> {

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,
),
Expand All @@ -176,7 +163,7 @@ class _HomePageState extends State<HomePage> {
child: Column(
children: [
const Text(
'📊 Network Stats',
'📊 Manual Stats Simulation',
style: TextStyle(
fontSize: 18,
fontWeight: FontWeight.bold,
Expand Down Expand Up @@ -217,7 +204,7 @@ class _HomePageState extends State<HomePage> {

// --- Simulation Controls ---
const Text(
'1. Network Simulation',
'1. Manual Reporting Simulation',
style: TextStyle(fontSize: 16, fontWeight: FontWeight.bold),
),
const SizedBox(height: 8),
Expand All @@ -227,7 +214,7 @@ class _HomePageState extends State<HomePage> {
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,
),
Expand All @@ -238,7 +225,7 @@ class _HomePageState extends State<HomePage> {
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),
),
),
Expand Down
66 changes: 13 additions & 53 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down Expand Up @@ -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:
Expand Down
4 changes: 0 additions & 4 deletions example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
53 changes: 34 additions & 19 deletions lib/src/network/README.md
Original file line number Diff line number Diff line change
@@ -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();
}
```
23 changes: 0 additions & 23 deletions lib/src/network/smart_rating_dio_interceptor.dart

This file was deleted.

5 changes: 3 additions & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
@@ -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:
Expand Down
Loading