Handle sharing intents
This commit is contained in:
@@ -4,16 +4,20 @@ import 'package:flutter/foundation.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/services.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:flutter_localizations/flutter_localizations.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:dynamic_color/dynamic_color.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:receive_sharing_intent/receive_sharing_intent.dart';
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'package:linkdy/constants/global_keys.dart';
|
||||
import 'package:linkdy/providers/app_status.provider.dart';
|
||||
import 'package:linkdy/router/paths.dart';
|
||||
import 'package:linkdy/providers/app_info.provider.dart';
|
||||
import 'package:linkdy/providers/receive_sharing_intent_url.provider.dart';
|
||||
import 'package:linkdy/config/theme.dart';
|
||||
import 'package:linkdy/constants/colors.dart';
|
||||
import 'package:linkdy/i18n/strings.g.dart';
|
||||
@@ -61,7 +65,7 @@ void main() async {
|
||||
}
|
||||
}
|
||||
|
||||
class MyApp extends ConsumerWidget {
|
||||
class MyApp extends HookConsumerWidget {
|
||||
const MyApp({super.key});
|
||||
|
||||
@override
|
||||
@@ -69,6 +73,33 @@ class MyApp extends ConsumerWidget {
|
||||
final selectedColor = ref.watch(appStatusProvider).selectedColor;
|
||||
final useDynamicColor = ref.watch(appStatusProvider).useDynamicTheme;
|
||||
|
||||
useEffect(
|
||||
() {
|
||||
// When app is on background
|
||||
ReceiveSharingIntent.getMediaStream().listen(
|
||||
(value) {
|
||||
if (value.isNotEmpty) {
|
||||
ref.read(receiveSharingIntentUrlProvider.notifier).setValue(value[0].path);
|
||||
ref.read(routerProvider).go(RoutesPaths.bookmarks);
|
||||
}
|
||||
},
|
||||
onError: (e, stackTrace) => Sentry.captureException(e, stackTrace: stackTrace),
|
||||
);
|
||||
|
||||
// When app is closed
|
||||
ReceiveSharingIntent.getInitialMedia().then((value) {
|
||||
if (value.isNotEmpty) {
|
||||
ref.read(receiveSharingIntentUrlProvider.notifier).setValue(value[0].path);
|
||||
ref.read(routerProvider).go(RoutesPaths.bookmarks);
|
||||
}
|
||||
ReceiveSharingIntent.reset();
|
||||
});
|
||||
|
||||
return null;
|
||||
},
|
||||
[],
|
||||
);
|
||||
|
||||
return DynamicColorBuilder(
|
||||
builder: (lightDynamic, darkDynamic) {
|
||||
ref.read(appStatusProvider.notifier).setSupportsDynamicTheme(lightDynamic != null && darkDynamic != null);
|
||||
|
||||
Reference in New Issue
Block a user