diff --git a/example/lib/presentation/menu/app_menu.dart b/example/lib/presentation/menu/app_menu.dart index edb6bb428..f4deffdf2 100644 --- a/example/lib/presentation/menu/app_menu.dart +++ b/example/lib/presentation/menu/app_menu.dart @@ -1,7 +1,9 @@ import 'package:dartx/dartx.dart'; import 'package:fl_chart_app/cubits/app/app_cubit.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:fl_chart_app/util/app_utils.dart'; import 'package:flutter/material.dart'; import 'package:flutter_bloc/flutter_bloc.dart'; import 'package:url_launcher/url_launcher.dart'; @@ -116,18 +118,29 @@ class _AppVersionRow extends StatelessWidget { ), ), ), - if (state.availableVersionToUpdate.isNotBlank) - TextButton( - onPressed: () {}, - child: const Text( - 'Update', - style: TextStyle( - color: AppColors.primary, - fontSize: 12, - fontWeight: FontWeight.bold, + state.availableVersionToUpdate.isNotBlank + ? TextButton( + onPressed: () {}, + child: Text( + 'Update to ${state.availableVersionToUpdate}', + style: const TextStyle( + color: AppColors.primary, + fontSize: 12, + fontWeight: FontWeight.bold, + ), + ), + ) + : TextButton( + onPressed: () => AppUtils().tryToLaunchUrl(Urls.aboutUrl), + child: const Text( + 'About', + style: TextStyle( + color: AppColors.primary, + fontSize: 12, + fontWeight: FontWeight.bold, + ), + ), ), - ), - ), ], ), ); diff --git a/example/lib/presentation/pages/home_page.dart b/example/lib/presentation/pages/home_page.dart index 33f08a1ce..497e098e8 100644 --- a/example/lib/presentation/pages/home_page.dart +++ b/example/lib/presentation/pages/home_page.dart @@ -3,10 +3,10 @@ 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:fl_chart_app/util/app_utils.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'; @@ -56,10 +56,7 @@ class HomePage extends StatelessWidget { onBannerClicked: kIsWeb || needsDrawer ? () async { if (kIsWeb) { - final url = Uri.parse(Urls.flChartUrl); - if (await canLaunchUrl(url)) { - await launchUrl(url); - } + await AppUtils().tryToLaunchUrl(Urls.flChartUrl); return; } if (needsDrawer) { diff --git a/example/lib/presentation/widgets/chart_holder.dart b/example/lib/presentation/widgets/chart_holder.dart index 2ea13ece4..3428d0838 100644 --- a/example/lib/presentation/widgets/chart_holder.dart +++ b/example/lib/presentation/widgets/chart_holder.dart @@ -1,7 +1,7 @@ import 'package:fl_chart_app/presentation/resources/app_resources.dart'; import 'package:fl_chart_app/presentation/samples/chart_sample.dart'; +import 'package:fl_chart_app/util/app_utils.dart'; import 'package:flutter/material.dart'; -import 'package:url_launcher/url_launcher.dart'; class ChartHolder extends StatelessWidget { final ChartSample chartSample; @@ -30,12 +30,7 @@ class ChartHolder extends StatelessWidget { ), Expanded(child: Container()), IconButton( - onPressed: () async { - final url = Uri.parse(chartSample.url); - if (await canLaunchUrl(url)) { - await launchUrl(url); - } - }, + onPressed: () => AppUtils().tryToLaunchUrl(chartSample.url), icon: const Icon( Icons.code, color: AppColors.primary, diff --git a/example/lib/urls.dart b/example/lib/urls.dart index d1b9fb160..83cb6d95b 100644 --- a/example/lib/urls.dart +++ b/example/lib/urls.dart @@ -11,4 +11,6 @@ class Urls { final chartDir = chartType.name.toLowerCase(); return 'https://github.com/imaNNeo/fl_chart/blob/master/repo_files/documentations/${chartDir}_chart.md'; } + + static String get aboutUrl => '$flChartUrl/about'; } diff --git a/example/lib/util/app_utils.dart b/example/lib/util/app_utils.dart index efb5cfa2a..51e209503 100644 --- a/example/lib/util/app_utils.dart +++ b/example/lib/util/app_utils.dart @@ -1,5 +1,7 @@ import 'dart:math' as math; +import 'package:url_launcher/url_launcher.dart'; + class AppUtils { factory AppUtils() { return _singleton; @@ -15,4 +17,12 @@ class AppUtils { double radianToDegree(double radian) { return radian * 180 / math.pi; } + + Future tryToLaunchUrl(String url) async { + final uri = Uri.parse(url); + if (await canLaunchUrl(uri)) { + return await launchUrl(uri); + } + return false; + } }