Add url_launcher for opening URLs.

This commit is contained in:
Dain Nilsson 2022-06-05 12:26:40 +02:00
parent a59dc4318c
commit 1897f79f65
No known key found for this signature in database
GPG Key ID: F04367096FBA95E8
8 changed files with 86 additions and 18 deletions

View File

@ -5,6 +5,7 @@ import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:logging/logging.dart';
import 'package:url_launcher/url_launcher.dart';
import 'app/state.dart';
import 'version.dart';
@ -25,7 +26,6 @@ class AboutPage extends ConsumerWidget {
title: const Text('About'),
child: Column(
mainAxisSize: MainAxisSize.min,
//crossAxisAlignment: CrossAxisAlignment.start,
children: [
Image.asset('assets/graphics/app-icon.png', scale: 1 / 0.75),
Padding(
@ -43,17 +43,17 @@ class AboutPage extends ConsumerWidget {
const Text(''),
Row(
mainAxisSize: MainAxisSize.min,
children: const [
children: [
UrlLink(
text: 'Terms of use',
url:
'https://www.yubico.com/support/terms-conditions/yubico-license-agreement/',
target: Uri.parse(
'https://www.yubico.com/support/terms-conditions/yubico-license-agreement/'),
),
SizedBox(width: 8.0),
const SizedBox(width: 8.0),
UrlLink(
text: 'Privacy policy',
url:
'https://www.yubico.com/support/terms-conditions/privacy-notice/',
target: Uri.parse(
'https://www.yubico.com/support/terms-conditions/privacy-notice/'),
),
],
),
@ -70,15 +70,16 @@ class AboutPage extends ConsumerWidget {
),
Row(
mainAxisSize: MainAxisSize.min,
children: const [
children: [
UrlLink(
text: 'Send us feedback',
url: 'https://example.com',
target: Uri.parse('https://example.com'),
),
SizedBox(width: 8.0),
const SizedBox(width: 8.0),
UrlLink(
text: 'I need help',
url: 'https://support.yubico.com/support/home'),
text: 'I need help',
target: Uri.parse('https://support.yubico.com/support/home'),
),
],
),
const Padding(
@ -169,9 +170,9 @@ class LoggingPanel extends ConsumerWidget {
class UrlLink extends StatefulWidget {
final String text;
final String url;
final Uri target;
const UrlLink({super.key, required this.text, required this.url});
const UrlLink({super.key, required this.text, required this.target});
@override
State<StatefulWidget> createState() => _UrlLinkState();
@ -185,9 +186,8 @@ class _UrlLinkState extends State<UrlLink> {
super.initState();
_tapRecognizer = TapGestureRecognizer();
_tapRecognizer.onTap = () {
//TODO: use url_launcher
// ignore: avoid_print
print('TODO: Go to ${widget.url}');
_log.debug('Opening browser to ${widget.target}');
launchUrl(widget.target, mode: LaunchMode.externalApplication);
};
}

View File

@ -7,12 +7,16 @@
#include "generated_plugin_registrant.h"
#include <desktop_drop/desktop_drop_plugin.h>
#include <url_launcher_linux/url_launcher_plugin.h>
#include <window_manager/window_manager_plugin.h>
void fl_register_plugins(FlPluginRegistry* registry) {
g_autoptr(FlPluginRegistrar) desktop_drop_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "DesktopDropPlugin");
desktop_drop_plugin_register_with_registrar(desktop_drop_registrar);
g_autoptr(FlPluginRegistrar) url_launcher_linux_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "UrlLauncherPlugin");
url_launcher_plugin_register_with_registrar(url_launcher_linux_registrar);
g_autoptr(FlPluginRegistrar) window_manager_registrar =
fl_plugin_registry_get_registrar_for_plugin(registry, "WindowManagerPlugin");
window_manager_plugin_register_with_registrar(window_manager_registrar);

View File

@ -4,6 +4,7 @@
list(APPEND FLUTTER_PLUGIN_LIST
desktop_drop
url_launcher_linux
window_manager
)

View File

@ -7,10 +7,12 @@ import Foundation
import desktop_drop
import shared_preferences_macos
import url_launcher_macos
import window_manager
func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) {
DesktopDropPlugin.register(with: registry.registrar(forPlugin: "DesktopDropPlugin"))
SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin"))
UrlLauncherPlugin.register(with: registry.registrar(forPlugin: "UrlLauncherPlugin"))
WindowManagerPlugin.register(with: registry.registrar(forPlugin: "WindowManagerPlugin"))
}

View File

@ -631,6 +631,62 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.3.0"
url_launcher:
dependency: "direct main"
description:
name: url_launcher
url: "https://pub.dartlang.org"
source: hosted
version: "6.1.2"
url_launcher_android:
dependency: transitive
description:
name: url_launcher_android
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.17"
url_launcher_ios:
dependency: transitive
description:
name: url_launcher_ios
url: "https://pub.dartlang.org"
source: hosted
version: "6.0.17"
url_launcher_linux:
dependency: transitive
description:
name: url_launcher_linux
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
url_launcher_macos:
dependency: transitive
description:
name: url_launcher_macos
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
url_launcher_platform_interface:
dependency: transitive
description:
name: url_launcher_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.5"
url_launcher_web:
dependency: transitive
description:
name: url_launcher_web
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.11"
url_launcher_windows:
dependency: transitive
description:
name: url_launcher_windows
url: "https://pub.dartlang.org"
source: hosted
version: "3.0.1"
vector_math:
dependency: transitive
description:
@ -696,4 +752,4 @@ packages:
version: "3.1.0"
sdks:
dart: ">=2.17.0 <3.0.0"
flutter: ">=2.8.0"
flutter: ">=2.10.0"

View File

@ -49,6 +49,7 @@ dependencies:
qrscanner_zxing:
path: android/flutter_plugins/qrscanner_zxing
desktop_drop: ^0.3.3
url_launcher: ^6.1.2
dependency_overrides:
analyzer: ^3.4.1

View File

@ -7,11 +7,14 @@
#include "generated_plugin_registrant.h"
#include <desktop_drop/desktop_drop_plugin.h>
#include <url_launcher_windows/url_launcher_windows.h>
#include <window_manager/window_manager_plugin.h>
void RegisterPlugins(flutter::PluginRegistry* registry) {
DesktopDropPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("DesktopDropPlugin"));
UrlLauncherWindowsRegisterWithRegistrar(
registry->GetRegistrarForPlugin("UrlLauncherWindows"));
WindowManagerPluginRegisterWithRegistrar(
registry->GetRegistrarForPlugin("WindowManagerPlugin"));
}

View File

@ -4,6 +4,7 @@
list(APPEND FLUTTER_PLUGIN_LIST
desktop_drop
url_launcher_windows
window_manager
)