73 lines
2.4 KiB
Dart
Executable File
73 lines
2.4 KiB
Dart
Executable File
import 'dart:io';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
import 'package:android_intent_plus/android_intent.dart';
|
|
import 'package:android_intent_plus/flag.dart';
|
|
import 'package:app_settings/app_settings.dart';
|
|
|
|
class AppLinksHelper {
|
|
static Future<void> checkAndShowDialogOnce(BuildContext context) async {
|
|
final prefs = await SharedPreferences.getInstance();
|
|
final shown = prefs.getBool('supported_links_enabled') ?? false;
|
|
|
|
if (!shown) {
|
|
_showAppLinkDialog(context);
|
|
}
|
|
}
|
|
|
|
static void _showAppLinkDialog(BuildContext context) {
|
|
showDialog(
|
|
context: context,
|
|
builder: (_) => AlertDialog(
|
|
title: const Text('Enable App Links'),
|
|
content: Platform.isIOS
|
|
? const Text(
|
|
'To ensure links like www.fcsc.com open directly in this app:\n\n'
|
|
'1. Open iOS Settings.\n'
|
|
'2. Scroll down and tap on "Your App Name".\n'
|
|
'3. Make sure "Allow Universal Links" is enabled (if visible).\n\n'
|
|
'Note: Some iOS versions do not show this explicitly.',
|
|
)
|
|
: const Text(
|
|
'To enable links like www.fcsc.com to open in this app:\n\n'
|
|
'1. Tap "Open Settings".\n'
|
|
'2. Tap "Supported web addresses".\n'
|
|
'3. Make sure your domain is enabled.\n\n'
|
|
'This helps open links directly in the app.',
|
|
),
|
|
actions: [
|
|
TextButton(
|
|
onPressed: () => Navigator.of(context).pop(),
|
|
child: const Text('Later'),
|
|
),
|
|
TextButton(
|
|
onPressed: () async {
|
|
Navigator.of(context).pop();
|
|
|
|
if (Platform.isIOS) {
|
|
AppSettings.openAppSettings();
|
|
} else {
|
|
_openAppLinkSettingsAndroid();
|
|
}
|
|
|
|
final prefs = await SharedPreferences.getInstance();
|
|
await prefs.setBool('supported_links_enabled', true);
|
|
},
|
|
child: const Text('Open Settings'),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
static void _openAppLinkSettingsAndroid() {
|
|
const packageName = 'ae.gov.fcsc.stats'; // 🔁 Replace with your app's package
|
|
final intent = AndroidIntent(
|
|
action: 'android.settings.APP_OPEN_BY_DEFAULT_SETTINGS',
|
|
data: 'package:$packageName',
|
|
flags: <int>[Flag.FLAG_ACTIVITY_NEW_TASK],
|
|
);
|
|
intent.launch();
|
|
}
|
|
}
|