mirror of
https://github.com/Yubico/yubioath-flutter.git
synced 2024-11-25 23:14:18 +03:00
Simplify the provider used to get WithContext.
This commit is contained in:
parent
13ad504808
commit
9850b4ba29
@ -58,8 +58,7 @@ Future<Widget> initialize() async {
|
||||
ref.read(androidSubPageProvider);
|
||||
|
||||
/// initializes global handler for dialogs
|
||||
FDialogApi.setup(
|
||||
FDialogApiImpl(ref.watch(contextProvider.notifier).withContext));
|
||||
FDialogApi.setup(FDialogApiImpl(ref.watch(withContextProvider)));
|
||||
return const MainPage();
|
||||
},
|
||||
)),
|
||||
|
@ -112,19 +112,12 @@ final qrScannerProvider = Provider<QrScanner?>(
|
||||
(ref) => null,
|
||||
);
|
||||
|
||||
final contextProvider =
|
||||
StateNotifierProvider<ContextProvider, Function(BuildContext)?>(
|
||||
(ref) => ContextProvider());
|
||||
final contextConsumer =
|
||||
StateNotifierProvider<ContextConsumer, Function(BuildContext)?>(
|
||||
(ref) => ContextConsumer());
|
||||
|
||||
/// Signature for the callback to [ContextProvider.withContext].
|
||||
///
|
||||
/// The callback will be invoked with a [BuildContext] that can be used to open
|
||||
/// dialogs, show Snackbars, etc.
|
||||
typedef WithContext = Future<T> Function<T>(
|
||||
Future<T> Function(BuildContext context) action);
|
||||
|
||||
class ContextProvider extends StateNotifier<Function(BuildContext)?> {
|
||||
ContextProvider() : super(null);
|
||||
class ContextConsumer extends StateNotifier<Function(BuildContext)?> {
|
||||
ContextConsumer() : super(null);
|
||||
|
||||
Future<T> withContext<T>(Future<T> Function(BuildContext context) action) {
|
||||
final completer = Completer<T>();
|
||||
@ -138,3 +131,13 @@ class ContextProvider extends StateNotifier<Function(BuildContext)?> {
|
||||
return completer.future;
|
||||
}
|
||||
}
|
||||
|
||||
/// A callback which will be invoked with a [BuildContext] that can be used to
|
||||
/// open dialogs, show Snackbars, etc.
|
||||
///
|
||||
/// Used with the [withContextProvider] provider.
|
||||
typedef WithContext = Future<T> Function<T>(
|
||||
Future<T> Function(BuildContext context) action);
|
||||
|
||||
final withContextProvider = Provider<WithContext>(
|
||||
(ref) => ref.watch(contextConsumer.notifier).withContext);
|
||||
|
@ -15,7 +15,7 @@ class MainPage extends ConsumerWidget {
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
ref.listen<Function(BuildContext)?>(
|
||||
contextProvider,
|
||||
contextConsumer,
|
||||
(previous, next) {
|
||||
next?.call(context);
|
||||
},
|
||||
|
@ -182,7 +182,7 @@ final desktopOathCredentialListProvider = StateNotifierProvider.autoDispose
|
||||
.family<OathCredentialListNotifier, List<OathPair>?, DevicePath>(
|
||||
(ref, devicePath) {
|
||||
var notifier = _DesktopCredentialListNotifier(
|
||||
ref.watch(contextProvider.notifier).withContext,
|
||||
ref.watch(withContextProvider),
|
||||
ref.watch(_sessionProvider(devicePath)),
|
||||
ref.watch(oathStateProvider(devicePath)
|
||||
.select((r) => r.whenOrNull(data: (state) => state.locked) ?? true)),
|
||||
|
Loading…
Reference in New Issue
Block a user