Skip to content

Commit

Permalink
Merge pull request #170 from Mohit-Joshi-dev/open_resource_link_button
Browse files Browse the repository at this point in the history
[Resolved] Open resource link externally button
  • Loading branch information
guyluz11 authored Jul 25, 2024
2 parents 19944b1 + 555c216 commit 3438b79
Show file tree
Hide file tree
Showing 7 changed files with 35 additions and 2 deletions.
1 change: 1 addition & 0 deletions lib/domain/controllers/controllers.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ export 'package:infinite_horizons/domain/controllers/notifications_controller.da
export 'package:infinite_horizons/domain/controllers/permissions_controller.dart';
export 'package:infinite_horizons/domain/controllers/player_controller.dart';
export 'package:infinite_horizons/domain/controllers/preferences_controller.dart';
export 'package:infinite_horizons/domain/controllers/url_launcher_controller.dart';
export 'package:infinite_horizons/domain/controllers/vibration_controller.dart';
export 'package:infinite_horizons/domain/controllers/wake_lock_controller.dart';
export 'package:infinite_horizons/domain/controllers/web_browser_controller.dart';
12 changes: 12 additions & 0 deletions lib/domain/controllers/url_launcher_controller.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
import 'package:url_launcher/url_launcher.dart';

part 'package:infinite_horizons/infrastructure/url_launcher_repository.dart';

abstract class UrlLauncherController {
static UrlLauncherController? _instance;

static UrlLauncherController get instance =>
_instance ??= _UrlLauncherRepository();

Future<bool> openUrl(String url);
}
6 changes: 6 additions & 0 deletions lib/infrastructure/url_launcher_repository.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
part of 'package:infinite_horizons/domain/controllers/url_launcher_controller.dart';

class _UrlLauncherRepository extends UrlLauncherController {
@override
Future<bool> openUrl(String url) => launchUrl(Uri.parse(url));
}
3 changes: 3 additions & 0 deletions lib/presentation/molecules/page_enclosure_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ class PageEnclosureMolecule extends StatelessWidget {
this.scaffold = true,
this.topBarRightOnTap,
this.expendChild = true,
this.topBarRightIcon,
super.key,
});

Expand All @@ -27,6 +28,7 @@ class PageEnclosureMolecule extends StatelessWidget {
final TopBarType topBarType;
final VoidCallback? topBarRightOnTap;
final bool expendChild;
final IconData? topBarRightIcon;

Widget topBarHelper() {
return Column(
Expand All @@ -37,6 +39,7 @@ class PageEnclosureMolecule extends StatelessWidget {
margin: false,
translate: topBarTranslate,
rightOnTap: topBarRightOnTap,
rightIcon: topBarRightIcon,
),
if (subTitle != null)
TextAtom(
Expand Down
4 changes: 3 additions & 1 deletion lib/presentation/molecules/top_bar_molecule.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ class TopBarMolecule extends StatelessWidget {
this.rightOnTap,
this.translate = true,
this.margin = true,
this.rightIcon,
});

final TopBarType topBarType;
final String? title;
final VoidCallback? leftOnTap;
final VoidCallback? rightOnTap;
final IconData? rightIcon;
final bool translate;
final bool margin;

Expand Down Expand Up @@ -108,7 +110,7 @@ class TopBarMolecule extends StatelessWidget {
variant: ButtonVariant.lowEmphasisIcon,
onPressed: rightOnTap!,
translate: translate,
icon: Icons.more_vert,
icon: rightIcon ?? Icons.more_vert,
)
else
TextAtom(
Expand Down
5 changes: 5 additions & 0 deletions lib/presentation/pages/tip_resources_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:infinite_horizons/domain/controllers/controllers.dart';
import 'package:infinite_horizons/presentation/molecules/molecules.dart';
import 'package:infinite_horizons/presentation/pages/pages.dart';

Expand All @@ -16,7 +17,9 @@ class TipResourcePage extends StatelessWidget {
title: "resource",
margin: false,
topBarType: TopBarType.back,
topBarRightOnTap: () => UrlLauncherController.instance.openUrl(url),
expendChild: false,
topBarRightIcon: Icons.open_in_new,
child: PdfViewerMolecule(
url: url,
),
Expand All @@ -31,6 +34,8 @@ class TipResourcePage extends StatelessWidget {
margin: false,
topBarType: TopBarType.back,
expendChild: false,
topBarRightIcon: Icons.open_in_new,
topBarRightOnTap: () => UrlLauncherController.instance.openUrl(url),
child: WebViewMolecule(
url: url,
),
Expand Down
6 changes: 5 additions & 1 deletion lib/presentation/pages/youtube_player_page.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:infinite_horizons/domain/controllers/controllers.dart';
import 'package:infinite_horizons/presentation/atoms/atoms.dart';
import 'package:infinite_horizons/presentation/core/global_variables.dart';
import 'package:infinite_horizons/presentation/molecules/molecules.dart';
Expand Down Expand Up @@ -30,9 +31,12 @@ class _YoutubePlayerPageState extends State<YoutubePlayerPage> {
body: Column(
children: [
if (!isFullScreen)
const TopBarMolecule(
TopBarMolecule(
topBarType: TopBarType.back,
title: 'resource',
rightIcon: Icons.open_in_new,
rightOnTap: () =>
UrlLauncherController.instance.openUrl(widget.url),
),
const SeparatorAtom(variant: SeparatorVariant.closeWidgets),
Expanded(
Expand Down

0 comments on commit 3438b79

Please sign in to comment.