mirror of
https://gitlab.com/veilid/veilidchat.git
synced 2025-07-21 21:58:46 -04:00
messages work
This commit is contained in:
parent
43dbf26cc0
commit
634543910b
47 changed files with 2206 additions and 123 deletions
|
@ -1,8 +1,8 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:async_tools/async_tools.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:fast_immutable_collections/fast_immutable_collections.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
typedef BlocMapState<K, S> = IMap<K, S>;
|
||||
|
||||
|
@ -48,6 +48,14 @@ abstract class BlocMapCubit<K, S, B extends BlocBase<S>>
|
|||
});
|
||||
}
|
||||
|
||||
Future<void> addState(K key, S value) =>
|
||||
_tagLock.protect(key, closure: () async {
|
||||
// Remove entry with the same key if it exists
|
||||
await _internalRemove(key);
|
||||
|
||||
emit(state.add(key, value));
|
||||
});
|
||||
|
||||
Future<void> _internalRemove(K key) async {
|
||||
final sub = _entries.remove(key);
|
||||
if (sub != null) {
|
||||
|
|
15
lib/tools/future_cubit.dart
Normal file
15
lib/tools/future_cubit.dart
Normal file
|
@ -0,0 +1,15 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:async_tools/async_tools.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
|
||||
abstract class FutureCubit<State> extends Cubit<AsyncValue<State>> {
|
||||
FutureCubit(Future<State> fut) : super(const AsyncValue.loading()) {
|
||||
unawaited(fut.then((value) {
|
||||
emit(AsyncValue.data(value));
|
||||
// ignore: avoid_types_on_closure_parameters
|
||||
}, onError: (Object e, StackTrace stackTrace) {
|
||||
emit(AsyncValue.error(e, stackTrace));
|
||||
}));
|
||||
}
|
||||
}
|
|
@ -1,7 +1,7 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:async_tools/async_tools.dart';
|
||||
import 'package:bloc/bloc.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
abstract class StreamWrapperCubit<State> extends Cubit<AsyncValue<State>> {
|
||||
StreamWrapperCubit(Stream<State> stream, {State? defaultState})
|
||||
|
|
|
@ -1,7 +1,8 @@
|
|||
export 'animations.dart';
|
||||
export 'cubit_map.dart';
|
||||
export 'bloc_map_cubit.dart';
|
||||
export 'enter_password.dart';
|
||||
export 'enter_pin.dart';
|
||||
export 'future_cubit.dart';
|
||||
export 'loggy.dart';
|
||||
export 'phono_byte.dart';
|
||||
export 'responsive.dart';
|
||||
|
@ -10,5 +11,6 @@ export 'shared_preferences.dart';
|
|||
export 'state_logger.dart';
|
||||
export 'stream_listenable.dart';
|
||||
export 'stream_wrapper_cubit.dart';
|
||||
export 'transformer_cubit.dart';
|
||||
export 'widget_helpers.dart';
|
||||
export 'window_control.dart';
|
||||
|
|
21
lib/tools/transformer_cubit.dart
Normal file
21
lib/tools/transformer_cubit.dart
Normal file
|
@ -0,0 +1,21 @@
|
|||
import 'dart:async';
|
||||
|
||||
import 'package:bloc/bloc.dart';
|
||||
|
||||
class TransformerCubit<T, S> extends Cubit<T> {
|
||||
TransformerCubit(this.input, {required this.transform})
|
||||
: super(transform(input.state)) {
|
||||
_subscription = input.stream.listen((event) => emit(transform(event)));
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> close() async {
|
||||
await _subscription.cancel();
|
||||
await input.close();
|
||||
await super.close();
|
||||
}
|
||||
|
||||
Cubit<S> input;
|
||||
T Function(S) transform;
|
||||
late final StreamSubscription<S> _subscription;
|
||||
}
|
|
@ -1,3 +1,4 @@
|
|||
import 'package:async_tools/async_tools.dart';
|
||||
import 'package:awesome_extensions/awesome_extensions.dart';
|
||||
import 'package:blurry_modal_progress_hud/blurry_modal_progress_hud.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
@ -6,7 +7,6 @@ import 'package:flutter_spinkit/flutter_spinkit.dart';
|
|||
import 'package:flutter_translate/flutter_translate.dart';
|
||||
import 'package:motion_toast/motion_toast.dart';
|
||||
import 'package:quickalert/quickalert.dart';
|
||||
import 'package:veilid_support/veilid_support.dart';
|
||||
|
||||
import '../theme/theme.dart';
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue