diff --git a/wrestling_scoreboard_client/lib/provider/data_provider.dart b/wrestling_scoreboard_client/lib/provider/data_provider.dart index e4972738..71396b8f 100644 --- a/wrestling_scoreboard_client/lib/provider/data_provider.dart +++ b/wrestling_scoreboard_client/lib/provider/data_provider.dart @@ -8,28 +8,57 @@ import 'package:wrestling_scoreboard_common/common.dart'; part 'data_provider.g.dart'; +/// Class to wrap equal single data for providers. +class SingleProviderData { + final int id; + final T? initialData; + + SingleProviderData({required this.id, this.initialData}); + + @override + bool operator ==(Object other) => identical(this, other) || other is SingleProviderData && id == other.id; + + @override + int get hashCode => Object.hash(id, T); +} + @riverpod Stream singleDataStream( - SingleDataStreamRef ref, { - required int id, - T? initialData, - }) { + SingleDataStreamRef ref, + SingleProviderData pData, +) { // Reload, whenever the stream connects or disconnects // TODO: integrate in updating websocket URL from stream provider ref.watch(webSocketStateStreamProvider); // ref.onDispose(webSocketConnectionStream.close); // TODO: e.g. may be triggered twice - return dataProvider - .streamSingle(id, init: initialData == null); + return dataProvider.streamSingle(pData.id, init: pData.initialData == null); +} + +/// Class to wrap equal many data for providers. +class ManyProviderData { + final S? filterObject; + final List? initialData; + + ManyProviderData({this.filterObject, this.initialData}); + + @override + bool operator ==(Object other) { + return identical(this, other) || + other is ManyProviderData && + (filterObject == null && other.filterObject == null || filterObject?.id == other.filterObject?.id); + } + + @override + int get hashCode => Object.hash(filterObject?.id, T, S); } @riverpod Stream> manyDataStream( - ManyDataStreamRef ref, { - S? filterObject, - List? initialData, -}) { + ManyDataStreamRef ref, + ManyProviderData pData, +) { // Reload, whenever the stream connects or disconnects // TODO: integrate in updating websocket URL from stream provider ref.watch(webSocketStateStreamProvider); @@ -37,6 +66,6 @@ Stream> manyDataStream( // ref.onDispose(webSocketConnectionStream.close); // TODO: e.g. bout action event triggered twice return dataProvider - .streamMany(filterObject: filterObject, init: initialData == null) + .streamMany(filterObject: pData.filterObject, init: pData.initialData == null) .map((event) => event.data); } diff --git a/wrestling_scoreboard_client/lib/provider/data_provider.g.dart b/wrestling_scoreboard_client/lib/provider/data_provider.g.dart index d665d748..14190ba2 100644 --- a/wrestling_scoreboard_client/lib/provider/data_provider.g.dart +++ b/wrestling_scoreboard_client/lib/provider/data_provider.g.dart @@ -6,7 +6,7 @@ part of 'data_provider.dart'; // RiverpodGenerator // ************************************************************************** -String _$singleDataStreamHash() => r'b1c83c1bed6ae98086dac08fcb71ffb2a3d18f06'; +String _$singleDataStreamHash() => r'4f7017064a58e5fbf7ee99bef94e7ba626e07309'; /// Copied from Dart SDK class _SystemHash { @@ -53,24 +53,21 @@ class SingleDataStreamFamily extends Family { String? get name => r'singleDataStreamProvider'; /// See also [singleDataStream]. - SingleDataStreamProvider call({ - required int id, - T? initialData, - }) { + SingleDataStreamProvider call( + SingleProviderData pData, + ) { return SingleDataStreamProvider( - id: id, - initialData: initialData, + pData, ); } @visibleForOverriding @override SingleDataStreamProvider getProviderOverride( - covariant SingleDataStreamProvider provider, + covariant SingleDataStreamProvider provider, ) { return call( - id: provider.id, - initialData: provider.initialData, + provider.pData, ); } @@ -92,8 +89,8 @@ class _$SingleDataStreamFamilyOverride implements FamilyOverride { final SingleDataStreamFamily overriddenFamily; @override - SingleDataStreamProvider getProviderOverride( - covariant SingleDataStreamProvider provider, + SingleDataStreamProvider getProviderOverride( + covariant SingleDataStreamProvider provider, ) { return provider._copyWith(create); } @@ -103,14 +100,12 @@ class _$SingleDataStreamFamilyOverride implements FamilyOverride { class SingleDataStreamProvider extends AutoDisposeStreamProvider { /// See also [singleDataStream]. - SingleDataStreamProvider({ - required int id, - T? initialData, - }) : this._internal( + SingleDataStreamProvider( + SingleProviderData pData, + ) : this._internal( (ref) => singleDataStream( ref as SingleDataStreamRef, - id: id, - initialData: initialData, + pData, ), from: singleDataStreamProvider, name: r'singleDataStreamProvider', @@ -121,8 +116,7 @@ class SingleDataStreamProvider dependencies: SingleDataStreamFamily._dependencies, allTransitiveDependencies: SingleDataStreamFamily._allTransitiveDependencies, - id: id, - initialData: initialData, + pData: pData, ); SingleDataStreamProvider._internal( @@ -132,12 +126,10 @@ class SingleDataStreamProvider required super.allTransitiveDependencies, required super.debugGetCreateSourceHash, required super.from, - required this.id, - required this.initialData, + required this.pData, }) : super.internal(); - final int id; - final T? initialData; + final SingleProviderData pData; @override Override overrideWith( @@ -152,21 +144,14 @@ class SingleDataStreamProvider dependencies: null, allTransitiveDependencies: null, debugGetCreateSourceHash: null, - id: id, - initialData: initialData, + pData: pData, ), ); } @override - ({ - int id, - T? initialData, - }) get argument { - return ( - id: id, - initialData: initialData, - ); + (SingleProviderData,) get argument { + return (pData,); } @override @@ -184,8 +169,7 @@ class SingleDataStreamProvider allTransitiveDependencies: allTransitiveDependencies, debugGetCreateSourceHash: debugGetCreateSourceHash, from: from, - id: id, - initialData: initialData, + pData: pData, ); } @@ -193,15 +177,13 @@ class SingleDataStreamProvider bool operator ==(Object other) { return other is SingleDataStreamProvider && other.runtimeType == runtimeType && - other.id == id && - other.initialData == initialData; + other.pData == pData; } @override int get hashCode { var hash = _SystemHash.combine(0, runtimeType.hashCode); - hash = _SystemHash.combine(hash, id.hashCode); - hash = _SystemHash.combine(hash, initialData.hashCode); + hash = _SystemHash.combine(hash, pData.hashCode); hash = _SystemHash.combine(hash, T.hashCode); return _SystemHash.finish(hash); @@ -210,11 +192,8 @@ class SingleDataStreamProvider mixin SingleDataStreamRef on AutoDisposeStreamProviderRef { - /// The parameter `id` of this provider. - int get id; - - /// The parameter `initialData` of this provider. - T? get initialData; + /// The parameter `pData` of this provider. + SingleProviderData get pData; } class _SingleDataStreamProviderElement @@ -222,12 +201,11 @@ class _SingleDataStreamProviderElement _SingleDataStreamProviderElement(super.provider); @override - int get id => (origin as SingleDataStreamProvider).id; - @override - T? get initialData => (origin as SingleDataStreamProvider).initialData; + SingleProviderData get pData => + (origin as SingleDataStreamProvider).pData; } -String _$manyDataStreamHash() => r'49089cdc4cfef3e619053020a56ac9835bcc4bc4'; +String _$manyDataStreamHash() => r'd9024a6583a8732e86e397989bed313960f9dc89'; /// See also [manyDataStream]. @ProviderFor(manyDataStream) @@ -254,13 +232,11 @@ class ManyDataStreamFamily extends Family { /// See also [manyDataStream]. ManyDataStreamProvider - call({ - S? filterObject, - List? initialData, - }) { + call( + ManyProviderData pData, + ) { return ManyDataStreamProvider( - filterObject: filterObject, - initialData: initialData, + pData, ); } @@ -270,8 +246,7 @@ class ManyDataStreamFamily extends Family { covariant ManyDataStreamProvider provider, ) { return call( - filterObject: provider.filterObject, - initialData: provider.initialData, + provider.pData, ); } @@ -305,14 +280,12 @@ class _$ManyDataStreamFamilyOverride implements FamilyOverride { class ManyDataStreamProvider extends AutoDisposeStreamProvider> { /// See also [manyDataStream]. - ManyDataStreamProvider({ - S? filterObject, - List? initialData, - }) : this._internal( + ManyDataStreamProvider( + ManyProviderData pData, + ) : this._internal( (ref) => manyDataStream( ref as ManyDataStreamRef, - filterObject: filterObject, - initialData: initialData, + pData, ), from: manyDataStreamProvider, name: r'manyDataStreamProvider', @@ -323,8 +296,7 @@ class ManyDataStreamProvider dependencies: ManyDataStreamFamily._dependencies, allTransitiveDependencies: ManyDataStreamFamily._allTransitiveDependencies, - filterObject: filterObject, - initialData: initialData, + pData: pData, ); ManyDataStreamProvider._internal( @@ -334,12 +306,10 @@ class ManyDataStreamProvider required super.allTransitiveDependencies, required super.debugGetCreateSourceHash, required super.from, - required this.filterObject, - required this.initialData, + required this.pData, }) : super.internal(); - final S? filterObject; - final List? initialData; + final ManyProviderData pData; @override Override overrideWith( @@ -354,26 +324,19 @@ class ManyDataStreamProvider dependencies: null, allTransitiveDependencies: null, debugGetCreateSourceHash: null, - filterObject: filterObject, - initialData: initialData, + pData: pData, ), ); } @override - ({ - S? filterObject, - List? initialData, - }) get argument { - return ( - filterObject: filterObject, - initialData: initialData, - ); + (ManyProviderData,) get argument { + return (pData,); } @override AutoDisposeStreamProviderElement> createElement() { - return _ManyDataStreamProviderElement(this); + return _ManyDataStreamProviderElement(this); } ManyDataStreamProvider _copyWith( @@ -388,8 +351,7 @@ class ManyDataStreamProvider allTransitiveDependencies: allTransitiveDependencies, debugGetCreateSourceHash: debugGetCreateSourceHash, from: from, - filterObject: filterObject, - initialData: initialData, + pData: pData, ); } @@ -397,15 +359,13 @@ class ManyDataStreamProvider bool operator ==(Object other) { return other is ManyDataStreamProvider && other.runtimeType == runtimeType && - other.filterObject == filterObject && - other.initialData == initialData; + other.pData == pData; } @override int get hashCode { var hash = _SystemHash.combine(0, runtimeType.hashCode); - hash = _SystemHash.combine(hash, filterObject.hashCode); - hash = _SystemHash.combine(hash, initialData.hashCode); + hash = _SystemHash.combine(hash, pData.hashCode); hash = _SystemHash.combine(hash, T.hashCode); hash = _SystemHash.combine(hash, S.hashCode); @@ -415,11 +375,8 @@ class ManyDataStreamProvider mixin ManyDataStreamRef on AutoDisposeStreamProviderRef> { - /// The parameter `filterObject` of this provider. - S? get filterObject; - - /// The parameter `initialData` of this provider. - List? get initialData; + /// The parameter `pData` of this provider. + ManyProviderData get pData; } class _ManyDataStreamProviderElement (origin as ManyDataStreamProvider).filterObject; - @override - List? get initialData => - (origin as ManyDataStreamProvider).initialData; + ManyProviderData get pData => + (origin as ManyDataStreamProvider).pData; } // ignore_for_file: type=lint // ignore_for_file: subtype_of_sealed_class, invalid_use_of_internal_member, invalid_use_of_visible_for_testing_member, inference_failure_on_uninitialized_variable, inference_failure_on_function_return_type, inference_failure_on_untyped_parameter, deprecated_member_use_from_same_package diff --git a/wrestling_scoreboard_client/lib/ui/components/consumer.dart b/wrestling_scoreboard_client/lib/ui/components/consumer.dart index c42bd76a..d4a542a0 100644 --- a/wrestling_scoreboard_client/lib/ui/components/consumer.dart +++ b/wrestling_scoreboard_client/lib/ui/components/consumer.dart @@ -22,7 +22,8 @@ class SingleConsumer extends ConsumerWidget { if (id == null) { return builder(context, initialData); } - final stream = ref.watch(singleDataStreamProvider(initialData: initialData, id: id!).future); + final stream = + ref.watch(singleDataStreamProvider(SingleProviderData(initialData: initialData, id: id!)).future); return LoadingBuilder( builder: builder, future: stream, @@ -41,7 +42,9 @@ class ManyConsumer extends Consumer @override Widget build(BuildContext context, WidgetRef ref) { - final stream = ref.watch(manyDataStreamProvider(initialData: initialData, filterObject: filterObject).future); + final stream = ref.watch( + manyDataStreamProvider(ManyProviderData(initialData: initialData, filterObject: filterObject)) + .future); return LoadingBuilder>( builder: builder, future: stream, diff --git a/wrestling_scoreboard_client/lib/ui/display/bout/bout_display.dart b/wrestling_scoreboard_client/lib/ui/display/bout/bout_display.dart index eea1ccc6..35d730fa 100644 --- a/wrestling_scoreboard_client/lib/ui/display/bout/bout_display.dart +++ b/wrestling_scoreboard_client/lib/ui/display/bout/bout_display.dart @@ -212,7 +212,7 @@ class BoutState extends ConsumerState { } Future> getActions() => - ref.read(manyDataStreamProvider(filterObject: bout).future); + ref.read(manyDataStreamProvider(ManyProviderData(filterObject: bout)).future); displayName(ParticipantState? pStatus, double padding) { return Expanded( @@ -245,7 +245,7 @@ class BoutState extends ConsumerState { return Consumer( builder: (context, ref, child) { ref.watch(manyDataStreamProvider( - filterObject: bout)); // TODO: replace by participantNotifierProvider + ManyProviderData(filterObject: bout))); // TODO: replace by participantNotifierProvider return pStatus?.classificationPoints != null ? ThemedContainer( color: color.shade800,