statenotifier

This commit is contained in:
Christien Rioux 2023-09-30 21:00:22 -04:00
parent 8f0b4aaba0
commit 7a49497620
15 changed files with 28 additions and 56 deletions

View file

@ -1,10 +1,10 @@
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:riverpod_annotation/riverpod_annotation.dart';
import '../proto/proto.dart' as proto;
import '../proto/proto.dart' show Chat, ChatType;
import '../tools/tools.dart';
import '../veilid_support/veilid_support.dart';
import 'account.dart';
@ -72,8 +72,8 @@ Future<void> deleteChat(
if (c.remoteConversationKey == remoteConversationKey) {
await chatList.tryRemoveItem(i);
if (activeChatState.currentState == remoteConversationRecordKey) {
activeChatState.add(null);
if (activeChatState.state == remoteConversationRecordKey) {
activeChatState.state = null;
}
return;
@ -113,7 +113,7 @@ Future<IList<Chat>?> fetchChatList(FetchChatListRef ref) async {
}
// The selected chat
ExternalStreamState<TypedKey?> activeChatState =
ExternalStreamState<TypedKey?>(null);
AutoDisposeStreamProvider<TypedKey?> activeChatStateProvider =
activeChatState.provider();
final activeChatState = StateController<TypedKey?>(null);
final activeChatStateProvider =
AutoDisposeStateNotifierProvider<StateController<TypedKey?>, TypedKey?>(
(ref) => activeChatState);

View file

@ -1,7 +1,5 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../tools/tools.dart';
enum GlobalConnectionState {
detached,
detaching,
@ -13,7 +11,8 @@ enum GlobalConnectionState {
overAttached,
}
ExternalStreamState<GlobalConnectionState> globalConnectionState =
ExternalStreamState<GlobalConnectionState>(GlobalConnectionState.detached);
AutoDisposeStreamProvider<GlobalConnectionState> globalConnectionStateProvider =
globalConnectionState.provider();
final globalConnectionState =
StateController<GlobalConnectionState>(GlobalConnectionState.detached);
final globalConnectionStateProvider = AutoDisposeStateNotifierProvider<
StateController<GlobalConnectionState>,
GlobalConnectionState>((ref) => globalConnectionState);

View file

@ -335,7 +335,7 @@ class ActiveConversationMessages extends _$ActiveConversationMessages {
FutureOr<IList<Message>?> build() async {
await eventualVeilid.future;
final activeChat = activeChatState.currentState;
final activeChat = ref.watch(activeChatStateProvider);
if (activeChat == null) {
return null;
}

View file

@ -159,7 +159,7 @@ class _FetchLocalAccountProviderElement
(origin as FetchLocalAccountProvider).accountMasterRecordKey;
}
String _$localAccountsHash() => r'148d98fcd8a61147bb475708d50b9699887c5bec';
String _$localAccountsHash() => r'f19ec560b585d353219be82bc383b2c091660c53';
/// See also [LocalAccounts].
@ProviderFor(LocalAccounts)

View file

@ -157,7 +157,7 @@ class _FetchLoginProviderElement
(origin as FetchLoginProvider).accountMasterRecordKey;
}
String _$loginsHash() => r'41c4630869b474c409b2fb3461dd2a56d9350c7f';
String _$loginsHash() => r'2660f71bb7903464187a93fba5c07e22041e8c40';
/// See also [Logins].
@ProviderFor(Logins)