Skip to content

Commit

Permalink
* Improved info dialog.
Browse files Browse the repository at this point in the history
  • Loading branch information
micer committed Jan 23, 2021
1 parent 6a75e7a commit 1901897
Show file tree
Hide file tree
Showing 6 changed files with 142 additions and 19 deletions.
1 change: 1 addition & 0 deletions ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -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"
1 change: 1 addition & 0 deletions ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -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"
2 changes: 1 addition & 1 deletion lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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';

Expand Down
132 changes: 132 additions & 0 deletions lib/page/about.dart
Original file line number Diff line number Diff line change
@@ -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<void>(
context: context,
builder: (context) {
return _AboutDialog();
},
);
}

Future<String> 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);
},
),
],
);
}
}
22 changes: 5 additions & 17 deletions lib/page/flights_page.dart → lib/page/flights.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -41,7 +41,9 @@ class _FlightsPageState extends State<FlightsPage> {
super.initState();
flights = Flights(items: []);
FirebaseAdMob.instance.initialize(appId: FirebaseAdMob.testAppId);
_bannerAd = createBannerAd()..load()..show();
_bannerAd = createBannerAd()
..load()
..show();
}

@override
Expand All @@ -62,21 +64,7 @@ class _FlightsPageState extends State<FlightsPage> {
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)
)
],
),
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit 1901897

Please sign in to comment.