Skip to content

Commit

Permalink
Merge pull request #246 from hellcp/riverpod-migrate-2.0
Browse files Browse the repository at this point in the history
Update riverpod to the latest version
  • Loading branch information
crc-32 authored May 6, 2024
2 parents 7f4497f + eaaebf5 commit d6c335a
Show file tree
Hide file tree
Showing 21 changed files with 46 additions and 46 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 @@ -80,7 +80,7 @@ class CalendarActionHandler implements ActionHandler {
final calendarList =
await (_calendarList.streamWithExistingValue.firstSuccessOrError() as FutureOr<AsyncValue<List<SelectableCalendar>>>);

final calendars = calendarList.data?.value;
final calendars = calendarList.value;
if (calendars == null) {
return TimelineActionResponse(false);
}
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 @@ -65,7 +65,7 @@ class BackgroundReceiver implements TimelineCallbacks {
final asyncValue =
await container.readUntilFirstSuccessOrError(preferencesProvider);

return asyncValue.data!.value;
return asyncValue.value!;
});

TimelineCallbacks.setup(this);
Expand Down
4 changes: 2 additions & 2 deletions lib/domain/api/appstore/appstore.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@ import 'package:cobble/infrastructure/datasources/web_services/appstore.dart';

final appstoreServiceProvider = FutureProvider<AppstoreService>((ref) async {
final boot = await (await ref.watch(bootServiceProvider.future)).config;
final token = await (await ref.watch(tokenProvider.last));
final token = await (await ref.watch(tokenProvider.future));
final oauth = await ref.watch(oauthClientProvider.future);
final prefs = await ref.watch(preferencesProvider.future);
if (token == null) {
throw NoTokenException("Service requires a token but none was found in storage");
}
return AppstoreService(boot.appstore.base, prefs, oauth, token);
});
});
2 changes: 1 addition & 1 deletion lib/domain/api/auth/auth.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';

