Skip to content

Commit

Permalink
feat: open link in twitter application (#1652)
Browse files Browse the repository at this point in the history
  • Loading branch information
Merculiar authored Dec 22, 2024
1 parent 5d1c8ea commit 5c15716
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ class ShareSection extends StatelessWidget {
@override
Widget build(BuildContext context) => Center(
child: InkWell(
onTap: () => context.openLink(twitterUrl),
onTap: () => context.openLink(twitterUrl, openInApp: true),
child: DecoratedBox(
decoration: const ShapeDecoration(
shape: CircleBorder(),
Expand Down
16 changes: 15 additions & 1 deletion packages/espressocash_app/lib/ui/web_view_screen.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_inappwebview/flutter_inappwebview.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:url_launcher/url_launcher.dart';

import '../l10n/l10n.dart';
import '../utils/errors.dart';
Expand All @@ -9,9 +10,22 @@ import 'snackbar.dart';
import 'theme.dart';

extension LinkOpenerExt on BuildContext {
Future<void> openLink(String link) async {
Future<void> openLink(
String link, {
bool openInApp = false,
}) async {
try {
final url = Uri.parse(link);

if (openInApp) {
final launched = await launchUrl(
url,
mode: LaunchMode.externalNonBrowserApplication,
);

if (launched) return;
}

await WebViewScreen.push(
this,
url: url,
Expand Down

0 comments on commit 5c15716

Please sign in to comment.