Skip to content

Commit

Permalink
Open fl_chart web page only when we're on the web, otherwise open the…
Browse files Browse the repository at this point in the history
… home page of the app
  • Loading branch information
imaNNeo committed Nov 12, 2023
1 parent b3529d3 commit dde8584
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 7 deletions.
10 changes: 3 additions & 7 deletions example/lib/presentation/menu/app_menu.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import 'package:fl_chart_app/presentation/resources/app_resources.dart';
import 'package:fl_chart_app/urls.dart';
import 'package:fl_chart_app/util/app_helper.dart';
import 'package:flutter/material.dart';
import 'package:url_launcher/url_launcher.dart';
Expand All @@ -11,12 +10,14 @@ class AppMenu extends StatefulWidget {
final List<ChartMenuItem> menuItems;
final int currentSelectedIndex;
final Function(int, ChartMenuItem) onItemSelected;
final VoidCallback? onBannerClicked;

const AppMenu({
Key? key,
required this.menuItems,
required this.currentSelectedIndex,
required this.onItemSelected,
required this.onBannerClicked,
}) : super(key: key);

@override
Expand All @@ -36,12 +37,7 @@ class AppMenuState extends State<AppMenu> {
aspectRatio: 3,
child: Center(
child: InkWell(
onTap: () async {
final url = Uri.parse(Urls.flChartUrl);
if (await canLaunchUrl(url)) {
await launchUrl(url);
}
},
onTap: widget.onBannerClicked,
child: const FlChartBanner(),
),
),
Expand Down
16 changes: 16 additions & 0 deletions example/lib/presentation/pages/home_page.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
import 'package:dartx/dartx.dart';
import 'package:fl_chart_app/presentation/menu/app_menu.dart';
import 'package:fl_chart_app/presentation/resources/app_resources.dart';
import 'package:fl_chart_app/urls.dart';
import 'package:fl_chart_app/util/app_helper.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:url_launcher/url_launcher.dart';

import 'chart_samples_page.dart';

Expand Down Expand Up @@ -50,6 +53,19 @@ class HomePage extends StatelessWidget {
Navigator.of(context).pop();
}
},
onBannerClicked: kIsWeb || needsDrawer ? () async {
if (kIsWeb) {
final url = Uri.parse(Urls.flChartUrl);
if (await canLaunchUrl(url)) {
await launchUrl(url);
}
return;
}
if (needsDrawer) {
Navigator.of(context).pop();
return;
}
} : null,
);
final samplesSectionWidget =
ChartSamplesPage(chartType: showingChartType);
Expand Down

0 comments on commit dde8584

Please sign in to comment.