url launching with feedback refactored
This commit is contained in:
@@ -172,17 +172,8 @@ class KagiScreen extends HookConsumerWidget {
|
||||
onPressed: () async {
|
||||
final url = await webViewController.value?.getUrl();
|
||||
if (url != null) {
|
||||
if (!await launchUrl(
|
||||
url,
|
||||
mode: LaunchMode.externalApplication,
|
||||
)) {
|
||||
if (context.mounted) {
|
||||
ui_helper.showErrorMessage(
|
||||
context,
|
||||
'Could not launch URL ($url)',
|
||||
);
|
||||
}
|
||||
}
|
||||
// ignore: use_build_context_synchronously
|
||||
await ui_helper.launchUrlFeedback(context, url);
|
||||
}
|
||||
},
|
||||
leadingIcon: const Icon(Icons.open_in_browser),
|
||||
|
||||
@@ -3,11 +3,11 @@ import 'package:bang_navigator/features/settings/data/repositories/settings_repo
|
||||
import 'package:bang_navigator/features/settings/presentation/controllers/save_settings.dart';
|
||||
import 'package:bang_navigator/features/settings/utils/session_link_extractor.dart';
|
||||
import 'package:bang_navigator/presentation/hooks/listenable_callback.dart';
|
||||
import 'package:bang_navigator/utils/ui_helper.dart' as ui_helper;
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_hooks/flutter_hooks.dart';
|
||||
import 'package:flutter_markdown/flutter_markdown.dart';
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class SettingsScreen extends HookConsumerWidget {
|
||||
const SettingsScreen({super.key});
|
||||
@@ -92,11 +92,11 @@ class SettingsScreen extends HookConsumerWidget {
|
||||
'You can visit your [Kagi Account Settings](user_details) to get your Session Link.',
|
||||
onTapLink: (text, href, title) async {
|
||||
if (href == 'user_details') {
|
||||
await launchUrl(
|
||||
await ui_helper.launchUrlFeedback(
|
||||
context,
|
||||
Uri.parse(
|
||||
'https://kagi.com/settings?p=user_details',
|
||||
),
|
||||
mode: LaunchMode.externalApplication,
|
||||
);
|
||||
}
|
||||
},
|
||||
|
||||
@@ -15,7 +15,6 @@ import 'package:flutter_material_design_icons/flutter_material_design_icons.dart
|
||||
import 'package:hooks_riverpod/hooks_riverpod.dart';
|
||||
import 'package:share_plus/share_plus.dart';
|
||||
import 'package:skeletonizer/skeletonizer.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class LoadingWebPageDialog extends HookConsumerWidget {
|
||||
final Uri url;
|
||||
@@ -139,17 +138,7 @@ class WebPageDialog extends HookConsumerWidget {
|
||||
),
|
||||
ListTile(
|
||||
onTap: () async {
|
||||
if (!await launchUrl(
|
||||
page.url,
|
||||
mode: LaunchMode.externalApplication,
|
||||
)) {
|
||||
if (context.mounted) {
|
||||
ui_helper.showErrorMessage(
|
||||
context,
|
||||
'Could not launch URL (${page.url})',
|
||||
);
|
||||
}
|
||||
}
|
||||
await ui_helper.launchUrlFeedback(context, page.url);
|
||||
},
|
||||
leading: const Icon(Icons.open_in_browser),
|
||||
title: const Text('Launch External'),
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
void showErrorMessage(BuildContext context, String message) {
|
||||
final snackBar = SnackBar(
|
||||
@@ -12,3 +13,21 @@ void showErrorMessage(BuildContext context, String message) {
|
||||
);
|
||||
ScaffoldMessenger.of(context).showSnackBar(snackBar);
|
||||
}
|
||||
|
||||
Future<void> launchUrlFeedback(
|
||||
BuildContext context,
|
||||
Uri url, {
|
||||
LaunchMode mode = LaunchMode.externalApplication,
|
||||
}) async {
|
||||
if (!await launchUrl(
|
||||
url,
|
||||
mode: mode,
|
||||
)) {
|
||||
if (context.mounted) {
|
||||
showErrorMessage(
|
||||
context,
|
||||
'Could not launch URL ($url)',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user