Skip to content

Commit

Permalink
Merge pull request #241 from hellcp/riverpod-migrate
Browse files Browse the repository at this point in the history
Update hooks_riverpod to 0.14.0
  • Loading branch information
crc-32 authored Jan 9, 2024
2 parents c25f057 + beb9441 commit a615162
Show file tree
Hide file tree
Showing 39 changed files with 74 additions and 74 deletions.
2 changes: 1 addition & 1 deletion lib/background/actions/calendar_action_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -215,6 +215,6 @@ final calendarActionHandlerProvider = Provider((ref) =>
ref.read(timelinePinDaoProvider),
ref.read(calendarSyncerProvider),
ref.read(watchTimelineSyncerProvider),
ref.read(calendarListProvider),
ref.read(calendarListProvider.notifier),
ref.read(deviceCalendarPluginProvider),
));
2 changes: 1 addition & 1 deletion lib/background/actions/master_action_handler.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:cobble/domain/db/dao/timeline_pin_dao.dart';
import 'package:cobble/domain/db/models/timeline_pin.dart';
import 'package:cobble/domain/timeline/timeline_action_response.dart';
import 'package:cobble/infrastructure/pigeons/pigeons.g.dart';
import 'package:hooks_riverpod/all.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:uuid_type/uuid_type.dart';

