diff --git a/wrestling_scoreboard_client/lib/mocks/mock_data_provider.dart b/wrestling_scoreboard_client/lib/mocks/mock_data_provider.dart index efb4ef57..24aedd58 100644 --- a/wrestling_scoreboard_client/lib/mocks/mock_data_provider.dart +++ b/wrestling_scoreboard_client/lib/mocks/mock_data_provider.dart @@ -3,6 +3,7 @@ import 'dart:math'; import 'package:wrestling_scoreboard_client/mocks/mocks.dart'; import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; +import 'package:wrestling_scoreboard_client/util/network/remote/web_socket.dart'; import 'package:wrestling_scoreboard_common/common.dart'; class MockDataProvider extends DataProvider { @@ -106,11 +107,11 @@ class MockDataProvider extends DataProvider { List> teamParticipations; List weightClasses; if (wrestlingEvent is TeamMatch) { - final homeParticipations = await dataProvider.readMany(filterObject: wrestlingEvent.home); + final homeParticipations = await readMany(filterObject: wrestlingEvent.home); final guestParticipations = - await dataProvider.readMany(filterObject: wrestlingEvent.guest); + await readMany(filterObject: wrestlingEvent.guest); teamParticipations = [homeParticipations, guestParticipations]; - weightClasses = await dataProvider.readMany(filterObject: wrestlingEvent.league); + weightClasses = await readMany(filterObject: wrestlingEvent.league); } else if (wrestlingEvent is Competition) { // TODO get all participations teamParticipations = []; @@ -391,4 +392,8 @@ class MockDataProvider extends DataProvider { throw DataUnimplementedError(crud, obj.runtimeType); } } + + @override + // TODO: implement webSocketManager + WebSocketManager get webSocketManager => throw UnimplementedError(); } diff --git a/wrestling_scoreboard_client/lib/provider/data_provider.dart b/wrestling_scoreboard_client/lib/provider/data_provider.dart index f27a7812..e140b0b7 100644 --- a/wrestling_scoreboard_client/lib/provider/data_provider.dart +++ b/wrestling_scoreboard_client/lib/provider/data_provider.dart @@ -3,7 +3,7 @@ import 'package:riverpod_annotation/riverpod_annotation.dart'; import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; -import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; +import 'package:wrestling_scoreboard_client/util/network/remote/web_socket.dart'; import 'package:wrestling_scoreboard_common/common.dart'; part 'data_provider.g.dart'; @@ -24,19 +24,19 @@ class SingleProviderData { @riverpod Stream singleDataStream( - SingleDataStreamRef ref, + SingleDataStreamRef ref, SingleProviderData pData, ) async* { - // 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 - if(pData.initialData != null) { - yield pData.initialData!; + // Reload, whenever the stream is connected + final wsConnectionState = await ref.watch(webSocketStateStreamProvider.future); + if (wsConnectionState == WebSocketConnectionState.connected) { + // TODO: e.g. may be triggered twice + if (pData.initialData != null) { + yield pData.initialData!; + } + final dataManager = ref.watch(dataManagerProvider); + yield* dataManager.streamSingle(pData.id, init: pData.initialData == null); } - yield* dataProvider.streamSingle(pData.id, init: pData.initialData == null); } /// Class to wrap equal many data for providers. @@ -59,19 +59,19 @@ class ManyProviderData { @riverpod Stream> manyDataStream( - ManyDataStreamRef ref, - ManyProviderData pData, + ManyDataStreamRef ref, + ManyProviderData pData, ) async* { - // 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. bout action event triggered twice - if(pData.initialData != null) { - yield pData.initialData!; + // Reload, whenever the stream is connected + final wsConnectionState = await ref.watch(webSocketStateStreamProvider.future); + if (wsConnectionState == WebSocketConnectionState.connected) { + // TODO: e.g. bout action event triggered twice + if (pData.initialData != null) { + yield pData.initialData!; + } + final dataManager = ref.watch(dataManagerProvider); + yield* dataManager + .streamMany(filterObject: pData.filterObject, init: pData.initialData == null) + .map((event) => event.data); } - yield* dataProvider - .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 14190ba2..be527173 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'4f7017064a58e5fbf7ee99bef94e7ba626e07309'; +String _$singleDataStreamHash() => r'2b1d0c01a55c09adc14c94b565ac7a001039d318'; /// Copied from Dart SDK class _SystemHash { @@ -64,7 +64,7 @@ class SingleDataStreamFamily extends Family { @visibleForOverriding @override SingleDataStreamProvider getProviderOverride( - covariant SingleDataStreamProvider provider, + covariant SingleDataStreamProvider provider, ) { return call( provider.pData, @@ -205,7 +205,7 @@ class _SingleDataStreamProviderElement (origin as SingleDataStreamProvider).pData; } -String _$manyDataStreamHash() => r'd9024a6583a8732e86e397989bed313960f9dc89'; +String _$manyDataStreamHash() => r'07e862d584b53513ec428fcf5f103355aeeb16c2'; /// See also [manyDataStream]. @ProviderFor(manyDataStream) diff --git a/wrestling_scoreboard_client/lib/provider/network_provider.dart b/wrestling_scoreboard_client/lib/provider/network_provider.dart index 4dbf67a8..ababcd8e 100644 --- a/wrestling_scoreboard_client/lib/provider/network_provider.dart +++ b/wrestling_scoreboard_client/lib/provider/network_provider.dart @@ -1,15 +1,31 @@ import 'package:riverpod_annotation/riverpod_annotation.dart'; +import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_client/util/network/remote/web_socket.dart'; +import 'package:wrestling_scoreboard_client/mocks/mock_data_provider.dart'; +import 'package:wrestling_scoreboard_client/util/environment.dart'; +import 'package:wrestling_scoreboard_client/util/network/remote/rest.dart'; part 'network_provider.g.dart'; +final _isMock = Env.appEnvironment.fromString() == 'mock'; + @Riverpod(keepAlive: true) -Raw> webSocketStateStream(WebSocketStateStreamRef ref) { - final webSocketConnectionStream = WebSocketManager.onWebSocketConnection.stream +class DataManager extends _$DataManager { + @override + Raw build() { + // TODO: override with mock via rivperpod overrides. + final dataProvider = _isMock ? MockDataProvider() : RestDataProvider(); + return dataProvider; + } +} + +@Riverpod(keepAlive: true) +Stream webSocketStateStream(WebSocketStateStreamRef ref) { + final dataManager = ref.watch(dataManagerProvider); + // TODO: integrate in updating websocket URL from stream provider + final webSocketConnectionStream = dataManager.webSocketManager.onWebSocketConnection.stream .distinct() .where((event) => event == WebSocketConnectionState.disconnected || event == WebSocketConnectionState.connected); - - // ref.onDispose(webSocketConnectionStream.close); return webSocketConnectionStream; } diff --git a/wrestling_scoreboard_client/lib/provider/network_provider.g.dart b/wrestling_scoreboard_client/lib/provider/network_provider.g.dart index b45857c4..023d23af 100644 --- a/wrestling_scoreboard_client/lib/provider/network_provider.g.dart +++ b/wrestling_scoreboard_client/lib/provider/network_provider.g.dart @@ -7,12 +7,12 @@ part of 'network_provider.dart'; // ************************************************************************** String _$webSocketStateStreamHash() => - r'3c3b0310b088715d5a1e58b0ff5d2888d9a16394'; + r'724acc900d53840a78018b4e53e95d0c1c053b45'; /// See also [webSocketStateStream]. @ProviderFor(webSocketStateStream) final webSocketStateStreamProvider = - Provider>>.internal( + StreamProvider.internal( webSocketStateStream, name: r'webSocketStateStreamProvider', debugGetCreateSourceHash: const bool.fromEnvironment('dart.vm.product') @@ -22,7 +22,21 @@ final webSocketStateStreamProvider = allTransitiveDependencies: null, ); -typedef WebSocketStateStreamRef - = ProviderRef>>; +typedef WebSocketStateStreamRef = StreamProviderRef; +String _$dataManagerHash() => r'5c94263367326024f3d8fe004371537ad9c5843d'; + +/// See also [DataManager]. +@ProviderFor(DataManager) +final dataManagerProvider = + NotifierProvider>.internal( + DataManager.new, + name: r'dataManagerProvider', + debugGetCreateSourceHash: + const bool.fromEnvironment('dart.vm.product') ? null : _$dataManagerHash, + dependencies: null, + allTransitiveDependencies: null, +); + +typedef _$DataManager = Notifier>; // 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 ae4bac9b..3cce4b05 100644 --- a/wrestling_scoreboard_client/lib/ui/components/consumer.dart +++ b/wrestling_scoreboard_client/lib/ui/components/consumer.dart @@ -2,6 +2,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:wrestling_scoreboard_client/provider/data_provider.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/exception.dart'; import 'package:wrestling_scoreboard_client/ui/components/loading_builder.dart'; import 'package:wrestling_scoreboard_client/util/network/remote/web_socket.dart'; @@ -30,7 +31,12 @@ class NullableSingleConsumer extends ConsumerWidget { builder: builder, future: stream, initialData: null, // Handle initial data via the stream - onRetry: () => WebSocketManager.onWebSocketConnection.sink.add(WebSocketConnectionState.connecting), + onRetry: () => ref + .read(dataManagerProvider) + .webSocketManager + .onWebSocketConnection + .sink + .add(WebSocketConnectionState.connecting), ); } } @@ -58,7 +64,9 @@ class SingleConsumer extends StatelessWidget { return ExceptionWidget(AppLocalizations.of(context)!.notFoundException); } return builder(context, data); - }, id: id, initialData: initialData); + }, + id: id, + initialData: initialData); } } @@ -78,7 +86,12 @@ class ManyConsumer extends Consumer builder: builder, future: stream, initialData: null, // Handle initial data via the stream - onRetry: () => WebSocketManager.onWebSocketConnection.sink.add(WebSocketConnectionState.connecting), + onRetry: () => ref + .read(dataManagerProvider) + .webSocketManager + .onWebSocketConnection + .sink + .add(WebSocketConnectionState.connecting), ); } } @@ -119,7 +132,7 @@ class SingleConsumerState extends State> ? widget.builder(context, widget.initialData) : StreamBuilder( stream: - widget.id == null ? null : dataProvider.streamSingle(widget.id!, init: widget.initialData == null), + widget.id == null ? null : ref.read(dataManagerProvider).streamSingle(widget.id!, init: widget.initialData == null), initialData: widget.initialData, builder: (BuildContext context, AsyncSnapshot snap) { if (snap.hasError) { @@ -164,7 +177,7 @@ class ManyConsumerState extends Sta stream: webSocketConnectionStream, builder: (context, snapshot) { final stream = - dataProvider.streamMany(filterObject: widget.filterObject, init: widget.initialData == null); + ref.read(dataManagerProvider).streamMany(filterObject: widget.filterObject, init: widget.initialData == null); final initialData = widget.initialData == null ? null : ManyDataObject(data: widget.initialData!); return LoadingStreamBuilder( builder: (context, data) => widget.builder(context, data.data), 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 ef332dc8..6615c9e2 100644 --- a/wrestling_scoreboard_client/lib/ui/display/bout/bout_display.dart +++ b/wrestling_scoreboard_client/lib/ui/display/bout/bout_display.dart @@ -7,6 +7,7 @@ import 'package:wrestling_scoreboard_client/data/bout_utils.dart'; import 'package:wrestling_scoreboard_client/data/wrestling_style.dart'; import 'package:wrestling_scoreboard_client/provider/app_state_provider.dart'; import 'package:wrestling_scoreboard_client/provider/data_provider.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/consumer.dart'; import 'package:wrestling_scoreboard_client/ui/components/loading_builder.dart'; import 'package:wrestling_scoreboard_client/ui/components/scaled_text.dart'; @@ -22,7 +23,6 @@ import 'package:wrestling_scoreboard_client/ui/models/participant_state_model.da import 'package:wrestling_scoreboard_client/ui/overview/team_match/team_match_bout_overview.dart'; import 'package:wrestling_scoreboard_client/ui/overview/team_match/team_match_overview.dart'; import 'package:wrestling_scoreboard_client/util/audio/audio.dart'; -import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_client/util/print/pdf/score_sheet.dart'; import 'package:wrestling_scoreboard_client/util/units.dart'; import 'package:wrestling_scoreboard_common/common.dart'; @@ -174,7 +174,7 @@ class BoutState extends ConsumerState { _b.activityStopwatch?.stop(); // Save time to database on each stop - dataProvider.createOrUpdateSingle(bout); + ref.read(dataManagerProvider).createOrUpdateSingle(bout); }); _boutStopwatch.onAdd.stream.listen((event) { _r.activityStopwatch?.addDuration(event); @@ -228,6 +228,7 @@ class BoutState extends ConsumerState { void handleAction(BoutScreenActionIntent intent) { intent.handle( + ref.read(dataManagerProvider), stopwatch, widget.bouts, getActions, @@ -509,6 +510,6 @@ class BoutState extends ConsumerState { _breakStopwatch.dispose(); // Save time to database when dispose - await dataProvider.createOrUpdateSingle(bout); + await ref.read(dataManagerProvider).createOrUpdateSingle(bout); } } diff --git a/wrestling_scoreboard_client/lib/ui/display/bout/bout_main_controls.dart b/wrestling_scoreboard_client/lib/ui/display/bout/bout_main_controls.dart index f84a7295..10113baf 100644 --- a/wrestling_scoreboard_client/lib/ui/display/bout/bout_main_controls.dart +++ b/wrestling_scoreboard_client/lib/ui/display/bout/bout_main_controls.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:wrestling_scoreboard_client/data/bout_result.dart'; import 'package:wrestling_scoreboard_client/data/bout_utils.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/consumer.dart'; import 'package:wrestling_scoreboard_client/ui/components/dropdown.dart'; import 'package:wrestling_scoreboard_client/ui/components/themed.dart'; @@ -9,17 +11,17 @@ import 'package:wrestling_scoreboard_client/ui/display/bout/bout_shortcuts.dart' import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; -class BoutMainControls extends StatefulWidget { +class BoutMainControls extends ConsumerStatefulWidget { final Function(BoutScreenActionIntent) callback; final BoutState boutState; const BoutMainControls(this.callback, this.boutState, {super.key}); @override - State createState() => BoutMainControlsState(); + ConsumerState createState() => BoutMainControlsState(); } -class BoutMainControlsState extends State { +class BoutMainControlsState extends ConsumerState { IconData _pausePlayButton = Icons.play_arrow; @override @@ -129,9 +131,10 @@ class BoutMainControlsState extends State { result: val, ); bout = bout.updateClassificationPoints(actions); - dataProvider.createOrUpdateSingle(bout); - if (bout.r != null) dataProvider.createOrUpdateSingle(bout.r!); - if (bout.b != null) dataProvider.createOrUpdateSingle(bout.b!); + final dataManager = ref.read(dataManagerProvider); + dataManager.createOrUpdateSingle(bout); + if (bout.r != null) dataManager.createOrUpdateSingle(bout.r!); + if (bout.b != null) dataManager.createOrUpdateSingle(bout.b!); widget.boutState.bout = bout; }); }, diff --git a/wrestling_scoreboard_client/lib/ui/display/bout/bout_shortcuts.dart b/wrestling_scoreboard_client/lib/ui/display/bout/bout_shortcuts.dart index a3fa4701..758a0546 100644 --- a/wrestling_scoreboard_client/lib/ui/display/bout/bout_shortcuts.dart +++ b/wrestling_scoreboard_client/lib/ui/display/bout/bout_shortcuts.dart @@ -2,7 +2,9 @@ import 'dart:async'; import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/util/audio/audio.dart'; import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; @@ -102,6 +104,7 @@ class BoutScreenActionIntent extends Intent { final BoutScreenActions type; Future handle( + DataProvider dataProvider, ObservableStopwatch stopwatch, List bouts, Future> Function() getActions, @@ -270,7 +273,7 @@ class BoutScreenActionIntent extends Intent { } } -class BoutActionHandler extends StatelessWidget { +class BoutActionHandler extends ConsumerWidget { final Widget child; final ObservableStopwatch stopwatch; final List bouts; @@ -289,13 +292,13 @@ class BoutActionHandler extends StatelessWidget { super.key, required this.navigateToBoutByIndex}); - Future handleIntent(BoutScreenActionIntent intent, {BuildContext? context}) async { - await intent.handle(stopwatch, bouts, getActions, boutIndex, doAction, - context: context, navigateToBoutByIndex: navigateToBoutByIndex); - } - @override - Widget build(BuildContext context) { + Widget build(BuildContext context, WidgetRef ref) { + Future handleIntent(BoutScreenActionIntent intent, {BuildContext? context}) async { + await intent.handle(ref.read(dataManagerProvider), stopwatch, bouts, getActions, boutIndex, doAction, + context: context, navigateToBoutByIndex: navigateToBoutByIndex); + } + const redOneIntent = BoutScreenActionIntent.redOne(); const redTwoIntent = BoutScreenActionIntent.redTwo(); const redThreeIntent = BoutScreenActionIntent.redThree(); diff --git a/wrestling_scoreboard_client/lib/ui/edit/bout_config_edit.dart b/wrestling_scoreboard_client/lib/ui/edit/bout_config_edit.dart index fe1cace6..e626db71 100644 --- a/wrestling_scoreboard_client/lib/ui/edit/bout_config_edit.dart +++ b/wrestling_scoreboard_client/lib/ui/edit/bout_config_edit.dart @@ -1,18 +1,20 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/edit.dart'; import 'package:wrestling_scoreboard_client/ui/edit/common.dart'; -import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; -abstract class BoutConfigEdit extends StatefulWidget { +abstract class BoutConfigEdit extends ConsumerStatefulWidget { final BoutConfig? boutConfig; const BoutConfigEdit({this.boutConfig, super.key}); } -abstract class BoutConfigEditState extends State implements AbstractEditState { +abstract class BoutConfigEditState extends ConsumerState + implements AbstractEditState { final _formKey = GlobalKey(); int? _periodDurationInSecs; @@ -133,7 +135,7 @@ abstract class BoutConfigEditState extends State im injuryDuration: Duration(seconds: _injuryDurationInSecs!), periodCount: _periodCount!, ); - boutConfig = boutConfig.copyWithId(await dataProvider.createOrUpdateSingle(boutConfig)); + boutConfig = boutConfig.copyWithId(await ref.read(dataManagerProvider).createOrUpdateSingle(boutConfig)); await handleNested(boutConfig); navigator.pop(); } diff --git a/wrestling_scoreboard_client/lib/ui/edit/bout_edit.dart b/wrestling_scoreboard_client/lib/ui/edit/bout_edit.dart index 3f77a072..51684180 100644 --- a/wrestling_scoreboard_client/lib/ui/edit/bout_edit.dart +++ b/wrestling_scoreboard_client/lib/ui/edit/bout_edit.dart @@ -4,13 +4,13 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:wrestling_scoreboard_client/data/bout_result.dart'; import 'package:wrestling_scoreboard_client/provider/data_provider.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/dropdown.dart'; import 'package:wrestling_scoreboard_client/ui/components/edit.dart'; import 'package:wrestling_scoreboard_client/ui/edit/common.dart'; -import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; -abstract class BoutEdit extends StatefulWidget { +abstract class BoutEdit extends ConsumerStatefulWidget { final Bout? bout; final Lineup lineupRed; final Lineup lineupBlue; @@ -23,7 +23,7 @@ abstract class BoutEdit extends StatefulWidget { }); } -abstract class BoutEditState extends State implements AbstractEditState { +abstract class BoutEditState extends ConsumerState implements AbstractEditState { final _formKey = GlobalKey(); BoutRole? _winnerRole; @@ -165,12 +165,12 @@ abstract class BoutEditState extends State implements Abs Participation? newParticipation, ParticipantState? oldParticipantState) async { if (newParticipation != oldParticipantState?.participation) { if (oldParticipantState != null) { - await dataProvider.deleteSingle(oldParticipantState); + await ref.read(dataManagerProvider).deleteSingle(oldParticipantState); } if (newParticipation != null) { final newParticipantState = ParticipantState(participation: newParticipation); - return newParticipantState - .copyWithId(await dataProvider.createOrUpdateSingle(newParticipantState)); + return newParticipantState.copyWithId( + await ref.read(dataManagerProvider).createOrUpdateSingle(newParticipantState)); } else { return null; } @@ -190,7 +190,7 @@ abstract class BoutEditState extends State implements Abs pool: widget.bout?.pool, ); - bout = bout.copyWithId(await dataProvider.createOrUpdateSingle(bout)); + bout = bout.copyWithId(await ref.read(dataManagerProvider).createOrUpdateSingle(bout)); await handleNested(bout); navigator.pop(); } diff --git a/wrestling_scoreboard_client/lib/ui/edit/club_edit.dart b/wrestling_scoreboard_client/lib/ui/edit/club_edit.dart index 9663fb72..d122a799 100644 --- a/wrestling_scoreboard_client/lib/ui/edit/club_edit.dart +++ b/wrestling_scoreboard_client/lib/ui/edit/club_edit.dart @@ -1,19 +1,21 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/edit.dart'; import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; -class ClubEdit extends StatefulWidget { +class ClubEdit extends ConsumerStatefulWidget { final Club? club; const ClubEdit({this.club, super.key}); @override - State createState() => ClubEditState(); + ConsumerState createState() => ClubEditState(); } -class ClubEditState extends State { +class ClubEditState extends ConsumerState { final _formKey = GlobalKey(); String? _name; @@ -69,7 +71,7 @@ class ClubEditState extends State { Future handleSubmit(NavigatorState navigator) async { if (_formKey.currentState!.validate()) { _formKey.currentState!.save(); - await dataProvider.createOrUpdateSingle(Club(id: widget.club?.id, name: _name!, no: _no)); + await ref.read(dataManagerProvider).createOrUpdateSingle(Club(id: widget.club?.id, name: _name!, no: _no)); navigator.pop(); } } diff --git a/wrestling_scoreboard_client/lib/ui/edit/lineup_edit.dart b/wrestling_scoreboard_client/lib/ui/edit/lineup_edit.dart index 2931ece3..6b9ba03e 100644 --- a/wrestling_scoreboard_client/lib/ui/edit/lineup_edit.dart +++ b/wrestling_scoreboard_client/lib/ui/edit/lineup_edit.dart @@ -7,14 +7,13 @@ import 'package:flutter_gen/gen_l10n/app_localizations.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:wrestling_scoreboard_client/data/wrestling_style.dart'; import 'package:wrestling_scoreboard_client/provider/data_provider.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/dropdown.dart'; import 'package:wrestling_scoreboard_client/ui/components/edit.dart'; import 'package:wrestling_scoreboard_client/ui/components/font.dart'; import 'package:wrestling_scoreboard_client/ui/components/ok_dialog.dart'; -import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; - // TODO: dynamically add or remove participants without weight class class LineupEdit extends ConsumerStatefulWidget { final Lineup lineup; @@ -61,12 +60,13 @@ class LineupEditState extends ConsumerState { Future handleSubmit(NavigatorState navigator, {void Function()? onSubmitGenerate}) async { if (_formKey.currentState!.validate()) { _formKey.currentState!.save(); - await dataProvider + await ref + .read(dataManagerProvider) .createOrUpdateSingle(Lineup(id: widget.lineup.id, team: widget.lineup.team, leader: _leader, coach: _coach)); - await Future.forEach( - _deleteParticipations, (Participation element) => dataProvider.deleteSingle(element)); - await Future.forEach( - _createOrUpdateParticipations, (Participation element) => dataProvider.createOrUpdateSingle(element)); + await Future.forEach(_deleteParticipations, + (Participation element) => ref.read(dataManagerProvider).deleteSingle(element)); + await Future.forEach(_createOrUpdateParticipations, + (Participation element) => ref.read(dataManagerProvider).createOrUpdateSingle(element)); if (onSubmitGenerate != null) onSubmitGenerate(); navigator.pop(); } diff --git a/wrestling_scoreboard_client/lib/ui/edit/membership_edit.dart b/wrestling_scoreboard_client/lib/ui/edit/membership_edit.dart index 01306bc2..e886a1c2 100644 --- a/wrestling_scoreboard_client/lib/ui/edit/membership_edit.dart +++ b/wrestling_scoreboard_client/lib/ui/edit/membership_edit.dart @@ -1,7 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/edit/person_edit.dart'; -import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; class MembershipEdit extends PersonEdit { @@ -11,7 +12,7 @@ class MembershipEdit extends PersonEdit { MembershipEdit({this.membership, required this.initialClub, super.key}) : super(person: membership?.person); @override - State createState() => MembershipEditState(); + ConsumerState createState() => MembershipEditState(); } class MembershipEditState extends PersonEditState { @@ -38,6 +39,6 @@ class MembershipEditState extends PersonEditState { @override Future handleNested(person) async { var membership = Membership(id: widget.membership?.id, person: person, club: widget.initialClub, no: _no); - membership = membership.copyWithId(await dataProvider.createOrUpdateSingle(membership)); + membership = membership.copyWithId(await ref.read(dataManagerProvider).createOrUpdateSingle(membership)); } } diff --git a/wrestling_scoreboard_client/lib/ui/edit/person_edit.dart b/wrestling_scoreboard_client/lib/ui/edit/person_edit.dart index 00a19534..3e41b66f 100644 --- a/wrestling_scoreboard_client/lib/ui/edit/person_edit.dart +++ b/wrestling_scoreboard_client/lib/ui/edit/person_edit.dart @@ -1,19 +1,20 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:wrestling_scoreboard_client/data/gender.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/edit.dart'; import 'package:wrestling_scoreboard_client/ui/edit/common.dart'; import 'package:wrestling_scoreboard_client/util/date_time.dart'; -import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; -abstract class PersonEdit extends StatefulWidget { +abstract class PersonEdit extends ConsumerStatefulWidget { final Person? person; const PersonEdit({this.person, super.key}); } -abstract class PersonEditState extends State implements AbstractEditState { +abstract class PersonEditState extends ConsumerState implements AbstractEditState { final _formKey = GlobalKey(); String? _prename; @@ -140,7 +141,7 @@ abstract class PersonEditState extends State implements birthDate: _dateOfBirth, gender: _gender, ); - person = person.copyWithId(await dataProvider.createOrUpdateSingle(person)); + person = person.copyWithId(await ref.read(dataManagerProvider).createOrUpdateSingle(person)); await handleNested(person); navigator.pop(); } diff --git a/wrestling_scoreboard_client/lib/ui/edit/team_edit.dart b/wrestling_scoreboard_client/lib/ui/edit/team_edit.dart index bf941416..e9ae6b3f 100644 --- a/wrestling_scoreboard_client/lib/ui/edit/team_edit.dart +++ b/wrestling_scoreboard_client/lib/ui/edit/team_edit.dart @@ -1,21 +1,22 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/dropdown.dart'; import 'package:wrestling_scoreboard_client/ui/components/edit.dart'; -import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; -class TeamEdit extends StatefulWidget { +class TeamEdit extends ConsumerStatefulWidget { final Team? team; final Club? initialClub; const TeamEdit({this.team, this.initialClub, super.key}); @override - State createState() => TeamEditState(); + ConsumerState createState() => TeamEditState(); } -class TeamEditState extends State { +class TeamEditState extends ConsumerState { final _formKey = GlobalKey(); List? availableClubs; @@ -74,7 +75,7 @@ class TeamEditState extends State { }), itemAsString: (u) => u.name, onFind: (String? filter) async { - availableClubs ??= await dataProvider.readMany(); + availableClubs ??= await ref.read(dataManagerProvider).readMany(); return (filter == null ? availableClubs! : availableClubs!.where((element) => element.name.contains(filter))) @@ -98,12 +99,12 @@ class TeamEditState extends State { Future handleSubmit(NavigatorState navigator) async { if (_formKey.currentState!.validate()) { _formKey.currentState!.save(); - await dataProvider.createOrUpdateSingle(Team( - id: widget.team?.id, - name: _name!, - description: _description, - club: _club!, - )); + await ref.read(dataManagerProvider).createOrUpdateSingle(Team( + id: widget.team?.id, + name: _name!, + description: _description, + club: _club!, + )); navigator.pop(); } } diff --git a/wrestling_scoreboard_client/lib/ui/edit/team_match/league_edit.dart b/wrestling_scoreboard_client/lib/ui/edit/team_match/league_edit.dart index d3842a6a..10d663b0 100644 --- a/wrestling_scoreboard_client/lib/ui/edit/team_match/league_edit.dart +++ b/wrestling_scoreboard_client/lib/ui/edit/team_match/league_edit.dart @@ -1,8 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/edit/bout_config_edit.dart'; import 'package:wrestling_scoreboard_client/util/date_time.dart'; -import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; class LeagueEdit extends BoutConfigEdit { @@ -11,7 +12,7 @@ class LeagueEdit extends BoutConfigEdit { LeagueEdit({this.league, super.key}) : super(boutConfig: league?.boutConfig); @override - State createState() => LeagueEditState(); + ConsumerState createState() => LeagueEditState(); } class LeagueEditState extends BoutConfigEditState { @@ -74,7 +75,7 @@ class LeagueEditState extends BoutConfigEditState { @override Future handleNested(BoutConfig dataObject) async { - await dataProvider.createOrUpdateSingle( + await ref.read(dataManagerProvider).createOrUpdateSingle( League(id: widget.league?.id, name: _name!, startDate: _startDate, boutConfig: dataObject)); } } diff --git a/wrestling_scoreboard_client/lib/ui/edit/team_match/league_team_participation_edit.dart b/wrestling_scoreboard_client/lib/ui/edit/team_match/league_team_participation_edit.dart index 029b42b4..b562da78 100644 --- a/wrestling_scoreboard_client/lib/ui/edit/team_match/league_team_participation_edit.dart +++ b/wrestling_scoreboard_client/lib/ui/edit/team_match/league_team_participation_edit.dart @@ -1,11 +1,13 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/dropdown.dart'; import 'package:wrestling_scoreboard_client/ui/components/edit.dart'; import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; -class LeagueTeamParticipationEdit extends StatefulWidget { +class LeagueTeamParticipationEdit extends ConsumerStatefulWidget { final LeagueTeamParticipation? participation; final Team? initialTeam; final League? initialLeague; @@ -18,10 +20,10 @@ class LeagueTeamParticipationEdit extends StatefulWidget { }); @override - State createState() => TeamEditState(); + ConsumerState createState() => TeamEditState(); } -class TeamEditState extends State { +class TeamEditState extends ConsumerState { final _formKey = GlobalKey(); List? availableTeams; @@ -53,7 +55,7 @@ class TeamEditState extends State { }), itemAsString: (u) => u.name, onFind: (String? filter) async { - availableTeams ??= await dataProvider.readMany(); + availableTeams ??= await ref.read(dataManagerProvider).readMany(); return (filter == null ? availableTeams! : availableTeams!.where((element) => element.name.contains(filter))) @@ -72,7 +74,7 @@ class TeamEditState extends State { }), itemAsString: (u) => u.name, onFind: (String? filter) async { - _availableLeagues ??= await dataProvider.readMany(); + _availableLeagues ??= await ref.read(dataManagerProvider).readMany(); return (filter == null ? _availableLeagues! : _availableLeagues!.where((element) => element.name.contains(filter))) @@ -96,11 +98,11 @@ class TeamEditState extends State { Future handleSubmit(NavigatorState navigator) async { if (_formKey.currentState!.validate()) { _formKey.currentState!.save(); - await dataProvider.createOrUpdateSingle(LeagueTeamParticipation( - id: widget.participation?.id, - team: _team!, - league: _league!, - )); + await ref.read(dataManagerProvider).createOrUpdateSingle(LeagueTeamParticipation( + id: widget.participation?.id, + team: _team!, + league: _league!, + )); navigator.pop(); } } diff --git a/wrestling_scoreboard_client/lib/ui/edit/team_match/league_weight_class_edit.dart b/wrestling_scoreboard_client/lib/ui/edit/team_match/league_weight_class_edit.dart index 74abc723..808692fa 100644 --- a/wrestling_scoreboard_client/lib/ui/edit/team_match/league_weight_class_edit.dart +++ b/wrestling_scoreboard_client/lib/ui/edit/team_match/league_weight_class_edit.dart @@ -1,8 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/edit/weight_class_edit.dart'; -import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; class LeagueWeightClassEdit extends WeightClassEdit { @@ -13,7 +14,7 @@ class LeagueWeightClassEdit extends WeightClassEdit { : super(weightClass: leagueWeightClass?.weightClass); @override - State createState() => LeagueWeightClassEditState(); + ConsumerState createState() => LeagueWeightClassEditState(); } class LeagueWeightClassEditState extends WeightClassEditState { @@ -45,6 +46,7 @@ class LeagueWeightClassEditState extends WeightClassEditState handleNested(weightClass) async { var leagueWeightClass = LeagueWeightClass( id: widget.leagueWeightClass?.id, league: widget.initialLeague, pos: _pos, weightClass: weightClass); - leagueWeightClass = leagueWeightClass.copyWithId(await dataProvider.createOrUpdateSingle(leagueWeightClass)); + leagueWeightClass = + leagueWeightClass.copyWithId(await ref.read(dataManagerProvider).createOrUpdateSingle(leagueWeightClass)); } } diff --git a/wrestling_scoreboard_client/lib/ui/edit/team_match/team_match_bout_edit.dart b/wrestling_scoreboard_client/lib/ui/edit/team_match/team_match_bout_edit.dart index 9fbb81a3..b931a4a4 100644 --- a/wrestling_scoreboard_client/lib/ui/edit/team_match/team_match_bout_edit.dart +++ b/wrestling_scoreboard_client/lib/ui/edit/team_match/team_match_bout_edit.dart @@ -1,8 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/edit/bout_edit.dart'; -import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; class TeamMatchBoutEdit extends BoutEdit { @@ -17,7 +18,7 @@ class TeamMatchBoutEdit extends BoutEdit { ); @override - State createState() => TeamMatchBoutEditState(); + ConsumerState createState() => TeamMatchBoutEditState(); } class TeamMatchBoutEditState extends BoutEditState { @@ -49,10 +50,10 @@ class TeamMatchBoutEditState extends BoutEditState { Future handleNested(bout) async { var teamMatchBout = TeamMatchBout(id: widget.teamMatchBout?.id, teamMatch: widget.initialTeamMatch, pos: _pos, bout: bout); - teamMatchBout = teamMatchBout.copyWithId(await dataProvider.createOrUpdateSingle(teamMatchBout)); + teamMatchBout = teamMatchBout.copyWithId(await ref.read(dataManagerProvider).createOrUpdateSingle(teamMatchBout)); } @override Future> get availableWeightClasses => - dataProvider.readMany(filterObject: widget.initialTeamMatch.league); + ref.read(dataManagerProvider).readMany(filterObject: widget.initialTeamMatch.league); } diff --git a/wrestling_scoreboard_client/lib/ui/edit/team_match/team_match_edit.dart b/wrestling_scoreboard_client/lib/ui/edit/team_match/team_match_edit.dart index 2be420d2..901b66e2 100644 --- a/wrestling_scoreboard_client/lib/ui/edit/team_match/team_match_edit.dart +++ b/wrestling_scoreboard_client/lib/ui/edit/team_match/team_match_edit.dart @@ -1,12 +1,13 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/dropdown.dart'; import 'package:wrestling_scoreboard_client/ui/components/edit.dart'; import 'package:wrestling_scoreboard_client/util/date_time.dart'; -import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; -class TeamMatchEdit extends StatefulWidget { +class TeamMatchEdit extends ConsumerStatefulWidget { final TeamMatch? teamMatch; final Team? initialHomeTeam; final Team? initialGuestTeam; @@ -21,10 +22,10 @@ class TeamMatchEdit extends StatefulWidget { }); @override - State createState() => TeamMatchEditState(); + ConsumerState createState() => TeamMatchEditState(); } -class TeamMatchEditState extends State { +class TeamMatchEditState extends ConsumerState { final _formKey = GlobalKey(); List? _availableLeagues; @@ -115,7 +116,7 @@ class TeamMatchEditState extends State { itemAsString: (u) => u.name, onFind: (String? filter) async { // TODO: filter by teams of same league, but may add an option to search all teams - _availableTeams ??= await dataProvider.readMany(); + _availableTeams ??= await ref.read(dataManagerProvider).readMany(); return (filter == null ? _availableTeams! : _availableTeams!.where((element) => element.name.contains(filter))) @@ -135,7 +136,7 @@ class TeamMatchEditState extends State { itemAsString: (u) => u.name, onFind: (String? filter) async { // TODO: filter by teams of same league, but may add an option to search all teams - _availableTeams ??= await dataProvider.readMany(); + _availableTeams ??= await ref.read(dataManagerProvider).readMany(); return (filter == null ? _availableTeams! : _availableTeams!.where((element) => element.name.contains(filter))) @@ -154,7 +155,7 @@ class TeamMatchEditState extends State { }), itemAsString: (u) => u.name, onFind: (String? filter) async { - _availableLeagues ??= await dataProvider.readMany(); + _availableLeagues ??= await ref.read(dataManagerProvider).readMany(); return (filter == null ? _availableLeagues! : _availableLeagues!.where((element) => element.name.contains(filter))) @@ -181,33 +182,33 @@ class TeamMatchEditState extends State { var home = widget.teamMatch?.home; if (home == null) { - final homeId = await dataProvider.createOrUpdateSingle(Lineup(team: _homeTeam!)); + final homeId = await ref.read(dataManagerProvider).createOrUpdateSingle(Lineup(team: _homeTeam!)); home = Lineup(id: homeId, team: _homeTeam!); // TODO check if it works without refetching the objects } else if (home.team != _homeTeam) { // Update Lineup team only, no need to replace whole lineup - await dataProvider.createOrUpdateSingle(Lineup(id: home.id, team: _homeTeam!)); + await ref.read(dataManagerProvider).createOrUpdateSingle(Lineup(id: home.id, team: _homeTeam!)); } var guest = widget.teamMatch?.guest; if (guest == null) { - final guestId = await dataProvider.createOrUpdateSingle(Lineup(team: _guestTeam!)); + final guestId = await ref.read(dataManagerProvider).createOrUpdateSingle(Lineup(team: _guestTeam!)); guest = Lineup(id: guestId, team: _guestTeam!); // TODO check if it works without refetching the objects } else if (guest.team != _guestTeam) { // Update Lineup team only, no need to replace whole lineup - await dataProvider.createOrUpdateSingle(Lineup(id: guest.id, team: _guestTeam!)); + await ref.read(dataManagerProvider).createOrUpdateSingle(Lineup(id: guest.id, team: _guestTeam!)); } - await dataProvider.createOrUpdateSingle( - TeamMatch( - id: widget.teamMatch?.id, - location: _location!, - no: _no, - home: home, - guest: guest, - date: _date, - league: _league, - ), - ); + await ref.read(dataManagerProvider).createOrUpdateSingle( + TeamMatch( + id: widget.teamMatch?.id, + location: _location!, + no: _no, + home: home, + guest: guest, + date: _date, + league: _league, + ), + ); navigator.pop(); } } diff --git a/wrestling_scoreboard_client/lib/ui/edit/weight_class_edit.dart b/wrestling_scoreboard_client/lib/ui/edit/weight_class_edit.dart index d4d783d6..9b843730 100644 --- a/wrestling_scoreboard_client/lib/ui/edit/weight_class_edit.dart +++ b/wrestling_scoreboard_client/lib/ui/edit/weight_class_edit.dart @@ -1,19 +1,20 @@ import 'package:flutter/material.dart'; import 'package:flutter/services.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:wrestling_scoreboard_client/data/wrestling_style.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/edit.dart'; import 'package:wrestling_scoreboard_client/ui/edit/common.dart'; -import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; -abstract class WeightClassEdit extends StatefulWidget { +abstract class WeightClassEdit extends ConsumerStatefulWidget { final WeightClass? weightClass; const WeightClassEdit({this.weightClass, super.key}); } -abstract class WeightClassEditState extends State +abstract class WeightClassEditState extends ConsumerState implements AbstractEditState { final _formKey = GlobalKey(); @@ -123,7 +124,7 @@ abstract class WeightClassEditState extends State _formKey.currentState!.save(); var weightClass = WeightClass( id: widget.weightClass?.id, suffix: _suffix!, weight: _weight, style: _wrestlingStyle, unit: _unit); - weightClass = weightClass.copyWithId(await dataProvider.createOrUpdateSingle(weightClass)); + weightClass = weightClass.copyWithId(await ref.read(dataManagerProvider).createOrUpdateSingle(weightClass)); await handleNested(weightClass); navigator.pop(); } diff --git a/wrestling_scoreboard_client/lib/ui/home/home.dart b/wrestling_scoreboard_client/lib/ui/home/home.dart index 05e94b79..620ea858 100644 --- a/wrestling_scoreboard_client/lib/ui/home/home.dart +++ b/wrestling_scoreboard_client/lib/ui/home/home.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/consumer.dart'; import 'package:wrestling_scoreboard_client/ui/components/grouped_list.dart'; import 'package:wrestling_scoreboard_client/ui/components/responsive_container.dart'; @@ -11,18 +13,19 @@ import 'package:wrestling_scoreboard_client/ui/overview/team_match/league_overvi import 'package:wrestling_scoreboard_client/util/network/remote/web_socket.dart'; import 'package:wrestling_scoreboard_common/common.dart'; -class Home extends StatefulWidget { +class Home extends ConsumerStatefulWidget { const Home({super.key}); @override - State createState() => HomeState(); + ConsumerState createState() => HomeState(); } -class HomeState extends State { +class HomeState extends ConsumerState { @override void initState() { super.initState(); - WebSocketManager.onWebSocketConnection.stream.distinct().listen((connectionState) { + final webSocketManager = ref.read(dataManagerProvider).webSocketManager; + webSocketManager.onWebSocketConnection.stream.distinct().listen((connectionState) { if (mounted && connectionState == WebSocketConnectionState.disconnected) { WidgetsBinding.instance.addPostFrameCallback((_) { final localizations = AppLocalizations.of(context)!; @@ -38,7 +41,7 @@ class HomeState extends State { TextButton( onPressed: () { Navigator.of(context).pop(); - WebSocketManager.onWebSocketConnection.sink.add(WebSocketConnectionState.connecting); + webSocketManager.onWebSocketConnection.sink.add(WebSocketConnectionState.connecting); }, child: Text(localizations.retry), ), diff --git a/wrestling_scoreboard_client/lib/ui/overview/bout_overview.dart b/wrestling_scoreboard_client/lib/ui/overview/bout_overview.dart index 5ad50f47..71bebfaa 100644 --- a/wrestling_scoreboard_client/lib/ui/overview/bout_overview.dart +++ b/wrestling_scoreboard_client/lib/ui/overview/bout_overview.dart @@ -1,8 +1,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:wrestling_scoreboard_client/data/bout_result.dart'; import 'package:wrestling_scoreboard_client/data/bout_utils.dart'; import 'package:wrestling_scoreboard_client/data/time.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/consumer.dart'; import 'package:wrestling_scoreboard_client/ui/components/grouped_list.dart'; import 'package:wrestling_scoreboard_client/ui/components/info.dart'; @@ -10,12 +12,13 @@ import 'package:wrestling_scoreboard_client/ui/overview/common.dart'; import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; -abstract class BoutOverview extends StatelessWidget implements AbstractOverview { +abstract class BoutOverview extends ConsumerWidget implements AbstractOverview { const BoutOverview({super.key}); @override Widget buildOverview( - BuildContext context, { + BuildContext context, + WidgetRef ref, { required String classLocale, required Widget editPage, required VoidCallback onDelete, @@ -33,7 +36,7 @@ abstract class BoutOverview extends StatelessWidget implements AbstractOverview< editPage: editPage, onDelete: () { onDelete(); - dataProvider.deleteSingle(data); + ref.read(dataManagerProvider).deleteSingle(data); }, classLocale: classLocale, children: [ diff --git a/wrestling_scoreboard_client/lib/ui/overview/club_overview.dart b/wrestling_scoreboard_client/lib/ui/overview/club_overview.dart index f52780fd..3900c270 100644 --- a/wrestling_scoreboard_client/lib/ui/overview/club_overview.dart +++ b/wrestling_scoreboard_client/lib/ui/overview/club_overview.dart @@ -1,6 +1,8 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/consumer.dart'; import 'package:wrestling_scoreboard_client/ui/components/grouped_list.dart'; import 'package:wrestling_scoreboard_client/ui/components/info.dart'; @@ -10,10 +12,9 @@ import 'package:wrestling_scoreboard_client/ui/edit/team_edit.dart'; import 'package:wrestling_scoreboard_client/ui/overview/common.dart'; import 'package:wrestling_scoreboard_client/ui/overview/membership_overview.dart'; import 'package:wrestling_scoreboard_client/ui/overview/team_overview.dart'; -import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; -class ClubOverview extends StatelessWidget { +class ClubOverview extends ConsumerWidget { static const route = 'club'; final int id; @@ -22,7 +23,7 @@ class ClubOverview extends StatelessWidget { const ClubOverview({super.key, required this.id, this.club}); @override - Widget build(BuildContext context) { + Widget build(BuildContext context, WidgetRef ref) { final localizations = AppLocalizations.of(context)!; return SingleConsumer( id: id, @@ -33,7 +34,7 @@ class ClubOverview extends StatelessWidget { editPage: ClubEdit( club: data, ), - onDelete: () => dataProvider.deleteSingle(data), + onDelete: () => ref.read(dataManagerProvider).deleteSingle(data), classLocale: localizations.club, children: [ ContentItem( diff --git a/wrestling_scoreboard_client/lib/ui/overview/common.dart b/wrestling_scoreboard_client/lib/ui/overview/common.dart index b7c09df3..1cbb2a54 100644 --- a/wrestling_scoreboard_client/lib/ui/overview/common.dart +++ b/wrestling_scoreboard_client/lib/ui/overview/common.dart @@ -1,9 +1,11 @@ import 'package:flutter/material.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:wrestling_scoreboard_common/common.dart'; abstract class AbstractOverview { Widget buildOverview( - BuildContext context, { + BuildContext context, + WidgetRef ref, { required String classLocale, required Widget editPage, required VoidCallback onDelete, diff --git a/wrestling_scoreboard_client/lib/ui/overview/membership_overview.dart b/wrestling_scoreboard_client/lib/ui/overview/membership_overview.dart index ef76c568..cde033e2 100644 --- a/wrestling_scoreboard_client/lib/ui/overview/membership_overview.dart +++ b/wrestling_scoreboard_client/lib/ui/overview/membership_overview.dart @@ -1,10 +1,11 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/consumer.dart'; import 'package:wrestling_scoreboard_client/ui/components/grouped_list.dart'; import 'package:wrestling_scoreboard_client/ui/edit/membership_edit.dart'; import 'package:wrestling_scoreboard_client/ui/overview/person_overview.dart'; -import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; class MembershipOverview extends PersonOverview { @@ -16,7 +17,7 @@ class MembershipOverview extends PersonOverview { const MembershipOverview({super.key, required this.id, this.membership}); @override - Widget build(BuildContext context) { + Widget build(BuildContext context, WidgetRef ref) { final localizations = AppLocalizations.of(context)!; return SingleConsumer( id: id, @@ -24,6 +25,7 @@ class MembershipOverview extends PersonOverview { builder: (context, membership) { return buildOverview( context, + ref, dataId: membership.person.id!, initialData: membership.person, classLocale: localizations.membership, @@ -31,7 +33,7 @@ class MembershipOverview extends PersonOverview { membership: membership, initialClub: membership.club, ), - onDelete: () => dataProvider.deleteSingle(membership), + onDelete: () => ref.read(dataManagerProvider).deleteSingle(membership), tiles: [ ContentItem( title: membership.no ?? '-', diff --git a/wrestling_scoreboard_client/lib/ui/overview/person_overview.dart b/wrestling_scoreboard_client/lib/ui/overview/person_overview.dart index 85778a12..aeb7f666 100644 --- a/wrestling_scoreboard_client/lib/ui/overview/person_overview.dart +++ b/wrestling_scoreboard_client/lib/ui/overview/person_overview.dart @@ -1,22 +1,24 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:wrestling_scoreboard_client/data/gender.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/consumer.dart'; import 'package:wrestling_scoreboard_client/ui/components/grouped_list.dart'; import 'package:wrestling_scoreboard_client/ui/components/info.dart'; import 'package:wrestling_scoreboard_client/ui/overview/common.dart'; import 'package:wrestling_scoreboard_client/util/date_time.dart'; -import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; -abstract class PersonOverview extends StatelessWidget implements AbstractOverview { +abstract class PersonOverview extends ConsumerWidget implements AbstractOverview { static const route = 'person'; const PersonOverview({super.key}); @override Widget buildOverview( - BuildContext context, { + BuildContext context, + WidgetRef ref, { required String classLocale, required Widget editPage, required VoidCallback onDelete, @@ -34,7 +36,7 @@ abstract class PersonOverview extends StatelessWidget implements AbstractOvervie editPage: editPage, onDelete: () { onDelete(); - dataProvider.deleteSingle(person); + ref.read(dataManagerProvider).deleteSingle(person); }, classLocale: classLocale, children: [ diff --git a/wrestling_scoreboard_client/lib/ui/overview/team_match/league_overview.dart b/wrestling_scoreboard_client/lib/ui/overview/team_match/league_overview.dart index f4cca251..9e37ab50 100644 --- a/wrestling_scoreboard_client/lib/ui/overview/team_match/league_overview.dart +++ b/wrestling_scoreboard_client/lib/ui/overview/team_match/league_overview.dart @@ -1,7 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import 'package:wrestling_scoreboard_client/data/wrestling_style.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/consumer.dart'; import 'package:wrestling_scoreboard_client/ui/components/grouped_list.dart'; import 'package:wrestling_scoreboard_client/ui/components/info.dart'; @@ -9,14 +11,13 @@ import 'package:wrestling_scoreboard_client/ui/edit/team_match/league_edit.dart' import 'package:wrestling_scoreboard_client/ui/edit/team_match/league_team_participation_edit.dart'; import 'package:wrestling_scoreboard_client/ui/edit/team_match/league_weight_class_edit.dart'; import 'package:wrestling_scoreboard_client/ui/overview/common.dart'; +import 'package:wrestling_scoreboard_client/ui/overview/shared/matches_widget.dart'; import 'package:wrestling_scoreboard_client/ui/overview/team_match/league_team_participation_overview.dart'; import 'package:wrestling_scoreboard_client/ui/overview/team_match/league_weight_class_overview.dart'; -import 'package:wrestling_scoreboard_client/ui/overview/shared/matches_widget.dart'; import 'package:wrestling_scoreboard_client/util/date_time.dart'; -import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; -class LeagueOverview extends StatelessWidget { +class LeagueOverview extends ConsumerWidget { static const route = 'league'; final int id; @@ -25,7 +26,7 @@ class LeagueOverview extends StatelessWidget { const LeagueOverview({super.key, required this.id, this.league}); @override - Widget build(BuildContext context) { + Widget build(BuildContext context, WidgetRef ref) { final localizations = AppLocalizations.of(context)!; return SingleConsumer( id: id, @@ -36,7 +37,7 @@ class LeagueOverview extends StatelessWidget { editPage: LeagueEdit( league: data, ), - onDelete: () => dataProvider.deleteSingle(data), + onDelete: () => ref.read(dataManagerProvider).deleteSingle(data), classLocale: localizations.league, children: [ ContentItem( diff --git a/wrestling_scoreboard_client/lib/ui/overview/team_match/league_team_participation_overview.dart b/wrestling_scoreboard_client/lib/ui/overview/team_match/league_team_participation_overview.dart index 4ad0cce8..3dc06bbc 100644 --- a/wrestling_scoreboard_client/lib/ui/overview/team_match/league_team_participation_overview.dart +++ b/wrestling_scoreboard_client/lib/ui/overview/team_match/league_team_participation_overview.dart @@ -1,5 +1,7 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/consumer.dart'; import 'package:wrestling_scoreboard_client/ui/components/grouped_list.dart'; import 'package:wrestling_scoreboard_client/ui/components/info.dart'; @@ -8,7 +10,7 @@ import 'package:wrestling_scoreboard_client/ui/overview/common.dart'; import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; -class LeagueTeamParticipationOverview extends StatelessWidget { +class LeagueTeamParticipationOverview extends ConsumerWidget { static const route = 'league_team_participation'; final int id; @@ -17,7 +19,7 @@ class LeagueTeamParticipationOverview extends StatelessWidget { const LeagueTeamParticipationOverview({super.key, required this.id, this.leagueTeamParticipation}); @override - Widget build(BuildContext context) { + Widget build(BuildContext context, WidgetRef ref) { final localizations = AppLocalizations.of(context)!; return SingleConsumer( id: id, @@ -28,7 +30,7 @@ class LeagueTeamParticipationOverview extends StatelessWidget { editPage: LeagueTeamParticipationEdit( participation: data, ), - onDelete: () => dataProvider.deleteSingle(data), + onDelete: () => ref.read(dataManagerProvider).deleteSingle(data), classLocale: localizations.team, children: [ ContentItem( diff --git a/wrestling_scoreboard_client/lib/ui/overview/team_match/league_weight_class_overview.dart b/wrestling_scoreboard_client/lib/ui/overview/team_match/league_weight_class_overview.dart index 08484626..00112d6a 100644 --- a/wrestling_scoreboard_client/lib/ui/overview/team_match/league_weight_class_overview.dart +++ b/wrestling_scoreboard_client/lib/ui/overview/team_match/league_weight_class_overview.dart @@ -1,9 +1,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/consumer.dart'; import 'package:wrestling_scoreboard_client/ui/edit/team_match/league_weight_class_edit.dart'; import 'package:wrestling_scoreboard_client/ui/overview/weight_class_overview.dart'; -import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; class LeagueWeightClassOverview extends WeightClassOverview { @@ -15,19 +16,19 @@ class LeagueWeightClassOverview extends WeightClassOverview { const LeagueWeightClassOverview({super.key, required this.id, this.leagueWeightClass}); @override - Widget build(BuildContext context) { + Widget build(BuildContext context, WidgetRef ref) { final localizations = AppLocalizations.of(context)!; return SingleConsumer( id: id, initialData: leagueWeightClass, builder: (context, data) { - return buildOverview(context, + return buildOverview(context, ref, classLocale: localizations.weightClass, editPage: LeagueWeightClassEdit( leagueWeightClass: data, initialLeague: data.league, ), - onDelete: () => dataProvider.deleteSingle(data), + onDelete: () => ref.read(dataManagerProvider).deleteSingle(data), tiles: [], dataId: data.weightClass.id!, initialData: data.weightClass); diff --git a/wrestling_scoreboard_client/lib/ui/overview/team_match/team_match_bout_overview.dart b/wrestling_scoreboard_client/lib/ui/overview/team_match/team_match_bout_overview.dart index 687c59f1..3567ddb2 100644 --- a/wrestling_scoreboard_client/lib/ui/overview/team_match/team_match_bout_overview.dart +++ b/wrestling_scoreboard_client/lib/ui/overview/team_match/team_match_bout_overview.dart @@ -1,9 +1,10 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/consumer.dart'; import 'package:wrestling_scoreboard_client/ui/edit/team_match/team_match_bout_edit.dart'; import 'package:wrestling_scoreboard_client/ui/overview/bout_overview.dart'; -import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; class TeamMatchBoutOverview extends BoutOverview { @@ -15,19 +16,19 @@ class TeamMatchBoutOverview extends BoutOverview { const TeamMatchBoutOverview({super.key, required this.id, this.teamMatchBout}); @override - Widget build(BuildContext context) { + Widget build(BuildContext context, WidgetRef ref) { final localizations = AppLocalizations.of(context)!; return SingleConsumer( id: id, initialData: teamMatchBout, builder: (context, data) { - return buildOverview(context, + return buildOverview(context, ref, classLocale: localizations.bout, editPage: TeamMatchBoutEdit( teamMatchBout: data, initialTeamMatch: data.teamMatch, ), - onDelete: () => dataProvider.deleteSingle(data), + onDelete: () => ref.read(dataManagerProvider).deleteSingle(data), tiles: [], dataId: data.bout.id!, initialData: data.bout); diff --git a/wrestling_scoreboard_client/lib/ui/overview/team_match/team_match_overview.dart b/wrestling_scoreboard_client/lib/ui/overview/team_match/team_match_overview.dart index b3440ae4..30a96b5c 100644 --- a/wrestling_scoreboard_client/lib/ui/overview/team_match/team_match_overview.dart +++ b/wrestling_scoreboard_client/lib/ui/overview/team_match/team_match_overview.dart @@ -1,7 +1,9 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:go_router/go_router.dart'; import 'package:wrestling_scoreboard_client/data/bout_utils.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/consumer.dart'; import 'package:wrestling_scoreboard_client/ui/components/grouped_list.dart'; import 'package:wrestling_scoreboard_client/ui/components/info.dart'; @@ -15,7 +17,7 @@ import 'package:wrestling_scoreboard_client/util/date_time.dart'; import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; -class TeamMatchOverview extends StatelessWidget { +class TeamMatchOverview extends ConsumerWidget { static const route = 'match'; final int id; @@ -24,7 +26,7 @@ class TeamMatchOverview extends StatelessWidget { const TeamMatchOverview({required this.id, this.match, super.key}); @override - Widget build(BuildContext context) { + Widget build(BuildContext context, WidgetRef ref) { final localizations = AppLocalizations.of(context)!; final navigator = Navigator.of(context); @@ -62,7 +64,7 @@ class TeamMatchOverview extends StatelessWidget { editPage: TeamMatchEdit( teamMatch: match, ), - onDelete: () => dataProvider.deleteSingle(match), + onDelete: () => ref.read(dataManagerProvider).deleteSingle(match), classLocale: localizations.match, children: [ ContentItem( @@ -142,6 +144,7 @@ class TeamMatchOverview extends StatelessWidget { match.league ?? League.outOfCompetition, match, navigator, + ref.read(dataManagerProvider), )), ContentItem( title: guestLineup.team.name, @@ -151,6 +154,7 @@ class TeamMatchOverview extends StatelessWidget { match.league ?? League.outOfCompetition, match, navigator, + ref.read(dataManagerProvider), )), ], ), @@ -203,9 +207,10 @@ class TeamMatchOverview extends StatelessWidget { context.push('/${TeamMatchOverview.route}/${match.id}/${MatchDisplay.route}'); } - handleSelectedLineup(Lineup lineup, League league, TeamMatch match, NavigatorState navigator) async { - final participations = await dataProvider.readMany(filterObject: lineup); - final weightClasses = await dataProvider.readMany(filterObject: league); + handleSelectedLineup( + Lineup lineup, League league, TeamMatch match, NavigatorState navigator, DataProvider dataManager) async { + final participations = await dataManager.readMany(filterObject: lineup); + final weightClasses = await dataManager.readMany(filterObject: league); navigator.push( MaterialPageRoute( builder: (context) { @@ -214,7 +219,7 @@ class TeamMatchOverview extends StatelessWidget { participations: participations, lineup: lineup, onSubmitGenerate: () { - dataProvider.generateBouts(match, false); + dataManager.generateBouts(match, false); }, ); }, diff --git a/wrestling_scoreboard_client/lib/ui/overview/team_overview.dart b/wrestling_scoreboard_client/lib/ui/overview/team_overview.dart index 35ceaedd..1c92077f 100644 --- a/wrestling_scoreboard_client/lib/ui/overview/team_overview.dart +++ b/wrestling_scoreboard_client/lib/ui/overview/team_overview.dart @@ -1,15 +1,16 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/consumer.dart'; import 'package:wrestling_scoreboard_client/ui/components/grouped_list.dart'; import 'package:wrestling_scoreboard_client/ui/components/info.dart'; import 'package:wrestling_scoreboard_client/ui/edit/team_edit.dart'; import 'package:wrestling_scoreboard_client/ui/overview/common.dart'; import 'package:wrestling_scoreboard_client/ui/overview/shared/matches_widget.dart'; -import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; -class TeamOverview extends StatelessWidget { +class TeamOverview extends ConsumerWidget { static const route = 'team'; final int id; @@ -18,7 +19,7 @@ class TeamOverview extends StatelessWidget { const TeamOverview({super.key, required this.id, this.team}); @override - Widget build(BuildContext context) { + Widget build(BuildContext context, WidgetRef ref) { final localizations = AppLocalizations.of(context)!; return SingleConsumer( id: id, @@ -29,7 +30,7 @@ class TeamOverview extends StatelessWidget { editPage: TeamEdit( team: data, ), - onDelete: () => dataProvider.deleteSingle(data), + onDelete: () => ref.read(dataManagerProvider).deleteSingle(data), classLocale: localizations.team, children: [ ContentItem( diff --git a/wrestling_scoreboard_client/lib/ui/overview/weight_class_overview.dart b/wrestling_scoreboard_client/lib/ui/overview/weight_class_overview.dart index 04b170ed..2fe4f2e9 100644 --- a/wrestling_scoreboard_client/lib/ui/overview/weight_class_overview.dart +++ b/wrestling_scoreboard_client/lib/ui/overview/weight_class_overview.dart @@ -1,19 +1,21 @@ import 'package:flutter/material.dart'; import 'package:flutter_gen/gen_l10n/app_localizations.dart'; +import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:wrestling_scoreboard_client/data/wrestling_style.dart'; +import 'package:wrestling_scoreboard_client/provider/network_provider.dart'; import 'package:wrestling_scoreboard_client/ui/components/consumer.dart'; import 'package:wrestling_scoreboard_client/ui/components/grouped_list.dart'; import 'package:wrestling_scoreboard_client/ui/components/info.dart'; import 'package:wrestling_scoreboard_client/ui/overview/common.dart'; -import 'package:wrestling_scoreboard_client/util/network/data_provider.dart'; import 'package:wrestling_scoreboard_common/common.dart'; -abstract class WeightClassOverview extends StatelessWidget implements AbstractOverview { +abstract class WeightClassOverview extends ConsumerWidget implements AbstractOverview { const WeightClassOverview({super.key}); @override Widget buildOverview( - BuildContext context, { + BuildContext context, + WidgetRef ref, { required String classLocale, required Widget editPage, required VoidCallback onDelete, @@ -31,7 +33,7 @@ abstract class WeightClassOverview extends StatelessWidget implements AbstractOv editPage: editPage, onDelete: () { onDelete(); - dataProvider.deleteSingle(data); + ref.read(dataManagerProvider).deleteSingle(data); }, classLocale: classLocale, children: [ diff --git a/wrestling_scoreboard_client/lib/util/network/data_provider.dart b/wrestling_scoreboard_client/lib/util/network/data_provider.dart index bb93b0d1..3485063e 100644 --- a/wrestling_scoreboard_client/lib/util/network/data_provider.dart +++ b/wrestling_scoreboard_client/lib/util/network/data_provider.dart @@ -1,16 +1,13 @@ import 'dart:async'; -import 'package:wrestling_scoreboard_client/mocks/mock_data_provider.dart'; -import 'package:wrestling_scoreboard_client/util/environment.dart'; -import 'package:wrestling_scoreboard_client/util/network/remote/rest.dart'; +import 'package:wrestling_scoreboard_client/util/network/remote/web_socket.dart'; import 'package:wrestling_scoreboard_common/common.dart'; -final _isMock = Env.appEnvironment.fromString() == 'mock'; - -final dataProvider = _isMock ? MockDataProvider() : RestDataProvider(); - /// Data exchange layer with CRUD operations abstract class DataProvider { + + WebSocketManager get webSocketManager; + /// READ: get a single object Future readSingle(int id); diff --git a/wrestling_scoreboard_client/lib/util/network/remote/rest.dart b/wrestling_scoreboard_client/lib/util/network/remote/rest.dart index 80c86cf9..8683be73 100644 --- a/wrestling_scoreboard_client/lib/util/network/remote/rest.dart +++ b/wrestling_scoreboard_client/lib/util/network/remote/rest.dart @@ -15,7 +15,7 @@ class RestDataProvider extends DataProvider { static const headers = {"Content-Type": "application/json"}; String _apiUrl = Env.apiUrl.fromString(); - late final WebSocketManager _webSocketManager; + late final WebSocketManager webSocketManager; RestDataProvider() { Preferences.getString(Preferences.keyApiUrl).then((value) { @@ -109,7 +109,7 @@ class RestDataProvider extends DataProvider { getManyRawStreamController(filterType: filterType)?.sink.add(tmp); } - _webSocketManager = WebSocketManager((message) { + webSocketManager = WebSocketManager((message) { final json = jsonDecode(message); handleFromJson(json, handleSingle: handleSingle, @@ -150,7 +150,7 @@ class RestDataProvider extends DataProvider { @override Future deleteSingle(T single) async { - _webSocketManager.addToSink(jsonEncode(singleToJson(single, T, CRUD.delete))); + webSocketManager.addToSink(jsonEncode(singleToJson(single, T, CRUD.delete))); } } diff --git a/wrestling_scoreboard_client/lib/util/network/remote/web_socket.dart b/wrestling_scoreboard_client/lib/util/network/remote/web_socket.dart index c88d0690..b4bd4063 100644 --- a/wrestling_scoreboard_client/lib/util/network/remote/web_socket.dart +++ b/wrestling_scoreboard_client/lib/util/network/remote/web_socket.dart @@ -22,9 +22,8 @@ class WebSocketManager { WebSocketChannel? _channel; String? wsUrl; - // TODO: convert to provider /// Manages connection state of WebSocket - static final StreamController onWebSocketConnection = StreamController.broadcast(); + final StreamController onWebSocketConnection = StreamController.broadcast(); WebSocketManager(this.messageHandler) { Preferences.onChangeWsUrlWebSocket.stream.listen((url) {