// main.dart import 'package:flutter/material.dart'; import 'pages/bookmarks_page.dart'; import 'pages/collections_page.dart'; import 'service/storage.dart'; import 'service/share_intent_service.dart'; import 'theme.dart'; void main() async { WidgetsFlutterBinding.ensureInitialized(); await Storage.initialize(); runApp(const MapsBookmarks()); } class MapsBookmarks extends StatefulWidget { const MapsBookmarks({super.key}); @override State createState() => _MapsBookmarksState(); } class _MapsBookmarksState extends State with WidgetsBindingObserver { final ShareIntentService _shareIntentService = ShareIntentService(); final GlobalKey _navigatorKey = GlobalKey(); @override void initState() { super.initState(); WidgetsBinding.instance.addObserver(this); // Check for shared content on app start _checkForSharedContent(); } @override void dispose() { WidgetsBinding.instance.removeObserver(this); super.dispose(); } @override void didChangeAppLifecycleState(AppLifecycleState state) { // Check for shared content when app resumes if (state == AppLifecycleState.resumed) { _checkForSharedContent(); } } Future _checkForSharedContent() async { final sharedText = await _shareIntentService.getSharedText(); if (sharedText != null && mounted) { // Validate it's a Google Maps link if (_shareIntentService.isGoogleMapsLink(sharedText)) { final metadata = _shareIntentService.extractMetadata(sharedText); _handleSharedMapsLink(metadata); } } } void _handleSharedMapsLink(MapsLinkMetadata metadata) { // Navigate to the appropriate page or show a dialog // You can customize this based on your app's flow // Option 1: Navigate to collections page with data _navigatorKey.currentState?.pushNamed( CollectionsPage.routeName, arguments: metadata, ); // Option 2: Show a dialog to select collection and save // This would be implemented based on your UI requirements } @override Widget build(BuildContext context) { return MaterialApp( navigatorKey: _navigatorKey, theme: lightTheme, darkTheme: darkTheme, initialRoute: CollectionsPage.routeName, routes: { CollectionsPage.routeName: (context) => const CollectionsPage(), BookmarksPage.routeName: (context) => const BookmarksPage(), }, ); } }