mirror of
https://git.selfprivacy.org/kherel/selfprivacy.org.app.git
synced 2024-11-13 20:23:16 +00:00
fix(ui): Deduplicated launch_url functions
Also fixed issue of calling URI with duplicate protocol Closes: #184
This commit is contained in:
parent
42b9de656c
commit
e186dac39f
|
@ -9,8 +9,8 @@ import 'package:selfprivacy/logic/models/service.dart';
|
|||
import 'package:selfprivacy/ui/components/brand_cards/filled_card.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_hero_screen/brand_hero_screen.dart';
|
||||
import 'package:selfprivacy/ui/pages/server_storage/binds_migration/services_migration.dart';
|
||||
import 'package:selfprivacy/utils/launch_url.dart';
|
||||
import 'package:selfprivacy/utils/route_transitions/basic.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class ServicePage extends StatefulWidget {
|
||||
const ServicePage({required this.serviceId, super.key});
|
||||
|
@ -59,7 +59,7 @@ class _ServicePageState extends State<ServicePage> {
|
|||
if (service.url != null)
|
||||
ListTile(
|
||||
iconColor: Theme.of(context).colorScheme.onBackground,
|
||||
onTap: () => _launchURL(service.url),
|
||||
onTap: () => launchURL(service.url),
|
||||
leading: const Icon(Icons.open_in_browser),
|
||||
title: Text(
|
||||
'service_page.open_in_browser'.tr(),
|
||||
|
@ -232,15 +232,3 @@ class ServiceStatusCard extends StatelessWidget {
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
void _launchURL(final url) async {
|
||||
try {
|
||||
final Uri uri = Uri.parse(url);
|
||||
await launchUrl(
|
||||
uri,
|
||||
mode: LaunchMode.externalApplication,
|
||||
);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -12,9 +12,9 @@ import 'package:selfprivacy/ui/components/icon_status_mask/icon_status_mask.dart
|
|||
import 'package:selfprivacy/ui/components/not_ready_card/not_ready_card.dart';
|
||||
import 'package:easy_localization/easy_localization.dart';
|
||||
import 'package:selfprivacy/ui/pages/services/service_page.dart';
|
||||
import 'package:selfprivacy/utils/launch_url.dart';
|
||||
import 'package:selfprivacy/utils/route_transitions/basic.dart';
|
||||
import 'package:selfprivacy/utils/ui_helpers.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
class ServicesPage extends StatefulWidget {
|
||||
const ServicesPage({super.key});
|
||||
|
@ -23,18 +23,6 @@ class ServicesPage extends StatefulWidget {
|
|||
State<ServicesPage> createState() => _ServicesPageState();
|
||||
}
|
||||
|
||||
void _launchURL(final url) async {
|
||||
try {
|
||||
final Uri uri = Uri.parse(url);
|
||||
await launchUrl(
|
||||
uri,
|
||||
mode: LaunchMode.externalApplication,
|
||||
);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
|
||||
class _ServicesPageState extends State<ServicesPage> {
|
||||
@override
|
||||
Widget build(final BuildContext context) {
|
||||
|
@ -145,7 +133,7 @@ class _Card extends StatelessWidget {
|
|||
Column(
|
||||
children: [
|
||||
GestureDetector(
|
||||
onTap: () => _launchURL(
|
||||
onTap: () => launchURL(
|
||||
service.url,
|
||||
),
|
||||
child: Text(
|
||||
|
|
|
@ -12,7 +12,7 @@ import 'package:selfprivacy/ui/components/brand_button/outlined_button.dart';
|
|||
import 'package:selfprivacy/ui/components/brand_cards/outlined_card.dart';
|
||||
import 'package:selfprivacy/ui/components/brand_md/brand_md.dart';
|
||||
import 'package:selfprivacy/ui/components/info_box/info_box.dart';
|
||||
import 'package:url_launcher/url_launcher.dart';
|
||||
import 'package:selfprivacy/utils/launch_url.dart';
|
||||
|
||||
class ServerProviderPicker extends StatefulWidget {
|
||||
const ServerProviderPicker({
|
||||
|
@ -249,7 +249,7 @@ class ProviderSelectionPage extends StatelessWidget {
|
|||
// Outlined button that will open website
|
||||
BrandOutlinedButton(
|
||||
onPressed: () =>
|
||||
_launchURL('https://www.hetzner.com/cloud'),
|
||||
launchURL('https://www.hetzner.com/cloud'),
|
||||
title: 'initializing.select_provider_site_button'.tr(),
|
||||
),
|
||||
],
|
||||
|
@ -323,7 +323,7 @@ class ProviderSelectionPage extends StatelessWidget {
|
|||
// Outlined button that will open website
|
||||
BrandOutlinedButton(
|
||||
onPressed: () =>
|
||||
_launchURL('https://www.digitalocean.com'),
|
||||
launchURL('https://www.digitalocean.com'),
|
||||
title: 'initializing.select_provider_site_button'.tr(),
|
||||
),
|
||||
],
|
||||
|
@ -336,15 +336,3 @@ class ProviderSelectionPage extends StatelessWidget {
|
|||
),
|
||||
);
|
||||
}
|
||||
|
||||
void _launchURL(final url) async {
|
||||
try {
|
||||
final Uri uri = Uri.parse(url);
|
||||
await launchUrl(
|
||||
uri,
|
||||
mode: LaunchMode.externalApplication,
|
||||
);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
}
|
||||
|
|
13
lib/utils/launch_url.dart
Normal file
13
lib/utils/launch_url.dart
Normal file
|
@ -0,0 +1,13 @@
|
|||
import 'package:url_launcher/url_launcher.dart';
|
||||
|
||||
void launchURL(final url) async {
|
||||
try {
|
||||
final Uri uri = Uri.parse(url);
|
||||
await launchUrl(
|
||||
uri,
|
||||
mode: LaunchMode.externalApplication,
|
||||
);
|
||||
} catch (e) {
|
||||
print(e);
|
||||
}
|
||||
}
|
Loading…
Reference in a new issue