veilidchat/lib/providers/connection_state.dart

30 lines
1.0 KiB
Dart
Raw Normal View History

2023-07-26 17:42:11 -04:00
import 'package:flutter_riverpod/flutter_riverpod.dart';
2023-10-21 19:23:43 -04:00
import 'package:freezed_annotation/freezed_annotation.dart';
2023-07-26 14:20:29 -04:00
2023-10-21 19:23:43 -04:00
import '../veilid_support/veilid_support.dart';
part 'connection_state.freezed.dart';
@freezed
class ConnectionState with _$ConnectionState {
const factory ConnectionState({
required VeilidStateAttachment attachment,
}) = _ConnectionState;
const ConnectionState._();
bool get isAttached => !(attachment.state == AttachmentState.detached ||
attachment.state == AttachmentState.detaching ||
attachment.state == AttachmentState.attaching);
bool get isPublicInternetReady => attachment.publicInternetReady;
2023-01-10 21:04:18 -05:00
}
2023-10-21 19:23:43 -04:00
final connectionState = StateController<ConnectionState>(const ConnectionState(
attachment: VeilidStateAttachment(
state: AttachmentState.detached,
publicInternetReady: false,
localNetworkReady: false)));
final connectionStateProvider =
StateNotifierProvider<StateController<ConnectionState>, ConnectionState>(
(ref) => connectionState);