mirror of
https://github.com/twonlyapp/twonly-app.git
synced 2026-05-25 05:22:13 +00:00
27 lines
759 B
Dart
27 lines
759 B
Dart
import 'dart:async';
|
|
import 'package:flutter/foundation.dart';
|
|
import 'package:twonly/locator.dart';
|
|
|
|
class CustomChangeProvider with ChangeNotifier, DiagnosticableTreeMixin {
|
|
CustomChangeProvider() {
|
|
// The API is connected before the subscription has started so ensure that the connection state is correct
|
|
_isConnected = apiService.isConnected;
|
|
_connSub = apiService.onConnectionStateUpdated.listen(
|
|
updateConnectionState,
|
|
);
|
|
}
|
|
late bool _isConnected;
|
|
late StreamSubscription<bool> _connSub;
|
|
bool get isConnected => _isConnected;
|
|
|
|
@override
|
|
void dispose() {
|
|
_connSub.cancel();
|
|
super.dispose();
|
|
}
|
|
|
|
Future<void> updateConnectionState(bool update) async {
|
|
_isConnected = update;
|
|
notifyListeners();
|
|
}
|
|
}
|