lemmur-app-android/lib/widgets/about_tile.dart

101 lines
3.1 KiB
Dart
Raw Normal View History

2021-01-30 14:11:41 +01:00
import 'package:flutter/cupertino.dart';
2020-10-01 17:57:04 +02:00
import 'package:flutter/material.dart';
2021-03-18 17:03:42 +01:00
import 'package:flutter/services.dart';
2020-10-01 17:57:04 +02:00
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:flutter_markdown/flutter_markdown.dart';
import 'package:package_info/package_info.dart';
2021-01-30 14:11:41 +01:00
import '../gen/assets.gen.dart';
2020-10-01 17:57:04 +02:00
import '../hooks/memo_future.dart';
import '../url_launcher.dart';
import 'bottom_modal.dart';
2020-10-01 18:15:08 +02:00
/// Title that opens a dialog with information about Lemmur.
/// Licenses, changelog, version etc.
2020-10-01 17:57:04 +02:00
class AboutTile extends HookWidget {
2021-01-03 19:43:39 +01:00
const AboutTile();
2020-10-01 17:57:04 +02:00
@override
Widget build(BuildContext context) {
2021-02-06 13:17:39 +01:00
final packageInfoSnap = useMemoFuture(
2021-03-18 17:03:42 +01:00
() async {
try {
return await PackageInfo.fromPlatform();
} on MissingPluginException {
// when we get here it means PackageInfo does not support this platform
return PackageInfo(
appName: 'lemmur',
packageName: '',
version: '',
buildNumber: '',
);
2021-03-18 17:03:42 +01:00
}
},
2021-02-06 13:17:39 +01:00
);
2020-10-01 17:57:04 +02:00
final assetBundle = DefaultAssetBundle.of(context);
final changelogSnap =
useMemoFuture(() => assetBundle.loadString('CHANGELOG.md'));
final packageInfo = packageInfoSnap.data;
final changelog = changelogSnap.data;
if (!packageInfoSnap.hasData ||
!changelogSnap.hasData ||
packageInfo == null ||
changelog == null) {
return const SizedBox.shrink();
}
2020-10-01 17:57:04 +02:00
return AboutListTile(
2021-01-03 19:43:39 +01:00
icon: const Icon(Icons.info),
2020-10-01 17:57:04 +02:00
aboutBoxChildren: [
2021-02-09 15:12:13 +01:00
TextButton.icon(
2021-01-03 19:43:39 +01:00
icon: const Icon(Icons.subject),
label: const Text('changelog'),
2021-02-09 15:12:13 +01:00
onPressed: () => showBottomModal(
2020-10-01 17:57:04 +02:00
context: context,
2021-02-09 15:12:13 +01:00
padding: const EdgeInsets.all(8),
builder: (_) => MarkdownBody(data: changelog),
2020-10-01 17:57:04 +02:00
),
),
2021-02-09 15:12:13 +01:00
TextButton.icon(
2021-01-03 19:43:39 +01:00
icon: const Icon(Icons.code),
label: const Text('source code'),
2020-10-01 17:57:04 +02:00
onPressed: () => openInBrowser('https://github.com/krawieck/lemmur'),
),
2021-02-09 15:12:13 +01:00
TextButton.icon(
2021-01-03 19:43:39 +01:00
icon: const Icon(Icons.monetization_on),
label: const Text('support development'),
onPressed: () {
showDialog(
context: context,
builder: (_) => Dialog(
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
2021-02-09 15:12:13 +01:00
TextButton(
onPressed: () =>
openInBrowser('https://patreon.com/lemmur'),
2021-01-03 19:43:39 +01:00
child: const Text('Patreon'),
),
2021-02-09 15:12:13 +01:00
TextButton(
onPressed: () =>
openInBrowser('https://buymeacoff.ee/lemmur'),
2021-01-03 19:43:39 +01:00
child: const Text('Buy Me a Coffee'),
),
],
),
),
);
}, // TODO: link to some donation site
2020-10-01 17:57:04 +02:00
),
],
applicationIcon: ClipRRect(
borderRadius: BorderRadius.circular(10),
2021-01-30 14:11:41 +01:00
child: Assets.appIcon.image(width: 54),
),
2020-10-01 17:57:04 +02:00
applicationVersion: packageInfo.version,
);
}
}