Skip to content

Commit

Permalink
fix otpauth from link klick
Browse files Browse the repository at this point in the history
  • Loading branch information
frankmer committed Oct 29, 2024
1 parent b9c401f commit 8b1eb1b
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 11 deletions.
6 changes: 4 additions & 2 deletions lib/state_notifiers/deeplink_notifier.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ class DeeplinkNotifier extends StateNotifier<DeepLink?> {

for (var source in _sources) {
_subs.add(source.stream.listen((Uri? uri) {
Logger.info('Got uri from ${source.name}');
if (!_initialUriIsHandled) return;
Logger.info('Got uri from ${source.name} (incoming)');
if (!mounted) return;
if (uri == null) return;
state = DeepLink(uri);
Expand All @@ -46,14 +47,15 @@ class DeeplinkNotifier extends StateNotifier<DeepLink?> {
Future<void> _handleInitialUri() async {
if (_initialUriIsHandled) return;
_initialUriIsHandled = true;

Logger.info('_handleInitialUri called');

for (var source in _sources) {
final initialUri = await source.initialUri;
if (initialUri != null) {
if (!mounted) return;
Logger.info('Got uri from ${source.name} (initial)');
state = DeepLink(initialUri, fromInit: true);
Logger.info('Got initial uri from ${source.name}');
return; // There should be only one initial uri
}
}
Expand Down
15 changes: 12 additions & 3 deletions lib/utils/riverpod_providers.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import 'package:app_links/app_links.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

import '../l10n/app_localizations.dart';
Expand Down Expand Up @@ -35,6 +35,8 @@ import 'riverpod_state_listener.dart';
/// Otherwise the whole app will rebuild on every state change of the provider
WidgetRef? globalRef;

Future<void> _handleUri(WidgetRef? ref, Uri uri) async => ref?.read(tokenProvider.notifier).handleLink(uri);

final tokenProvider = StateNotifierProvider<TokenNotifier, TokenState>(
(ref) {
Logger.info("New TokenNotifier created");
Expand All @@ -46,7 +48,10 @@ final tokenProvider = StateNotifierProvider<TokenNotifier, TokenState>(
return;
}
Logger.info("Received new deeplink", name: 'tokenProvider#deeplinkProvider');
newTokenNotifier.handleLink(newLink.uri);
WidgetsBinding.instance.addPostFrameCallback((_) async {
await Future.delayed(Duration(milliseconds: 500));
_handleUri(globalRef, newLink.uri);
});
});

return newTokenNotifier;
Expand Down Expand Up @@ -102,7 +107,11 @@ final deeplinkProvider = StateNotifierProvider<DeeplinkNotifier, DeepLink?>(
(ref) {
Logger.info("New DeeplinkNotifier created", name: 'deeplinkProvider');
return DeeplinkNotifier(sources: [
DeeplinkSource(name: 'uni_links', stream: AppLinks().uriLinkStream, initialUri: AppLinks().getInitialLink()),
DeeplinkSource(
name: 'uni_links',
stream: AppLinks().uriLinkStream,
initialUri: Future.value(null), // We got the initial uri from uni_links in both (initial and incoming) cases
),
DeeplinkSource(
name: 'home_widget',
stream: HomeWidgetUtils().widgetClicked,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ class _MainViewTokensListState extends ConsumerState<MainViewTokensList> {
@override
Widget build(BuildContext context) {
final draggingSortable = ref.watch(draggingSortableProvider);
final allSortables = ref.watch(sortableProvider);
final allSortables = [...ref.watch(tokenProvider).tokens, ...ref.watch(tokenFolderProvider).folders];
final allowToRefresh = allSortables.any((element) => element is PushToken);
bool filterPushTokens = ref.watch(settingsProvider).hidePushTokens && allowToRefresh;

Expand All @@ -77,7 +77,6 @@ class _MainViewTokensListState extends ConsumerState<MainViewTokensList> {
if (element.folderId != null) continue;
showSortables.add(element);
}

if ((showSortables.isEmpty)) return const NoTokenScreen();
return Stack(
children: [
Expand Down Expand Up @@ -144,12 +143,10 @@ class _MainViewTokensListState extends ConsumerState<MainViewTokensList> {
),
),
),
],
);

],
);
}


ScrollPhysics _getScrollPhysics(bool allowToRefresh) =>
allowToRefresh ? const AlwaysScrollableScrollPhysics(parent: ClampingScrollPhysics()) : const BouncingScrollPhysics();
}

0 comments on commit 8b1eb1b

Please sign in to comment.