bump to riverpod 2.1.1 and fix deprecations

This commit is contained in:
Adam Velebil 2022-11-30 15:27:32 +01:00
parent cf82012b71
commit 443fadd11f
No known key found for this signature in database
GPG Key ID: AC6D6B9D715FC084
15 changed files with 96 additions and 90 deletions

View File

@ -57,23 +57,37 @@ Future<Widget> initialize() async {
Application.oath,
]),
prefProvider.overrideWithValue(await SharedPreferences.getInstance()),
logLevelProvider.overrideWithProvider(androidLogProvider),
logLevelProvider.overrideWith(
(ref) => ref.watch(androidLogProvider.notifier),
),
attachedDevicesProvider
.overrideWithProvider(androidAttachedDevicesProvider),
currentDeviceDataProvider.overrideWithProvider(androidDeviceDataProvider),
.overrideWith(
() => AndroidAttachedDevicesNotifier(),
),
currentDeviceDataProvider.overrideWith(
(ref) => ref.watch(androidDeviceDataProvider),
),
oathStateProvider.overrideWithProvider(androidOathStateProvider),
credentialListProvider
.overrideWithProvider(androidCredentialListProvider),
currentAppProvider.overrideWithProvider(androidSubPageProvider),
currentAppProvider.overrideWith(
(ref) => ref.watch(androidSubPageProvider.notifier),
),
managementStateProvider.overrideWithProvider(androidManagementState),
currentDeviceProvider.overrideWithProvider(androidCurrentDeviceProvider),
currentDeviceProvider.overrideWith(
() => AndroidCurrentDeviceNotifier(),
),
qrScannerProvider
.overrideWithProvider(androidQrScannerProvider(await getHasCamera())),
windowStateProvider.overrideWithProvider(androidWindowStateProvider),
clipboardProvider.overrideWithProvider(androidClipboardProvider),
.overrideWith(androidQrScannerProvider(await getHasCamera())),
windowStateProvider.overrideWith((ref) => ref.watch(androidWindowStateProvider)),
clipboardProvider.overrideWith(
(ref) => ref.watch(androidClipboardProvider),
),
androidSdkVersionProvider.overrideWithValue(await getAndroidSdkVersion()),
supportedThemesProvider
.overrideWithProvider(androidSupportedThemesProvider)
.overrideWith(
(ref) => ref.watch(androidSupportedThemesProvider),
)
],
child: DismissKeyboard(
child: YubicoAuthenticatorApp(page: Consumer(

View File

@ -15,7 +15,6 @@
*/
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:yubico_authenticator/app/state.dart';
import 'package:yubico_authenticator/cancellation_exception.dart';
import 'package:yubico_authenticator/theme.dart';
@ -46,6 +45,7 @@ class AndroidQrScanner implements QrScanner {
}
}
final androidQrScannerProvider = Provider.family<QrScanner?, bool>(
(ref, hasCamera) =>
hasCamera ? AndroidQrScanner(ref.watch(withContextProvider)) : null);
QrScanner? Function(dynamic) androidQrScannerProvider(hasCamera) {
return (ref) =>
hasCamera ? AndroidQrScanner(ref.watch(withContextProvider)) : null;
}

View File

@ -95,31 +95,20 @@ class _AndroidSubPageNotifier extends CurrentAppNotifier {
}
}
final androidAttachedDevicesProvider =
StateNotifierProvider<AttachedDevicesNotifier, List<DeviceNode>>((ref) {
var currentDeviceData = ref.watch(androidDeviceDataProvider);
List<DeviceNode> devs = currentDeviceData.maybeWhen(
data: (data) => [data.node], orElse: () => []);
return _AndroidAttachedDevicesNotifier(devs);
});
class _AndroidAttachedDevicesNotifier extends AttachedDevicesNotifier {
_AndroidAttachedDevicesNotifier(super.state);
class AndroidAttachedDevicesNotifier extends AttachedDevicesNotifier {
@override
List<DeviceNode> build() => ref
.watch(androidDeviceDataProvider)
.maybeWhen(data: (data) => [data.node], orElse: () => []);
}
final androidDeviceDataProvider = Provider<AsyncValue<YubiKeyData>>(
(ref) => ref.watch(androidYubikeyProvider));
final androidCurrentDeviceProvider =
StateNotifierProvider<CurrentDeviceNotifier, DeviceNode?>((ref) {
final provider =
_AndroidCurrentDeviceNotifier(ref.watch(androidYubikeyProvider));
return provider;
});
class _AndroidCurrentDeviceNotifier extends CurrentDeviceNotifier {
_AndroidCurrentDeviceNotifier(AsyncValue<YubiKeyData> device)
: super(device.whenOrNull(data: (data) => data.node));
class AndroidCurrentDeviceNotifier extends CurrentDeviceNotifier {
@override
DeviceNode? build() =>
ref.watch(androidYubikeyProvider).whenOrNull(data: (data) => data.node);
@override
setCurrentDevice(DeviceNode? device) {

View File

@ -80,12 +80,11 @@ class ThemeModeNotifier extends StateNotifier<ThemeMode> {
// Override with platform implementation
final attachedDevicesProvider =
StateNotifierProvider<AttachedDevicesNotifier, List<DeviceNode>>(
(ref) => AttachedDevicesNotifier([]),
NotifierProvider<AttachedDevicesNotifier, List<DeviceNode>>(
() => throw UnimplementedError(),
);
class AttachedDevicesNotifier extends StateNotifier<List<DeviceNode>> {
AttachedDevicesNotifier(super.state);
abstract class AttachedDevicesNotifier extends Notifier<List<DeviceNode>> {
/// Force a refresh of all device data.
void refresh() {}
@ -98,12 +97,10 @@ final currentDeviceDataProvider = Provider<AsyncValue<YubiKeyData>>(
// Override with platform implementation
final currentDeviceProvider =
StateNotifierProvider<CurrentDeviceNotifier, DeviceNode?>(
(ref) => throw UnimplementedError());
abstract class CurrentDeviceNotifier extends StateNotifier<DeviceNode?> {
CurrentDeviceNotifier(super.state);
NotifierProvider<CurrentDeviceNotifier, DeviceNode?>(
() => throw UnimplementedError());
abstract class CurrentDeviceNotifier extends Notifier<DeviceNode?> {
setCurrentDevice(DeviceNode? device);
}

View File

@ -72,7 +72,7 @@ class AppFailurePage extends ConsumerWidget {
duration: const Duration(seconds: 30));
try {
if (await ref.read(rpcProvider).elevate()) {
ref.refresh(rpcProvider);
ref.invalidate(rpcProvider);
} else {
showMessage(context, 'Permission denied');
}

View File

@ -49,7 +49,7 @@ class DeviceErrorScreen extends ConsumerWidget {
duration: const Duration(seconds: 30));
try {
if (await ref.read(rpcProvider).elevate()) {
ref.refresh(rpcProvider);
ref.invalidate(rpcProvider);
} else {
showMessage(context, 'Permission denied');
}

View File

@ -189,22 +189,19 @@ class NfcDeviceNotifier extends StateNotifier<List<NfcReaderNode>> {
}
}
final desktopDevicesProvider =
StateNotifierProvider<AttachedDevicesNotifier, List<DeviceNode>>((ref) {
final usbDevices = ref.watch(_usbDevicesProvider).toList();
final nfcDevices = ref.watch(_nfcDevicesProvider).toList();
usbDevices.sort((a, b) => a.name.compareTo(b.name));
nfcDevices.sort((a, b) => a.name.compareTo(b.name));
return _DesktopDevicesNotifier(ref, [...usbDevices, ...nfcDevices]);
});
class _DesktopDevicesNotifier extends AttachedDevicesNotifier {
final Ref _ref;
_DesktopDevicesNotifier(this._ref, List<DeviceNode> state) : super(state);
class DesktopDevicesNotifier extends AttachedDevicesNotifier {
@override
List<DeviceNode> build() {
final usbDevices = ref.watch(_usbDevicesProvider).toList();
final nfcDevices = ref.watch(_nfcDevicesProvider).toList();
usbDevices.sort((a, b) => a.name.compareTo(b.name));
nfcDevices.sort((a, b) => a.name.compareTo(b.name));
return [...usbDevices, ...nfcDevices];
}
@override
refresh() {
_ref.read(_usbDevicesProvider.notifier).refresh();
ref.read(_usbDevicesProvider.notifier).refresh();
}
}

View File

@ -58,7 +58,7 @@ final desktopFidoState = StateNotifierProvider.autoDispose
ref.watch(_pinProvider(devicePath).notifier),
);
session.setErrorHandler('state-reset', (_) async {
ref.refresh(_sessionProvider(devicePath));
ref.invalidate(_sessionProvider(devicePath));
});
session.setErrorHandler('auth-required', (_) async {
final pin = ref.read(_pinProvider(devicePath));

View File

@ -119,24 +119,37 @@ Future<Widget> initialize(List<String> argv) async {
]),
prefProvider.overrideWithValue(prefs),
rpcProvider.overrideWithValue(rpc),
windowStateProvider.overrideWithProvider(desktopWindowStateProvider),
attachedDevicesProvider.overrideWithProvider(desktopDevicesProvider),
currentDeviceProvider.overrideWithProvider(desktopCurrentDeviceProvider),
currentDeviceDataProvider.overrideWithProvider(desktopDeviceDataProvider),
windowStateProvider.overrideWith(
(ref) => ref.watch(desktopWindowStateProvider),
),
attachedDevicesProvider.overrideWith(
() => DesktopDevicesNotifier(),
),
currentDeviceProvider.overrideWith(
() => DesktopCurrentDeviceNotifier(),
),
currentDeviceDataProvider.overrideWith(
(ref) => ref.watch(desktopDeviceDataProvider),
),
// OATH
oathStateProvider.overrideWithProvider(desktopOathState),
credentialListProvider
.overrideWithProvider(desktopOathCredentialListProvider),
qrScannerProvider.overrideWithProvider(desktopQrScannerProvider),
qrScannerProvider.overrideWith(
(ref) => ref.watch(desktopQrScannerProvider),
),
// Management
managementStateProvider.overrideWithProvider(desktopManagementState),
// FIDO
fidoStateProvider.overrideWithProvider(desktopFidoState),
fingerprintProvider.overrideWithProvider(desktopFingerprintProvider),
credentialProvider.overrideWithProvider(desktopCredentialProvider),
clipboardProvider.overrideWithProvider(desktopClipboardProvider),
supportedThemesProvider
.overrideWithProvider(desktopSupportedThemesProvider)
clipboardProvider.overrideWith(
(ref) => ref.watch(desktopClipboardProvider),
),
supportedThemesProvider.overrideWith(
(ref) => ref.watch(desktopSupportedThemesProvider),
)
],
child: YubicoAuthenticatorApp(
page: Consumer(

View File

@ -43,7 +43,7 @@ final desktopManagementState = StateNotifierProvider.autoDispose
final session = ref.watch(_sessionProvider(devicePath));
final notifier = _DesktopManagementStateNotifier(ref, session);
session.setErrorHandler('state-reset', (_) async {
ref.refresh(_sessionProvider(devicePath));
ref.invalidate(_sessionProvider(devicePath));
});
ref.onDispose(() {
session.unsetErrorHandler('state-reset');

View File

@ -69,7 +69,7 @@ final desktopOathState = StateNotifierProvider.autoDispose
final notifier = _DesktopOathStateNotifier(session, ref);
session
..setErrorHandler('state-reset', (_) async {
ref.refresh(_sessionProvider(devicePath));
ref.invalidate(_sessionProvider(devicePath));
})
..setErrorHandler('auth-required', (_) async {
await notifier.refresh();
@ -111,7 +111,7 @@ class _DesktopOathStateNotifier extends OathStateNotifier {
Future<void> reset() async {
await _session.command('reset');
_ref.read(_oathLockKeyProvider(_session.devicePath).notifier).unsetKey();
_ref.refresh(_sessionProvider(_session.devicePath));
_ref.invalidate(_sessionProvider(_session.devicePath));
}
@override

View File

@ -151,34 +151,30 @@ final desktopSupportedThemesProvider = StateProvider<List<ThemeMode>>(
(ref) => ThemeMode.values,
);
final desktopCurrentDeviceProvider =
StateNotifierProvider<CurrentDeviceNotifier, DeviceNode?>((ref) {
final provider = _DesktopCurrentDeviceNotifier(ref.watch(prefProvider));
ref.listen(attachedDevicesProvider, provider._updateAttachedDevices);
return provider;
});
class _DesktopCurrentDeviceNotifier extends CurrentDeviceNotifier {
class DesktopCurrentDeviceNotifier extends CurrentDeviceNotifier {
static const String _lastDevice = 'APP_STATE_LAST_DEVICE';
final SharedPreferences _prefs;
DeviceNode? _deviceNode;
_DesktopCurrentDeviceNotifier(this._prefs) : super(null);
@override
DeviceNode? build() {
SharedPreferences prefs = ref.watch(prefProvider);
var devices = ref.watch(attachedDevicesProvider);
_updateAttachedDevices(List<DeviceNode>? previous, List<DeviceNode> devices) {
if (!devices.contains(state)) {
final lastDevice = _prefs.getString(_lastDevice) ?? '';
if (!devices.contains(_deviceNode)) {
final lastDevice = prefs.getString(_lastDevice) ?? '';
try {
state = devices.firstWhere((dev) => dev.path.key == lastDevice,
_deviceNode = devices.firstWhere((dev) => dev.path.key == lastDevice,
orElse: () => devices.whereType<UsbYubiKeyNode>().first);
} on StateError {
state = null;
_deviceNode = null;
}
}
return _deviceNode;
}
@override
setCurrentDevice(DeviceNode? device) {
state = device;
_prefs.setString(_lastDevice, device?.path.key ?? '');
ref.read(prefProvider).setString(_lastDevice, device?.path.key ?? '');
}
}

View File

@ -225,7 +225,7 @@ packages:
name: flutter_riverpod
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
version: "2.1.1"
flutter_test:
dependency: "direct dev"
description: flutter
@ -462,7 +462,7 @@ packages:
name: riverpod
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.2"
version: "2.1.1"
screen_retriever:
dependency: transitive
description:

View File

@ -45,7 +45,7 @@ dependencies:
logging: ^1.1.0
collection: ^1.16.0
shared_preferences: ^2.0.12
flutter_riverpod: ^2.0.2
flutter_riverpod: ^2.1.1
json_annotation: ^4.7.0
freezed_annotation: ^2.2.0
window_manager: ^0.2.7

View File

@ -21,9 +21,9 @@ import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:flutter_test/flutter_test.dart';
import 'package:shared_preferences/shared_preferences.dart';
import 'package:yubico_authenticator/android/keys.dart' as keys;
import 'package:yubico_authenticator/android/preferences.dart';
import 'package:yubico_authenticator/android/state.dart';
import 'package:yubico_authenticator/android/views/android_settings_page.dart';
import 'package:yubico_authenticator/android/preferences.dart';
import 'package:yubico_authenticator/app/state.dart';
import 'package:yubico_authenticator/core/state.dart';
@ -146,7 +146,7 @@ Widget androidWidget({
prefProvider.overrideWithValue(sharedPrefs),
androidSdkVersionProvider.overrideWithValue(sdkVersion),
supportedThemesProvider
.overrideWithProvider(androidSupportedThemesProvider)
.overrideWith((ref) => ref.watch(androidSupportedThemesProvider))
], child: child);
void main() {