Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update riverpod to 1.0 #243

Merged
merged 1 commit into from
Jan 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -210,7 +210,7 @@ class CalendarActionHandler implements ActionHandler {
}
}

final calendarActionHandlerProvider = Provider((ref) =>
final calendarActionHandlerProvider = Provider<CalendarActionHandler>((ref) =>
CalendarActionHandler(
ref.read(timelinePinDaoProvider),
ref.read(calendarSyncerProvider),
Expand Down
7 changes: 3 additions & 4 deletions lib/background/main_background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -52,10 +52,9 @@ class BackgroundReceiver implements TimelineCallbacks {

masterActionHandler = container.read(masterActionHandlerProvider);

connectionSubscription = container.listen(
connectionStateProvider,
mayHaveChanged: (sub) {
final currentConnectedWatch = sub.read().currentConnectedWatch;
connectionSubscription = container.listen<WatchConnectionState>(
connectionStateProvider, (previous, sub) {
final currentConnectedWatch = sub.currentConnectedWatch;
if (isConnectedToWatch()! && currentConnectedWatch!.name!.isNotEmpty) {
onWatchConnected(currentConnectedWatch);
}
Expand Down
12 changes: 6 additions & 6 deletions lib/background/modules/apps_background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,15 @@ class AppsBackground implements BackgroundAppInstallCallbacks {
AppsBackground(this.container);

void init() async {
watchAppsSyncer = container.listen(watchAppSyncerProvider).read();
appDao = container.listen(appDaoProvider).read();
appLifecycleManager = container.listen(appLifecycleManagerProvider).read();
preferences = container.listen(preferencesProvider.future).read();
watchAppsSyncer = container.listen<WatchAppsSyncer>(watchAppSyncerProvider, (previous, value) {}).read();
appDao = container.listen<AppDao>(appDaoProvider, (previous, value) {}).read();
appLifecycleManager = container.listen<AppLifecycleManager>(appLifecycleManagerProvider, (previous, value) {}).read();
preferences = container.listen<Future<Preferences>>(preferencesProvider.future, (previous, value) {}).read();

BackgroundAppInstallCallbacks.setup(this);

connectionSubscription = container.listen(
connectionStateProvider,
connectionSubscription = container.listen<WatchConnectionState>(
connectionStateProvider, (previous, value) {},
);
}

Expand Down
10 changes: 5 additions & 5 deletions lib/background/modules/calendar_background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,14 +21,14 @@ class CalendarBackground implements CalendarCallbacks {
CalendarBackground(this.container);

void init() async {
calendarSyncer = container.listen(calendarSyncerProvider).read();
watchTimelineSyncer = container.listen(watchTimelineSyncerProvider).read();
timelinePinDao = container.listen(timelinePinDaoProvider).read();
calendarSyncer = container.listen<CalendarSyncer>(calendarSyncerProvider, (previous, value) {}).read();
watchTimelineSyncer = container.listen<WatchTimelineSyncer>(watchTimelineSyncerProvider, (previous, value) {}).read();
timelinePinDao = container.listen<TimelinePinDao>(timelinePinDaoProvider, (previous, value) {}).read();

CalendarCallbacks.setup(this);

connectionSubscription = container.listen(
connectionStateProvider,
connectionSubscription = container.listen<WatchConnectionState>(
connectionStateProvider, (previous, value) {},
);
}

Expand Down
4 changes: 2 additions & 2 deletions lib/background/modules/notifications_background.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class NotificationsBackground implements NotificationListening {
NotificationsBackground(this.container);

void init() async {
notificationManager = container.listen(notificationManagerProvider).read();
_notificationChannelDao = container.listen(notifChannelDaoProvider).read();
notificationManager = container.listen<NotificationManager>(notificationManagerProvider, (previous, value) {}).read();
_notificationChannelDao = container.listen<NotificationChannelDao>(notifChannelDaoProvider, (previous, value) {}).read();

NotificationListening.setup(this);
}
Expand Down
2 changes: 1 addition & 1 deletion lib/background/notification/notification_manager.dart
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class NotificationManager {
}
}

final notificationManagerProvider = Provider((ref) => NotificationManager(ref.read(activeNotifDaoProvider), ref.read(notifChannelDaoProvider), ref.read(sharedPreferencesProvider)));
final notificationManagerProvider = Provider<NotificationManager>((ref) => NotificationManager(ref.read(activeNotifDaoProvider), ref.read(notifChannelDaoProvider), ref.read(sharedPreferencesProvider)));

final disabledActionPackagesKey = "disabledActionPackages";

Expand Down
2 changes: 1 addition & 1 deletion lib/domain/api/appstore/appstore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import 'package:cobble/infrastructure/datasources/secure_storage.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:cobble/infrastructure/datasources/web_services/appstore.dart';

final appstoreServiceProvider = FutureProvider((ref) async {
final appstoreServiceProvider = FutureProvider<AppstoreService>((ref) async {
final boot = await (await ref.watch(bootServiceProvider.future)).config;
final token = await (await ref.watch(tokenProvider.last));
final oauth = await ref.watch(oauthClientProvider.future);
Expand Down
7 changes: 4 additions & 3 deletions lib/domain/api/auth/auth.dart
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
import 'package:cobble/domain/api/auth/oauth.dart';
import 'package:cobble/domain/api/auth/user.dart';
import 'package:cobble/domain/api/boot/boot.dart';
import 'package:cobble/domain/api/no_token_exception.dart';
import 'package:cobble/infrastructure/datasources/preferences.dart';
import 'package:cobble/infrastructure/datasources/secure_storage.dart';
import 'package:cobble/infrastructure/datasources/web_services/auth.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

final authServiceProvider = FutureProvider((ref) async {
final authServiceProvider = FutureProvider<AuthService>((ref) async {
final boot = await (await ref.watch(bootServiceProvider.future)).config;
final token = await (await ref.watch(tokenProvider.last));
final oauth = await ref.watch(oauthClientProvider.future);
Expand All @@ -17,11 +18,11 @@ final authServiceProvider = FutureProvider((ref) async {
return AuthService(boot.auth.base, prefs, oauth, token);
});

final authUserProvider = FutureProvider((ref) async {
final authUserProvider = FutureProvider<User?>((ref) async {
try {
final auth = await ref.watch(authServiceProvider.future);
return await auth.user;
} on NoTokenException {
return null;
}
});
});
2 changes: 1 addition & 1 deletion lib/domain/api/auth/oauth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -186,7 +186,7 @@ class OAuthException implements Exception {
String toString() => "OAuthException: $errorCode";
}

final oauthClientProvider = FutureProvider((ref) async {
final oauthClientProvider = FutureProvider<OAuthClient>((ref) async {
final boot = await (await ref.watch(bootServiceProvider.future)).config;
final prefs = await ref.watch(preferencesProvider.future);
final secureStorage = ref.watch(secureStorageProvider);
Expand Down
2 changes: 1 addition & 1 deletion lib/domain/api/boot/boot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import 'package:cobble/infrastructure/datasources/preferences.dart';
import 'package:cobble/infrastructure/datasources/web_services/boot.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

final bootServiceProvider = FutureProvider(
final bootServiceProvider = FutureProvider<BootService>(
(ref) async => BootService(await ref.watch(bootUrlProvider.last) ?? ""),
);
2 changes: 1 addition & 1 deletion lib/domain/apps/app_logs.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ class AppLogReceiver extends StateNotifier<List<AppLogEntry>>
}
}

final recievedLogsProvider = StateNotifierProvider.autoDispose((ref) {
final recievedLogsProvider = StateNotifierProvider.autoDispose<AppLogReceiver, dynamic>((ref) {
final receiver = AppLogReceiver();

ref.onDispose(() {
Expand Down
4 changes: 2 additions & 2 deletions lib/domain/calendar/device_calendar_plugin_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@ import 'package:cobble/infrastructure/pigeons/pigeons.g.dart';
import 'package:device_calendar/device_calendar.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

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

final calendarControlProvider = Provider((ref) => CalendarControl());
final calendarControlProvider = Provider<CalendarControl>((ref) => CalendarControl());
2 changes: 1 addition & 1 deletion lib/domain/connection/raw_incoming_packets_provider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ class RawIncomingPacketsProvider implements RawIncomingPacketsCallbacks {
Stream<Uint8List> get stream => _streamController.stream;
}

final Provider<Stream<Uint8List>> rawPacketStreamProvider = Provider((ref) => RawIncomingPacketsProvider().stream);
final Provider<Stream<Uint8List>> rawPacketStreamProvider = Provider<Stream<Uint8List>>((ref) => RawIncomingPacketsProvider().stream);

2 changes: 1 addition & 1 deletion lib/domain/db/dao/active_notification_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ class ActiveNotificationDao {
}
}

final AutoDisposeProvider<ActiveNotificationDao> activeNotifDaoProvider = Provider.autoDispose((ref) {
final AutoDisposeProvider<ActiveNotificationDao> activeNotifDaoProvider = Provider.autoDispose<ActiveNotificationDao>((ref) {
final dbFuture = ref.watch(databaseProvider.future);
return ActiveNotificationDao(dbFuture);
});
2 changes: 1 addition & 1 deletion lib/domain/db/dao/app_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ class AppDao {
}
}

final AutoDisposeProvider<AppDao> appDaoProvider = Provider.autoDispose((ref) {
final AutoDisposeProvider<AppDao> appDaoProvider = Provider.autoDispose<AppDao>((ref) {
final dbFuture = ref.watch(databaseProvider.future);
return AppDao(dbFuture);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/domain/db/dao/locker_cache_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ class LockerCacheDao {
}
}

final AutoDisposeProvider<LockerCacheDao> lockerCacheDaoProvider = Provider.autoDispose((ref) {
final AutoDisposeProvider<LockerCacheDao> lockerCacheDaoProvider = Provider.autoDispose<LockerCacheDao>((ref) {
final dbFuture = ref.watch(databaseProvider.future);
return LockerCacheDao(dbFuture);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/domain/db/dao/notification_channel_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ class NotificationChannelDao {
}
}

final AutoDisposeProvider<NotificationChannelDao> notifChannelDaoProvider = Provider.autoDispose((ref) {
final AutoDisposeProvider<NotificationChannelDao> notifChannelDaoProvider = Provider.autoDispose<NotificationChannelDao>((ref) {
final dbFuture = ref.watch(databaseProvider!.future);
return NotificationChannelDao(dbFuture);
});
2 changes: 1 addition & 1 deletion lib/domain/db/dao/timeline_pin_dao.dart
Original file line number Diff line number Diff line change
Expand Up @@ -136,7 +136,7 @@ class TimelinePinDao {
}

final AutoDisposeProvider<TimelinePinDao> timelinePinDaoProvider =
Provider.autoDispose((ref) {
Provider.autoDispose<TimelinePinDao>((ref) {
final dbFuture = ref.watch(databaseProvider.future);
return TimelinePinDao(dbFuture);
});
Expand Down
2 changes: 1 addition & 1 deletion lib/domain/package_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ import 'package:cobble/infrastructure/pigeons/pigeons.g.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

final packageDetailsProvider =
Provider((ref) => PackageDetails());
Provider<PackageDetails>((ref) => PackageDetails());
4 changes: 2 additions & 2 deletions 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/hooks_riverpod.dart';

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

final sharedPreferencesProvider =
Provider((ref) => SharedPreferences.getInstance());
Provider<Future<SharedPreferences>>((ref) => SharedPreferences.getInstance());
2 changes: 1 addition & 1 deletion lib/domain/secure_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';

const _androidOptions = AndroidOptions(encryptedSharedPreferences: true);
final flutterSecureStorageProvider =
Provider((ref) => const FlutterSecureStorage(aOptions: _androidOptions));
Provider<FlutterSecureStorage>((ref) => const FlutterSecureStorage(aOptions: _androidOptions));
2 changes: 1 addition & 1 deletion lib/domain/timeline/watch_apps_syncer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -160,4 +160,4 @@ Provider.autoDispose<WatchAppsSyncer>((ref) {
);
});

final appInstallControlProvider = Provider((ref) => AppInstallControl());
final appInstallControlProvider = Provider<AppInstallControl>((ref) => AppInstallControl());
2 changes: 1 addition & 1 deletion lib/domain/timeline/watch_timeline_syncer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -168,4 +168,4 @@ final AutoDisposeProvider<WatchTimelineSyncer> watchTimelineSyncerProvider =
);
});

final timelineSyncControlProvider = Provider((ref) => TimelineSyncControl());
final timelineSyncControlProvider = Provider<TimelineSyncControl>((ref) => TimelineSyncControl());
2 changes: 1 addition & 1 deletion lib/infrastructure/backgroundcomm/BackgroundRpc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ class BackgroundRpc {
} else if (receivedMessage.errorResult != null) {
result = AsyncValue.error(
receivedMessage.errorResult!,
receivedMessage.errorStacktrace,
stackTrace: receivedMessage.errorStacktrace,
);
} else {
result = AsyncValue.error("Received result without any data.");
Expand Down
4 changes: 2 additions & 2 deletions lib/infrastructure/datasources/paired_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -86,12 +86,12 @@ class PairedStorage extends StateNotifier<List<StoredDevice>> {
}

final pairedStorageProvider = StateNotifierProvider<PairedStorage, List<StoredDevice>>((ref) => PairedStorage());
final defaultWatchProvider = Provider((ref) => ref
final defaultWatchProvider = Provider<PebbleScanDevice?>((ref) => ref
.watch(pairedStorageProvider)
.firstWhereOrNull((element) => element.isDefault!)
?.device);
final ProviderFamily<PebbleScanDevice, dynamic>? specificWatchProvider =
Provider.family(((ref, dynamic address) => ref
.watch(pairedStorageProvider)
.firstWhereOrNull((element) => element.device.address == address)
?.device) as PebbleScanDevice Function(ProviderReference, dynamic));
?.device) as PebbleScanDevice Function(Ref, dynamic));
22 changes: 11 additions & 11 deletions lib/infrastructure/datasources/preferences.dart
Original file line number Diff line number Diff line change
Expand Up @@ -166,23 +166,23 @@ final preferencesProvider = FutureProvider<Preferences>((ref) async {
return Preferences(sharedPreferences);
});

final calendarSyncEnabledProvider = _createPreferenceProvider(
final calendarSyncEnabledProvider = _createPreferenceProvider<bool?>(
(preferences) => preferences.isCalendarSyncEnabled(),
);

final phoneNotificationsMuteProvider = _createPreferenceProvider(
final phoneNotificationsMuteProvider = _createPreferenceProvider<bool?>(
(preferences) => preferences.isPhoneNotificationMuteEnabled(),
);

final phoneCallsMuteProvider = _createPreferenceProvider(
final phoneCallsMuteProvider = _createPreferenceProvider<bool?>(
(preferences) => preferences.isPhoneCallMuteEnabled(),
);

final notificationToggleProvider = _createPreferenceProvider(
final notificationToggleProvider = _createPreferenceProvider<bool?>(
(preferences) => preferences.areNotificationsEnabled(),
);

final notificationsMutedPackagesProvider = _createPreferenceProvider(
final notificationsMutedPackagesProvider = _createPreferenceProvider<List<String?>>(
(preferences) => preferences.getNotificationsMutedPackages(),
);

Expand All @@ -197,29 +197,29 @@ final notificationsMutedPackagesProvider = _createPreferenceProvider(
/// hasBeenConnected.then((value) => /*...*/);
/// }, []);
/// ```
final hasBeenConnectedProvider = _createPreferenceProvider(
final hasBeenConnectedProvider = _createPreferenceProvider<bool>(
(preferences) => preferences.hasBeenConnected(),
);

final wasSetupSuccessfulProvider = _createPreferenceProvider(
final wasSetupSuccessfulProvider = _createPreferenceProvider<bool>(
(preferences) => preferences.wasSetupSuccessful(),
);

final bootUrlProvider = _createPreferenceProvider(
final bootUrlProvider = _createPreferenceProvider<String?>(
(preferences) {
return preferences.getBoot();
},
);

final overrideBootValueProvider = _createPreferenceProvider(
final overrideBootValueProvider = _createPreferenceProvider<String?>(
(preferences) => preferences.getOverrideBootValue(),
);

final shouldOverrideBootProvider = _createPreferenceProvider(
final shouldOverrideBootProvider = _createPreferenceProvider<bool?>(
(preferences) => preferences.shouldOverrideBoot(),
);

final oauthTokenCreationDateProvider = _createPreferenceProvider(
final oauthTokenCreationDateProvider = _createPreferenceProvider<DateTime?>(
(preferences) => preferences.getOAuthTokenCreationDate(),
);

Expand Down
6 changes: 3 additions & 3 deletions lib/infrastructure/datasources/secure_storage.dart
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ class SecureStorage {
}

final secureStorageProvider =
Provider((ref) => SecureStorage(ref.watch(flutterSecureStorageProvider)));
Provider<SecureStorage>((ref) => SecureStorage(ref.watch(flutterSecureStorageProvider)));

final tokenProvider =
_createSecureStorageItemProvider((secureStorage) => secureStorage.getToken());
_createSecureStorageItemProvider<Future<OAuthToken?>>((secureStorage) => secureStorage.getToken());

StreamProvider<T> _createSecureStorageItemProvider<T>(
T Function(SecureStorage secureStorage) mapper,
Expand All @@ -54,4 +54,4 @@ StreamProvider<T> _createSecureStorageItemProvider<T>(
.map(mapper)
.distinct();
});
}
}
12 changes: 6 additions & 6 deletions lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ void initBackground() {
BackgroundSetupControl().setupBackground(wrapper);
}

class MyApp extends HookWidget {
class MyApp extends HookConsumerWidget {
@override
Widget build(BuildContext context) {
final permissionControl = useProvider(permissionControlProvider);
final permissionCheck = useProvider(permissionCheckProvider);
final defaultWatch = useProvider(defaultWatchProvider);
final preferences = useProvider(preferencesProvider.future);
Widget build(BuildContext context, WidgetRef ref) {
final permissionControl = ref.watch(permissionControlProvider);
final permissionCheck = ref.watch(permissionCheckProvider);
final defaultWatch = ref.watch(defaultWatchProvider);
final preferences = ref.watch(preferencesProvider.future);

useEffect(() {
Future.microtask(() async {
Expand Down
Loading
Loading