class MasterActionHandler {
Expand Down
2 changes: 1 addition & 1 deletion lib/background/main_background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ class BackgroundReceiver implements TimelineCallbacks {
masterActionHandler = container.read(masterActionHandlerProvider);

connectionSubscription = container.listen(
connectionStateProvider.state,
connectionStateProvider,
mayHaveChanged: (sub) {
final currentConnectedWatch = sub.read().currentConnectedWatch;
if (isConnectedToWatch()! && currentConnectedWatch!.name!.isNotEmpty) {
Expand Down
2 changes: 1 addition & 1 deletion lib/background/modules/apps_background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ class AppsBackground implements BackgroundAppInstallCallbacks {
BackgroundAppInstallCallbacks.setup(this);

connectionSubscription = container.listen(
connectionStateProvider.state,
connectionStateProvider,
);
}

Expand Down
2 changes: 1 addition & 1 deletion lib/background/modules/calendar_background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ class CalendarBackground implements CalendarCallbacks {
CalendarCallbacks.setup(this);

connectionSubscription = container.listen(
connectionStateProvider.state,
connectionStateProvider,
);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/domain/api/appstore/locker_sync.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ class LockerSync extends StateNotifier<List<LockerEntry>?> {
}
}

final lockerSyncProvider = AutoDisposeStateNotifierProvider((ref) {
final lockerSyncProvider = AutoDisposeStateNotifierProvider<LockerSync, List<LockerEntry>?>((ref) {
final appstoreFuture = ref.watch(appstoreServiceProvider.future);
final lockerCacheDao = ref.watch(lockerCacheDaoProvider);
return LockerSync(appstoreFuture, lockerCacheDao);
});
});
2 changes: 1 addition & 1 deletion lib/domain/apps/app_install_status.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ AppInstallStatus _getDefault() {
}

final appInstallStatusProvider =
AutoDisposeStateNotifierProvider<AppInstallStatusStateNotifier>((ref) {
AutoDisposeStateNotifierProvider<AppInstallStatusStateNotifier, AppInstallStatus>((ref) {
final notifier = AppInstallStatusStateNotifier();

ref.onDispose(() {
Expand Down
4 changes: 2 additions & 2 deletions lib/domain/apps/app_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -176,9 +176,9 @@ class AppManager extends StateNotifier<List<App>> {
}
}

final appManagerProvider = AutoDisposeStateNotifierProvider<AppManager>((ref) {
final appManagerProvider = AutoDisposeStateNotifierProvider<AppManager, List<App>>((ref) {
final dao = ref.watch(appDaoProvider);
final rpc = ref.read(backgroundRpcProvider);
final lockerSync = ref.watch(lockerSyncProvider);
final lockerSync = ref.watch(lockerSyncProvider.notifier);
return AppManager(dao, rpc, lockerSync);
});
4 changes: 2 additions & 2 deletions lib/domain/calendar/calendar_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ class CalendarList extends StateNotifier<AsyncValue<List<SelectableCalendar>>> {
}
}

final AutoDisposeStateNotifierProvider<CalendarList> calendarListProvider =
StateNotifierProvider.autoDispose<CalendarList>((ref) {
final AutoDisposeStateNotifierProvider<CalendarList, AsyncValue<List<SelectableCalendar>>> calendarListProvider =
StateNotifierProvider.autoDispose<CalendarList, AsyncValue<List<SelectableCalendar>>>((ref) {
// Use auto-dispose to ensure calendar list is reloaded every time user
// re-opens the screen since we cannot propagate change notifications
// between background and UI isolate
Expand Down
2 changes: 1 addition & 1 deletion lib/domain/calendar/calendar_syncer.db.dart
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@ class _EventInCalendar {

final AutoDisposeProvider<CalendarSyncer> calendarSyncerProvider =
Provider.autoDispose<CalendarSyncer>((ref) {
final calendarList = ref.watch(calendarListProvider);
final calendarList = ref.watch(calendarListProvider.notifier);
final deviceCalendar = ref.watch(deviceCalendarPluginProvider);
final dateTimeProvider = ref.watch(currentDateTimeProvider);
final timelinePinDao = ref.watch(timelinePinDaoProvider);
Expand Down
2 changes: 1 addition & 1 deletion lib/domain/calendar/device_calendar_plugin_provider.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:cobble/infrastructure/pigeons/pigeons.g.dart';
import 'package:device_calendar/device_calendar.dart';
import 'package:hooks_riverpod/all.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

final deviceCalendarPluginProvider = Provider((ref) => DeviceCalendarPlugin());

Expand Down
2 changes: 1 addition & 1 deletion lib/domain/calendar/result_converter.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:device_calendar/device_calendar.dart';
import 'package:hooks_riverpod/all.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

extension ResultConverter<T> on Result<T> {
AsyncValue<T> toAsyncValue() {
Expand Down
4 changes: 2 additions & 2 deletions lib/domain/connection/connection_state_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -37,9 +37,9 @@ class ConnectionCallbacksStateNotifier
}
}

final AutoDisposeStateNotifierProvider<ConnectionCallbacksStateNotifier>
final AutoDisposeStateNotifierProvider<ConnectionCallbacksStateNotifier, WatchConnectionState>
connectionStateProvider =
StateNotifierProvider.autoDispose<ConnectionCallbacksStateNotifier>((ref) {
StateNotifierProvider.autoDispose<ConnectionCallbacksStateNotifier, WatchConnectionState>((ref) {
final notifier = ConnectionCallbacksStateNotifier();
ref.onDispose(notifier.dispose);
return notifier;
Expand Down
2 changes: 1 addition & 1 deletion lib/domain/connection/pair_provider.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'dart:async';

import 'package:cobble/infrastructure/pigeons/pigeons.g.dart' as pigeon;
import 'package:hooks_riverpod/all.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

class PairCallbacks implements pigeon.PairCallbacks {
final StreamController<String?> streamController;
Expand Down
4 changes: 2 additions & 2 deletions lib/domain/connection/scan_provider.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:cobble/domain/entities/pebble_scan_device.dart';
import 'package:cobble/infrastructure/pigeons/pigeons.g.dart' as pigeon;
import 'package:hooks_riverpod/all.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

/// Stores state of current scan operation. Devices can be empty array but
/// will never be null.
Expand Down Expand Up @@ -40,7 +40,7 @@ class ScanCallbacks extends StateNotifier<ScanState>
}
}

final scanProvider = StateNotifierProvider<ScanCallbacks>((ref) {
final scanProvider = StateNotifierProvider<ScanCallbacks, ScanState>((ref) {
final notifier = ScanCallbacks();
pigeon.ScanCallbacks.setup(notifier);
ref.onDispose(() {
Expand Down
2 changes: 1 addition & 1 deletion lib/domain/date/date_providers.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:hooks_riverpod/all.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

typedef DateTimeProvider = DateTime Function();

Expand Down
4 changes: 2 additions & 2 deletions lib/domain/db/dao/active_notification_dao.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:cobble/domain/db/models/active_notification.dart';
import 'package:hooks_riverpod/all.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:sqflite/sqflite.dart';
import 'package:uuid_type/uuid_type.dart';

Expand Down Expand Up @@ -70,4 +70,4 @@ class ActiveNotificationDao {
final AutoDisposeProvider<ActiveNotificationDao> activeNotifDaoProvider = Provider.autoDispose((ref) {
final dbFuture = ref.watch(databaseProvider.future);
return ActiveNotificationDao(dbFuture);
});
});
2 changes: 1 addition & 1 deletion lib/domain/local_notifications.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:flutter_local_notifications/flutter_local_notifications.dart';
import 'package:hooks_riverpod/all.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

final localNotificationsPluginProvider =
FutureProvider<FlutterLocalNotificationsPlugin>(
Expand Down
2 changes: 1 addition & 1 deletion lib/domain/permissions.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
import 'package:cobble/infrastructure/pigeons/pigeons.g.dart';
import 'package:hooks_riverpod/all.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

final permissionControlProvider = Provider((ref) => PermissionControl());
final permissionCheckProvider = Provider((ref) => PermissionCheck());
2 changes: 1 addition & 1 deletion lib/domain/preferences.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:hooks_riverpod/all.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:shared_preferences/shared_preferences.dart';

final sharedPreferencesProvider =
Expand Down
4 changes: 2 additions & 2 deletions lib/domain/timeline/watch_apps_syncer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ import '../logging.dart';
class WatchAppsSyncer {
final AppDao appDao;
final AppInstallControl appInstallControl;
final ConnectionCallbacksStateNotifier connectionStateProvider;
final WatchConnectionState connectionStateProvider;
final Future<Preferences> preferences;

WatchAppsSyncer(this.appDao, this.appInstallControl,
Expand Down Expand Up @@ -56,7 +56,7 @@ class WatchAppsSyncer {
}

Future<int?> _performSync() async {
final connectedWatch = connectionStateProvider.state.currentConnectedWatch;
final connectedWatch = connectionStateProvider.currentConnectedWatch;
if (connectedWatch == null) {
return statusWatchDisconnected;
}
Expand Down
4 changes: 2 additions & 2 deletions lib/infrastructure/datasources/dev_connection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -158,9 +158,9 @@ class DevConnState {
DevConnState(this.running, this.connected, this.localIp);
}

final devConnectionProvider = StateNotifierProvider<DevConnection>((ref) {
final devConnectionProvider = StateNotifierProvider<DevConnection, DevConnState>((ref) {
final incomingPacketsStream = ref.read(rawPacketStreamProvider);
final appManager = ref.read(appManagerProvider);
final appManager = ref.read(appManagerProvider.notifier);
return DevConnection(incomingPacketsStream, appManager);
});

Expand Down
6 changes: 3 additions & 3 deletions lib/infrastructure/datasources/paired_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -85,13 +85,13 @@ class PairedStorage extends StateNotifier<List<StoredDevice>> {
}
}

final pairedStorageProvider = StateNotifierProvider((ref) => PairedStorage());
final pairedStorageProvider = StateNotifierProvider<PairedStorage, List<StoredDevice>>((ref) => PairedStorage());
final defaultWatchProvider = Provider((ref) => ref
.watch(pairedStorageProvider.state)
.watch(pairedStorageProvider)
.firstWhereOrNull((element) => element.isDefault!)
?.device);
final ProviderFamily<PebbleScanDevice, dynamic>? specificWatchProvider =
Provider.family(((ref, dynamic address) => ref
.watch(pairedStorageProvider.state)
.watch(pairedStorageProvider)
.firstWhereOrNull((element) => element.device.address == address)
?.device) as PebbleScanDevice Function(ProviderReference, dynamic));
4 changes: 2 additions & 2 deletions lib/infrastructure/datasources/workarounds.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import 'package:cobble/infrastructure/datasources/preferences.dart';
import 'package:cobble/infrastructure/pigeons/pigeons.g.dart';
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/all.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:rxdart/rxdart.dart';

class Workaround {
Expand Down Expand Up @@ -35,4 +35,4 @@ final neededWorkaroundsProvider = StreamProvider<List<Workaround>>((ref) {

return ZipStream(streams, (e) => e as List<Workaround>);
});
});
});
8 changes: 4 additions & 4 deletions lib/ui/devoptions/dev_options_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,12 @@ enum ActionItem { debugOptions }
class DevOptionsPage extends HookWidget implements CobbleScreen {
@override
Widget build(BuildContext context) {
final devConControl = useProvider(devConnectionProvider);
final devConnState = useProvider(devConnectionProvider.state);
final devConControl = useProvider(devConnectionProvider.notifier);
final devConnState = useProvider(devConnectionProvider);

final connectionState = useProvider(connectionStateProvider.state);
final connectionState = useProvider(connectionStateProvider);
final ConnectionControl connectionControl = ConnectionControl();
final pairedStorage = useProvider(pairedStorageProvider);
final pairedStorage = useProvider(pairedStorageProvider.notifier);

void _onDisconnectPressed(bool inSettings) {
connectionControl.disconnect();
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/devoptions/test_logs_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
class TestLogsPage extends HookWidget implements CobbleScreen {
@override
Widget build(BuildContext context) {
final logs = useProvider(recievedLogsProvider.state);
final logs = useProvider(recievedLogsProvider);

return ListView.builder(
itemBuilder: (context, index) {
Expand Down
6 changes: 3 additions & 3 deletions lib/ui/home/tabs/locker_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,12 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
class LockerTab extends HookWidget implements CobbleScreen {
@override
Widget build(BuildContext context) {
final connectionState = useProvider(connectionStateProvider.state);
final connectionState = useProvider(connectionStateProvider);

final currentWatch = connectionState.currentConnectedWatch;

final appManager = useProvider(appManagerProvider);
List allPackages = useProvider(appManagerProvider.state);
final appManager = useProvider(appManagerProvider.notifier);
List allPackages = useProvider(appManagerProvider);
List incompatibleApps =
allPackages.where((element) => !element.isWatchface).toList();
List incompatibleFaces =
Expand Down
6 changes: 3 additions & 3 deletions lib/ui/home/tabs/watches_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,10 @@ class MyWatchesTab extends HookWidget implements CobbleScreen {

@override
Widget build(BuildContext context) {
final connectionState = useProvider(connectionStateProvider.state);
final connectionState = useProvider(connectionStateProvider);
final defaultWatch = useProvider(defaultWatchProvider);
final pairedStorage = useProvider(pairedStorageProvider);
final allWatches = useProvider(pairedStorageProvider.state);
final pairedStorage = useProvider(pairedStorageProvider.notifier);
final allWatches = useProvider(pairedStorageProvider);
final preferencesFuture = useProvider(preferencesProvider.future);

List<PebbleScanDevice> allWatchesList =
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/screens/calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ class Calendar extends HookWidget implements CobbleScreen {

@override
Widget build(BuildContext context) {
final calendars = useProvider(calendarListProvider.state);
final calendarSelector = useProvider(calendarListProvider);
final calendars = useProvider(calendarListProvider);
final calendarSelector = useProvider(calendarListProvider.notifier);
final calendarControl = useProvider(calendarControlProvider);
final backgroundRpc = useProvider(backgroundRpcProvider);

Expand Down
6 changes: 3 additions & 3 deletions lib/ui/screens/install_prompt.dart
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ class InstallPrompt extends HookWidget implements CobbleScreen {
final userInitiatedInstall = useState(false);
final watchUploadHasStarted = useState(false);

final installStatus = useProvider(appInstallStatusProvider.state);
final appManager = useProvider(appManagerProvider);
final connectionStatus = useProvider(connectionStateProvider.state);
final installStatus = useProvider(appInstallStatusProvider);
final appManager = useProvider(appManagerProvider.notifier);
final connectionStatus = useProvider(connectionStateProvider);

final connectedWatch = connectionStatus.currentConnectedWatch;

Expand Down
8 changes: 4 additions & 4 deletions lib/ui/setup/pair_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -49,8 +49,8 @@ class PairPage extends HookWidget implements CobbleScreen {

@override
Widget build(BuildContext context) {
final pairedStorage = useProvider(pairedStorageProvider);
final scan = useProvider(scanProvider.state);
final pairedStorage = useProvider(pairedStorageProvider.notifier);
final scan = useProvider(scanProvider);
final pair = useProvider(pairProvider).data?.value;
final preferences = useProvider(preferencesProvider);

Expand Down Expand Up @@ -83,14 +83,14 @@ class PairPage extends HookWidget implements CobbleScreen {

final _refreshDevicesBle = () {
if (!scan.scanning) {
context.refresh(scanProvider).onScanStarted();
context.refresh(scanProvider.notifier).onScanStarted();
scanControl.startBleScan();
}
};

final _refreshDevicesClassic = () {
if (!scan.scanning) {
context.refresh(scanProvider).onScanStarted();
context.refresh(scanProvider.notifier).onScanStarted();
scanControl.startClassicScan();
}
};
Expand Down
2 changes: 1 addition & 1 deletion lib/util/container_extensions.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:async';

import 'package:hooks_riverpod/all.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

import 'stream_extensions.dart';

Expand Down
2 changes: 1 addition & 1 deletion lib/util/state_provider_extension.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'dart:async';

import 'package:hooks_riverpod/all.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

extension StateProviderExtension<T> on StateNotifier<T> {
/// Variant of StateNotifier.stream that also returns existing value
Expand Down
2 changes: 1 addition & 1 deletion lib/util/stream_extensions.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import 'package:hooks_riverpod/all.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

extension StreamExtension<T> on Stream<AsyncValue<T>?> {
Future<AsyncValue<T>?> firstSuccessOrError() {
Expand Down
Loading

0 comments on commit a615162

Please sign in to comment.