-
Notifications
You must be signed in to change notification settings - Fork 5
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: Better handling of HTTPS links in the app settings.
- Loading branch information
Showing
5 changed files
with
77 additions
and
39 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,28 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:open_authenticator/app.dart'; | ||
import 'package:open_authenticator/i18n/translations.g.dart'; | ||
import 'package:url_launcher/url_launcher.dart'; | ||
import 'package:open_authenticator/pages/settings/entries/uri_settings_entry.dart'; | ||
|
||
/// Takes the user to Github to report bugs, suggest new features, ... | ||
class GithubSettingsEntryWidget extends StatelessWidget { | ||
class GithubSettingsEntryWidget extends UriSettingsEntry { | ||
/// Creates a new Github settings entry widget instance. | ||
const GithubSettingsEntryWidget({ | ||
GithubSettingsEntryWidget({ | ||
super.key, | ||
}); | ||
}) : super( | ||
icon: Icons.bug_report, | ||
title: translations.settings.about.github.title, | ||
subtitle: translations.settings.about.github.subtitle, | ||
uri: Uri.parse(App.githubRepositoryUrl), | ||
); | ||
|
||
@override | ||
Widget build(BuildContext context) => ListTile( | ||
leading: const Icon(Icons.bug_report), | ||
title: Text(translations.settings.about.github.title), | ||
subtitle: Text(translations.settings.about.github.subtitle), | ||
onTap: () async { | ||
Uri uri = Uri.parse(App.githubRepositoryUrl); | ||
Uri withFragment = Uri( | ||
scheme: uri.scheme, | ||
host: uri.host, | ||
path: uri.path, | ||
fragment: 'report-bugs-or-suggest-new-features', | ||
); | ||
if (await canLaunchUrl(withFragment)) { | ||
launchUrl(withFragment); | ||
} | ||
}, | ||
); | ||
Uri get uri { | ||
Uri uri = super.uri; | ||
return Uri( | ||
scheme: uri.scheme, | ||
host: uri.host, | ||
path: uri.path, | ||
fragment: 'report-bugs-or-suggest-new-features', | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,18 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:open_authenticator/app.dart'; | ||
import 'package:open_authenticator/i18n/translations.g.dart'; | ||
import 'package:open_authenticator/pages/settings/entries/uri_settings_entry.dart'; | ||
import 'package:url_launcher/url_launcher.dart'; | ||
|
||
/// Takes the user to the app translation page. | ||
class TranslateSettingsEntryWidget extends StatelessWidget { | ||
class TranslateSettingsEntryWidget extends UriSettingsEntry { | ||
/// Creates a new translate settings entry widget instance. | ||
const TranslateSettingsEntryWidget({ | ||
TranslateSettingsEntryWidget({ | ||
super.key, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) => ListTile( | ||
leading: const Icon(Icons.translate), | ||
title: Text(translations.settings.about.translate.title), | ||
subtitle: Text(translations.settings.about.translate.subtitle(appName: App.appName)), | ||
onTap: () async { | ||
Uri uri = Uri.parse(App.appTranslationUrl); | ||
if (await canLaunchUrl(uri)) { | ||
launchUrl(uri); | ||
} | ||
}, | ||
); | ||
}) : super( | ||
icon: Icons.translate, | ||
title: translations.settings.about.translate.title, | ||
subtitle: translations.settings.about.translate.subtitle(appName: App.appName), | ||
uri: Uri.parse(App.appTranslationUrl), | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import 'package:flutter/material.dart'; | ||
import 'package:url_launcher/url_launcher.dart'; | ||
|
||
/// A settings entry that allows to open a specific URI. | ||
class UriSettingsEntry extends StatelessWidget { | ||
/// The entry widget title. | ||
final String title; | ||
|
||
/// The entry widget subtitle. | ||
final String? subtitle; | ||
|
||
/// The icon. | ||
final IconData? icon; | ||
|
||
/// The URI to open. | ||
final Uri uri; | ||
|
||
/// Creates a new URI settings entry instance. | ||
const UriSettingsEntry({ | ||
super.key, | ||
required this.title, | ||
this.subtitle, | ||
this.icon, | ||
required this.uri, | ||
}); | ||
|
||
@override | ||
Widget build(BuildContext context) => FutureBuilder( | ||
future: canLaunchUrl(uri), | ||
builder: (context, snapshot) => createListTile(context, snapshot.data), | ||
); | ||
|
||
Widget createListTile(BuildContext context, bool? canLaunchUri) => canLaunchUri == null || canLaunchUri == true | ||
? ListTile( | ||
leading: const Icon(Icons.translate), | ||
title: Text(title), | ||
subtitle: subtitle == null ? null : Text(subtitle!), | ||
onTap: canLaunchUri == true ? (() async => await launchUrl(uri)) : null, | ||
) | ||
: SizedBox.shrink(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters