|
| 1 | +# Migration Guide: v2 to v3 |
| 2 | + |
| 3 | +This major release removed the dependency on the |
| 4 | +[`connectivity_plus`](https://pub.dev/packages/connectivity_plus) package, |
| 5 | +converting this library into a pure Dart package. If your application relied on |
| 6 | +hardware network connectivity changes to quickly trigger internet reachability |
| 7 | +checks, you must now pass a trigger stream explicitly. |
| 8 | + |
| 9 | +## Breaking Changes |
| 10 | + |
| 11 | +- Automatic listening to network hardware changes (e.g. Wi-Fi turning off) is no |
| 12 | + longer enabled by default since we no longer depend on `connectivity_plus`. |
| 13 | + |
| 14 | +## Migration Steps |
| 15 | + |
| 16 | +If you want to maintain the exact same behavior from `v2.x.x`, follow these |
| 17 | +steps: |
| 18 | + |
| 19 | +### 1. Add `connectivity_plus` to your pubspec.yaml |
| 20 | + |
| 21 | +Since it is no longer bundled with our package, you must install it directly. |
| 22 | + |
| 23 | +```yaml |
| 24 | +dependencies: |
| 25 | + internet_connection_checker_plus: ^3.0.0 |
| 26 | + connectivity_plus: ^7.0.0 # or latest |
| 27 | +``` |
| 28 | +
|
| 29 | +### 2. Pass the trigger stream to `InternetConnection` |
| 30 | + |
| 31 | +When you create or configure the internet connection, use the `createInstance` |
| 32 | +method and pass `Connectivity().onConnectivityChanged` to the new |
| 33 | +`triggerStream` parameter. |
| 34 | + |
| 35 | +**Before (v2):** |
| 36 | + |
| 37 | +```dart |
| 38 | +import 'package:internet_connection_checker_plus/internet_connection_checker_plus.dart'; |
| 39 | +
|
| 40 | +final connection = InternetConnection(); |
| 41 | +``` |
| 42 | + |
| 43 | +**After (v3):** |
| 44 | + |
| 45 | +```dart |
| 46 | +import 'package:internet_connection_checker_plus/internet_connection_checker_plus.dart'; |
| 47 | +import 'package:connectivity_plus/connectivity_plus.dart'; |
| 48 | +
|
| 49 | +final connection = InternetConnection.createInstance( |
| 50 | + triggerStream: Connectivity().onConnectivityChanged, |
| 51 | +); |
| 52 | +``` |
| 53 | + |
| 54 | +By providing a `triggerStream`, `InternetConnection` will instantly execute a |
| 55 | +ping reachability check whenever `connectivity_plus` emits an event, ensuring |
| 56 | +your users get the most accurate and real-time connectivity status. |
0 commit comments