final authServiceProvider = FutureProvider<AuthService>((ref) async {
final boot = await (await ref.watch(bootServiceProvider.future)).config;
final token = await (await ref.watch(tokenProvider.last));
final token = await (await ref.watch(tokenProvider.future));
final oauth = await ref.watch(oauthClientProvider.future);
final prefs = await ref.watch(preferencesProvider.future);
if (token == null) {
Expand Down
4 changes: 2 additions & 2 deletions lib/domain/api/boot/boot.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,5 @@ import 'package:cobble/infrastructure/datasources/web_services/boot.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';

final bootServiceProvider = FutureProvider<BootService>(
(ref) async => BootService(await ref.watch(bootUrlProvider.last) ?? ""),
);
(ref) async => BootService(await ref.watch(bootUrlProvider.future) ?? ""),
);
4 changes: 2 additions & 2 deletions lib/domain/calendar/calendar_list.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class CalendarList extends StateNotifier<AsyncValue<List<SelectableCalendar>>> {
await _permissionCheck.hasCalendarPermission();

if (hasCalendarPermission.value == false) {
return AsyncValue.error([ResultError(0, "No permission")]);
return AsyncValue.error([ResultError(0, "No permission")], StackTrace.current);
}

final preferences = await _preferencesFuture;
Expand All @@ -43,7 +43,7 @@ class CalendarList extends StateNotifier<AsyncValue<List<SelectableCalendar>>> {

final calendars = await _deviceCalendarPlugin.retrieveCalendars();
if (!calendars.isSuccess) {
return AsyncValue.error(calendars.errors);
return AsyncValue.error(calendars.errors, StackTrace.current);
} else {
return AsyncValue.data(calendars.data
?.map((c) => SelectableCalendar(
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 @@ -33,7 +33,7 @@ class CalendarSyncer {
return false;
}

final allCalendars = allCalendarsResult.data!.value;
final allCalendars = allCalendarsResult.value!;

final now = _dateTimeProvider();
// 1 day is added since we need to get the start of the next day
Expand Down
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 @@ -134,7 +134,7 @@ class WatchTimelineSyncer {
return;
}

final plugin = pluginValue.data!.value;
final plugin = pluginValue.value!;

const AndroidNotificationDetails androidPlatformChannelSpecifics =
AndroidNotificationDetails("WARNINGS", "Warnings",
Expand Down
4 changes: 2 additions & 2 deletions lib/infrastructure/backgroundcomm/BackgroundRpc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,10 +78,10 @@ class BackgroundRpc {
} else if (receivedMessage.errorResult != null) {
result = AsyncValue.error(
receivedMessage.errorResult!,
stackTrace: receivedMessage.errorStacktrace,
receivedMessage.errorStacktrace ?? StackTrace.current,
);
} else {
result = AsyncValue.error("Received result without any data.");
result = AsyncValue.error("Received result without any data.", StackTrace.current);
}

waitingCompleter.complete(result);
Expand Down
2 changes: 1 addition & 1 deletion lib/infrastructure/datasources/workarounds.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ final neededWorkaroundsProvider = StreamProvider<List<Workaround>>((ref) {
return Stream<List<Workaround>>.empty();
}

final preferences = preferencesData.data!.value;
final preferences = preferencesData.value!;

fetchControls() async {
final workaroundControl = WorkaroundsControl();
Expand Down
6 changes: 3 additions & 3 deletions lib/ui/devoptions/debug_options_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ class DebugOptionsPage extends HookConsumerWidget implements CobbleScreen {
@override
Widget build(BuildContext context, WidgetRef ref) {
final preferences = ref.watch(preferencesProvider);
final bootUrl = ref.watch(bootUrlProvider).data?.value ?? "";
final bootUrl = ref.watch(bootUrlProvider).value ?? "";
final shouldOverrideBoot =
ref.watch(shouldOverrideBootProvider).data?.value ?? false;
ref.watch(shouldOverrideBootProvider).value ?? false;
final overrideBootUrl =
ref.watch(overrideBootValueProvider).data?.value ?? "";
ref.watch(overrideBootValueProvider).value ?? "";

final bootUrlController = useTextEditingController();
final bootOverrideUrlController = useTextEditingController();
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/home/tabs/test_tab.dart
Original file line number Diff line number Diff line change
Expand Up @@ -121,8 +121,8 @@ class TestTab extends HookConsumerWidget implements CobbleScreen {
Switch(
value: workaround.disabled,
onChanged: (value) async {
await preferences.data?.value
.setWorkaroundDisabled(workaround.name, value);
await preferences.value
?.setWorkaroundDisabled(workaround.name, value);
},
),
Text(workaround.name)
Expand Down
8 changes: 4 additions & 4 deletions lib/ui/screens/alerting_app_details.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,16 +51,16 @@ class AlertingAppDetails extends HookConsumerWidget implements CobbleScreen {
child: Switch(
value: app.enabled,
onChanged: (value) async {
var mutedPkgList = mutedPackages.data?.value ?? [];
var mutedPkgList = mutedPackages.value ?? [];
if (value) {
mutedPkgList.removeWhere((element) => element == app.packageId);
}else {
print(app.packageId);
mutedPkgList.add(app.packageId);
}
app = AlertingApp(app.name, value, app.packageId);
await preferences.data?.value
.setNotificationsMutedPackages(mutedPkgList);
await preferences.value
?.setNotificationsMutedPackages(mutedPkgList);
},
),
),
Expand Down Expand Up @@ -101,4 +101,4 @@ class AlertingAppDetails extends HookConsumerWidget implements CobbleScreen {
);
}

}
}
2 changes: 1 addition & 1 deletion lib/ui/screens/alerting_apps.dart
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ class AlertingApps extends HookConsumerWidget implements CobbleScreen {
if (snapshot.hasData && snapshot.data != null) {
List<AlertingApp> apps = [];
for (int i = 0; i < snapshot.data!.packageId!.length; i++) {
final enabled = (mutedPackages.data?.value ?? []).firstWhere(
final enabled = (mutedPackages.value ?? []).firstWhere(
(element) => element == snapshot.data!.packageId![i],
orElse: () => null) ==
null;
Expand Down
8 changes: 4 additions & 4 deletions lib/ui/screens/calendar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,9 @@ class Calendar extends HookConsumerWidget implements CobbleScreen {
title: tr.calendar.toggleTitle,
subtitle: tr.calendar.toggleSubtitle,
child: Switch(
value: calendarSyncEnabled.data?.value ?? false,
value: calendarSyncEnabled.value ?? false,
onChanged: (value) async {
await preferences.data?.value.setCalendarSyncEnabled(value);
await preferences.value?.setCalendarSyncEnabled(value);

if (!value) {
backgroundRpc.triggerMethod(DeleteAllCalendarPinsRequest());
Expand All @@ -57,11 +57,11 @@ class Calendar extends HookConsumerWidget implements CobbleScreen {
),
),
CobbleDivider(),
if (calendarSyncEnabled.data?.value ?? false) ...[
if (calendarSyncEnabled.value ?? false) ...[
CobbleTile.title(
title: tr.calendar.choose,
),
...calendars.data?.value.map((e) {
...calendars.value?.map((e) {
return CobbleTile.setting(
leading: BoxDecoration(
color: Color(e.color).withOpacity(1),
Expand Down
12 changes: 6 additions & 6 deletions lib/ui/screens/notifications.dart
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ class Notifications extends HookConsumerWidget implements CobbleScreen {
leading: RebbleIcons.notification,
title: tr.notifications.enabled,
child: Switch(
value: notifcationsEnabled.data?.value ?? true,
value: notifcationsEnabled.value ?? true,
onChanged: (bool value) async {
await preferences.data?.value.setNotificationsEnabled(value);
await preferences.value?.setNotificationsEnabled(value);
},
),
),
Expand All @@ -55,19 +55,19 @@ class Notifications extends HookConsumerWidget implements CobbleScreen {
leading: CobbleTile.reservedIconSpace,
title: tr.notifications.silence.notifications,
child: Switch(
value: phoneNotificationsMuteEnabled.data?.value ?? false,
value: phoneNotificationsMuteEnabled.value ?? false,
onChanged: (bool value) async {
await preferences.data?.value.setPhoneNotificationMute(value);
await preferences.value?.setPhoneNotificationMute(value);
},
),
),
CobbleTile.setting(
leading: CobbleTile.reservedIconSpace,
title: tr.notifications.silence.calls,
child: Switch(
value: phoneCallsMuteEnabled.data?.value ?? false,
value: phoneCallsMuteEnabled.value ?? false,
onChanged: (bool value) async {
await preferences.data?.value.setPhoneCallsMute(value);
await preferences.value?.setPhoneCallsMute(value);
},
),
),
Expand Down
2 changes: 1 addition & 1 deletion lib/ui/setup/boot/rebble_setup_fail.dart
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ class RebbleSetupFail extends HookConsumerWidget implements CobbleScreen {
),
floatingActionButton: FloatingActionButton.extended(
onPressed: () async {
await preferences.data?.value.setWasSetupSuccessful(false);
await preferences.value?.setWasSetupSuccessful(false);
context.pushAndRemoveAllBelow(HomePage());
},
label: Text(tr.setup.failure.fab)),
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/setup/pair_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ class PairPage extends HookConsumerWidget implements CobbleScreen {
Widget build(BuildContext context, WidgetRef ref) {
final pairedStorage = ref.watch(pairedStorageProvider.notifier);
final scan = ref.watch(scanProvider);
final pair = ref.watch(pairProvider).data?.value;
final pair = ref.watch(pairProvider).value;
final preferences = ref.watch(preferencesProvider);

useEffect(() {
Expand Down Expand Up @@ -99,7 +99,7 @@ class PairPage extends HookConsumerWidget implements CobbleScreen {
StringWrapper addressWrapper = StringWrapper();
addressWrapper.value = dev.address;
uiConnectionControl.connectToWatch(addressWrapper);
preferences.data?.value.setHasBeenConnected();
preferences.value?.setHasBeenConnected();
};

final title = tr.pairPage.title;
Expand Down
4 changes: 2 additions & 2 deletions lib/ui/splash/splash_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -24,12 +24,12 @@ class SplashPage extends HookConsumerWidget {

@override
Widget build(BuildContext context, WidgetRef ref) {
final hasBeenConnected = ref.watch(hasBeenConnectedProvider).data;
final hasBeenConnected = ref.watch(hasBeenConnectedProvider).value;
// Let's not do a timed splash screen here, it's a waste of
// the user's time and there are better platform ways to do it
useEffect(() {
if (hasBeenConnected != null) {
Future.microtask(_openHome(hasBeenConnected.value, context: context));
Future.microtask(_openHome(hasBeenConnected, context: context));
}
}, [hasBeenConnected]);
return CobbleScaffold.page(
Expand Down
12 changes: 6 additions & 6 deletions pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,10 @@ packages:
dependency: transitive
description:
name: flutter_riverpod
sha256: d84e180f039a6b963e610d2e4435641fdfe8f12437e8770e963632e05af16d80
sha256: b6cb0041c6c11cefb2dcb97ef436eba43c6d41287ac6d8ca93e02a497f53a4f3
url: "https://pub.dev"
source: hosted
version: "1.0.4"
version: "2.3.7"
flutter_secure_storage:
dependency: "direct main"
description:
Expand Down Expand Up @@ -473,10 +473,10 @@ packages:
dependency: "direct main"
description:
name: hooks_riverpod
sha256: c2264035396e5fc238e98ef053b07b9cab298450e39c6a8704634c8452c61bbe
sha256: "2bb8ae6a729e1334f71f1ef68dd5f0400dca8f01de8cbdcde062584a68017b18"
url: "https://pub.dev"
source: hosted
version: "1.0.4"
version: "2.3.8"
http:
dependency: transitive
description:
Expand Down Expand Up @@ -817,10 +817,10 @@ packages:
dependency: transitive
description:
name: riverpod
sha256: e7f097159b9512f5953ff544164c19057f45ce28fd0cb971fc4cad1f7b28217d
sha256: b0657b5b30c81a3184bdaab353045f0a403ebd60bb381591a8b7ad77dcade793
url: "https://pub.dev"
source: hosted
version: "1.0.3"
version: "2.3.7"
rxdart:
dependency: "direct main"
description:
Expand Down
2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ dependencies:
sqflite: ^2.2.0
package_info_plus: ^3.0.0
state_notifier: ^0.7.0
hooks_riverpod: ^1.0.1
hooks_riverpod: ^2.0.0
flutter_hooks: ^0.18.0
device_calendar: ^4.3.0
uuid_type: ^2.0.0
Expand Down

0 comments on commit d6c335a

Please sign in to comment.