wonders/lib/ui/screens/home_menu/about_dialog_content.dart

92 lines
3.8 KiB
Dart
Raw Normal View History

2022-08-29 20:38:28 -06:00
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
2022-08-29 20:38:28 -06:00
import 'package:flutter/gestures.dart';
import 'package:url_launcher/url_launcher.dart';
2022-08-29 20:38:28 -06:00
import 'package:wonders/common_libs.dart';
import 'package:wonders/logic/common/platform_info.dart';
2022-08-29 20:38:28 -06:00
import 'package:wonders/ui/common/modals/fullscreen_web_view.dart';
class AboutDialogContent extends StatelessWidget {
const AboutDialogContent({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
void handleTap(String url) {
if(PlatformInfo.isDesktopOrWeb){
launchUrl(Uri.parse(url));
} else {
Navigator.push(context, CupertinoPageRoute(builder: (_) => FullscreenWebView(url)));
}
}
2022-08-29 20:38:28 -06:00
List<TextSpan> buildSpan(String text, {Map<String, List<String>>? linkSupplants}) {
if (linkSupplants?.isNotEmpty ?? false) {
final r = RegExp(r'\{\w+\}');
final matches = r.allMatches(text);
final a = text.split(r);
final supplantKeys = matches.map((x) => x.group(0));
final sortedEntries = supplantKeys.map((x) => linkSupplants?.entries.firstWhere((e) => e.key == x));
final spans = <TextSpan>[];
for (var i = 0; i < a.length; i++) {
spans.add(TextSpan(text: a[i]));
if (i < sortedEntries.length) {
final label = sortedEntries.elementAt(i)!.value[0];
final link = sortedEntries.elementAt(i)!.value[1];
spans.add(TextSpan(
text: label,
recognizer: TapGestureRecognizer()..onTap = () => handleTap(link),
style: TextStyle(fontWeight: FontWeight.bold, color: $styles.colors.accent1),
));
}
}
return spans;
} else {
return [TextSpan(text: text)];
}
}
2023-03-01 14:32:43 -07:00
double fontSize = $styles.text.body.fontSize!;
2022-09-01 21:04:25 -06:00
fontSize *= MediaQuery.textScaleFactorOf(context);
2022-08-29 20:38:28 -06:00
return SingleChildScrollView(
child: Column(children: [
Gap($styles.insets.sm),
RichText(
text: TextSpan(
2022-09-01 21:04:25 -06:00
style: $styles.text.bodySmall.copyWith(color: Colors.black, fontSize: fontSize),
2022-08-29 20:38:28 -06:00
children: [
...buildSpan($strings.homeMenuAboutWonderous),
...buildSpan($strings.homeMenuAboutBuilt('{flutterUrl}', '{gskinnerUrl}'), linkSupplants: {
2022-12-03 12:36:06 -07:00
'{flutterUrl}': [$strings.homeMenuAboutFlutter, 'https://flutter.dev'],
'{gskinnerUrl}': [$strings.homeMenuAboutGskinner, 'https://gskinner.com/flutter'],
2022-08-29 20:38:28 -06:00
}),
...buildSpan('\n\n'),
2022-12-12 09:32:25 -07:00
...buildSpan('${$strings.homeMenuAboutLearn('{wonderousUrl}')} ', linkSupplants: {
2022-12-12 10:12:50 -07:00
'{wonderousUrl}': [$strings.homeMenuAboutApp, 'https://flutter.gskinner.com/wonderous/'],
2022-08-29 20:38:28 -06:00
}),
2022-12-03 12:36:06 -07:00
...buildSpan($strings.homeMenuAboutSource('{githubUrl}'), linkSupplants: {
2022-12-12 09:33:26 -07:00
'{githubUrl}': [($strings.homeMenuAboutRepo), 'https://github.com/gskinnerTeam/flutter-wonderous-app'],
2022-08-29 20:38:28 -06:00
}),
...buildSpan(' ${$strings.privacyStatement('{privacyUrl}')}', linkSupplants: {
'{privacyUrl}': [$strings.privacyPolicy, 'https://flutter.gskinner.com/wonderous/privacy/'],
}),
2022-08-29 20:38:28 -06:00
...buildSpan('\n\n'),
2022-12-12 09:32:25 -07:00
...buildSpan('${$strings.homeMenuAboutPublic('{metUrl}')} ', linkSupplants: {
2022-12-03 12:36:06 -07:00
'{metUrl}': [
2022-08-29 20:38:28 -06:00
$strings.homeMenuAboutMet,
'https://www.metmuseum.org/about-the-met/policies-and-documents/open-access'
],
}),
2022-12-03 12:36:06 -07:00
...buildSpan($strings.homeMenuAboutPhotography('{unsplashUrl}'), linkSupplants: {
'{unsplashUrl}': [$strings.homeMenuAboutUnsplash, 'https://unsplash.com/@gskinner/collections'],
2022-08-29 20:38:28 -06:00
}),
],
),
),
]),
);
}
}