From 19018973927da21ccebfe53a60ac5e7863a09667 Mon Sep 17 00:00:00 2001 From: michal Date: Sat, 23 Jan 2021 22:46:05 +0100 Subject: [PATCH] * Improved info dialog. --- ios/Flutter/Debug.xcconfig | 1 + ios/Flutter/Release.xcconfig | 1 + lib/main.dart | 2 +- lib/page/about.dart | 132 +++++++++++++++++++ lib/page/{flights_page.dart => flights.dart} | 22 +--- pubspec.yaml | 3 +- 6 files changed, 142 insertions(+), 19 deletions(-) create mode 100644 lib/page/about.dart rename lib/page/{flights_page.dart => flights.dart} (92%) diff --git a/ios/Flutter/Debug.xcconfig b/ios/Flutter/Debug.xcconfig index e8efba1..b2f5fae 100644 --- a/ios/Flutter/Debug.xcconfig +++ b/ios/Flutter/Debug.xcconfig @@ -1,2 +1,3 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig" #include "Generated.xcconfig" diff --git a/ios/Flutter/Release.xcconfig b/ios/Flutter/Release.xcconfig index 399e934..88c2914 100644 --- a/ios/Flutter/Release.xcconfig +++ b/ios/Flutter/Release.xcconfig @@ -1,2 +1,3 @@ +#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig" #include "Generated.xcconfig" diff --git a/lib/main.dart b/lib/main.dart index 8c59cf9..5651874 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -5,7 +5,7 @@ import 'package:firebase_core/firebase_core.dart'; import 'package:flutter/material.dart'; import 'package:pull_to_refresh/pull_to_refresh.dart'; -import 'page/flights_page.dart'; +import 'page/flights.dart'; import 'util/colors.dart'; import 'util/proxy_for_debug.dart'; diff --git a/lib/page/about.dart b/lib/page/about.dart new file mode 100644 index 0000000..1e9500b --- /dev/null +++ b/lib/page/about.dart @@ -0,0 +1,132 @@ +import 'package:flutter/gestures.dart'; +import 'package:flutter/material.dart'; +import 'package:package_info/package_info.dart'; +import 'package:url_launcher/url_launcher.dart'; + +void showAboutDialog({ + @required BuildContext context, +}) { + assert(context != null); + showDialog( + context: context, + builder: (context) { + return _AboutDialog(); + }, + ); +} + +Future getVersionNumber() async { + final packageInfo = await PackageInfo.fromPlatform(); + return packageInfo.version; +} + +class _AboutDialog extends StatelessWidget { + @override + Widget build(BuildContext context) { + final colorScheme = Theme.of(context).colorScheme; + final textTheme = Theme.of(context).textTheme; + final bodyTextStyle = textTheme.bodyText1.apply(color: Colors.black87); + + final name = 'Gibraltar Flights'; + final madeByText = 'Made in Flutter with ❤️ during 2020/21 pandemic times.'; + final repoLinkText = "source code"; + final privacyLinkText = "privacy policy"; + final mainText = + "Feel free to check out the source code of this app if you're interested. Mandatory link to privacy policy belongs here too.\n\n🐵 Please DO NOT feed the monkeys! 🐵"; + final repoLinkIndex = mainText.indexOf(repoLinkText); + final repoLinkIndexEnd = repoLinkIndex + repoLinkText.length; + final privacyLinkIndex = mainText.indexOf(privacyLinkText); + final privacyLinkIndexEnd = privacyLinkIndex + privacyLinkText.length; + final mainTextFirst = mainText.substring(0, repoLinkIndex); + final mainTextSecond = + mainText.substring(repoLinkIndexEnd, privacyLinkIndex); + final mainTextThird = mainText.substring(privacyLinkIndexEnd); + + return AlertDialog( + backgroundColor: Theme.of(context).primaryColorLight, + shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)), + content: Container( + constraints: const BoxConstraints(maxWidth: 400), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + mainAxisSize: MainAxisSize.min, + children: [ + FutureBuilder( + future: getVersionNumber(), + builder: (context, snapshot) => Text( + snapshot.hasData ? '$name ${snapshot.data}' : '$name', + style: textTheme.headline6.apply(color: Colors.black87), + ), + ), + const SizedBox(height: 24), + RichText( + text: TextSpan( + children: [ + TextSpan( + style: bodyTextStyle, + text: mainTextFirst, + ), + TextSpan( + style: bodyTextStyle.copyWith( + color: colorScheme.primary, + decoration: TextDecoration.underline), + text: repoLinkText, + recognizer: TapGestureRecognizer() + ..onTap = () async { + final url = + 'https://github.com/micer/gibraltar-flights-flutter'; + if (await canLaunch(url)) { + await launch( + url, + forceSafariVC: false, + ); + } + }, + ), + TextSpan( + style: bodyTextStyle, + text: mainTextSecond, + ), + TextSpan( + style: bodyTextStyle.copyWith( + color: colorScheme.primary, + decoration: TextDecoration.underline), + text: privacyLinkText, + recognizer: TapGestureRecognizer() + ..onTap = () async { + final url = + 'https://micer.eu/gibflights/privacy_policy.html'; + if (await canLaunch(url)) { + await launch( + url, + forceSafariVC: false, + ); + } + }, + ), + TextSpan( + style: bodyTextStyle, + text: mainTextThird, + ), + ], + ), + ), + const SizedBox(height: 18), + Text( + madeByText, + style: bodyTextStyle, + ), + ], + ), + ), + actions: [ + TextButton( + child: Text(MaterialLocalizations.of(context).closeButtonLabel), + onPressed: () { + Navigator.pop(context); + }, + ), + ], + ); + } +} diff --git a/lib/page/flights_page.dart b/lib/page/flights.dart similarity index 92% rename from lib/page/flights_page.dart rename to lib/page/flights.dart index 280fbd8..fc38583 100644 --- a/lib/page/flights_page.dart +++ b/lib/page/flights.dart @@ -5,11 +5,11 @@ import 'package:flutter_svg/flutter_svg.dart'; import 'package:gibraltar_flights/main.dart'; import 'package:gibraltar_flights/model/flight.dart'; import 'package:gibraltar_flights/model/flights.dart'; +import 'package:gibraltar_flights/page/about.dart' as about; import 'package:gibraltar_flights/util/extensions.dart'; import 'package:gibraltar_flights/util/scrappy.dart'; import 'package:intl/intl.dart' hide TextDirection; import 'package:pull_to_refresh/pull_to_refresh.dart'; -import 'package:rflutter_alert/rflutter_alert.dart'; class FlightsPage extends StatefulWidget { const FlightsPage({Key key, @required this.title}) : super(key: key); @@ -41,7 +41,9 @@ class _FlightsPageState extends State { super.initState(); flights = Flights(items: []); FirebaseAdMob.instance.initialize(appId: FirebaseAdMob.testAppId); - _bannerAd = createBannerAd()..load()..show(); + _bannerAd = createBannerAd() + ..load() + ..show(); } @override @@ -62,21 +64,7 @@ class _FlightsPageState extends State { color: Colors.white, ), onPressed: () => - Alert( - context: context, - title: "Thanks for using this app!", - desc: "Made with ❤️ during 2020/21 pandemic times.", - image: Image.asset("assets/launcher/ic_launcher_foreground.png"), - buttons: [ - DialogButton( - onPressed: () => Navigator.pop(context), - child: Text( - "CLOSE", - style: TextStyle(color: Colors.white, fontSize: 16), - ), - ) - ] - ).show() + about.showAboutDialog(context: context) ) ], ), diff --git a/pubspec.yaml b/pubspec.yaml index 0fa1ca3..24348b4 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -33,10 +33,11 @@ dependencies: flutter_svg: ^0.19.2+1 html: ^0.14.0+3 jiffy: ^3.0.1 + package_info: ^0.4.3+2 path_provider: ^1.6.24 pull_to_refresh: ^1.6.3 - rflutter_alert: ^1.1.0 scrapy: ^0.0.3 + url_launcher: ^5.7.10 dev_dependencies: flutter_test: