barcode_scanner/lib/services/connectivity_service.dart
your-name db71578ded feat: Improves data synchronization and connectivity UI
Implements automatic synchronization of unsynced local reception data (move line quantities) to the backend before fetching new receptions. This ensures local changes are pushed when connectivity is available.

Adds a pull-to-refresh mechanism on the reception page, allowing users to manually refresh the list of receptions.

Integrates an offline indicator in the main app bar, providing immediate visual feedback on the application's network connectivity status.
2025-07-31 04:00:06 +03:00

38 lines
1.1 KiB
Dart

import 'dart:async';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
/// Provider qui retourne un booléen: connecté ou non
final isConnectedProvider =
StateNotifierProvider<ConnectivityBoolNotifier, bool>(
(ref) => ConnectivityBoolNotifier(),
);
class ConnectivityBoolNotifier extends StateNotifier<bool> {
ConnectivityBoolNotifier() : super(false) {
_init();
_subscription = Connectivity().onConnectivityChanged.listen(
(results) => state = _isConnected(results),
);
}
late final StreamSubscription<List<ConnectivityResult>> _subscription;
Future<void> _init() async {
final result = await Connectivity().checkConnectivity();
state = _isConnected(result);
}
bool _isConnected(List<ConnectivityResult> result) {
return (result).contains(ConnectivityResult.mobile) ||
(result).contains(ConnectivityResult.wifi) ||
(result).contains(ConnectivityResult.vpn) ||
(result).contains(ConnectivityResult.ethernet);
}
@override
void dispose() {
_subscription.cancel();
super.dispose();
}
}