diff --git a/lib/widgets/about/about_page.dart b/lib/widgets/about/about_page.dart index 727f59028..6777a7257 100644 --- a/lib/widgets/about/about_page.dart +++ b/lib/widgets/about/about_page.dart @@ -1,4 +1,5 @@ import 'package:aves/widgets/about/licenses.dart'; +import 'package:aves/widgets/common/link_chip.dart'; import 'package:flutter/material.dart'; import 'package:flutter_staggered_animations/flutter_staggered_animations.dart'; @@ -19,17 +20,27 @@ class AboutPage extends StatelessWidget { delegate: SliverChildListDelegate( [ Center( - child: Text.rich( - TextSpan( - children: [ - const TextSpan(text: 'Made with ❤️ and '), - WidgetSpan( - child: FlutterLogo( - size: Theme.of(context).textTheme.bodyText2.fontSize * 1.25, - ), + child: Column( + children: [ + Text.rich( + TextSpan( + children: [ + const TextSpan(text: 'Made with ❤️ and '), + WidgetSpan( + child: FlutterLogo( + size: Theme.of(context).textTheme.bodyText2.fontSize * 1.25, + ), + ), + ], ), - ], - ), + ), + const SizedBox(height: 8), + const LinkChip( + text: 'Sources', + url: 'https://github.com/deckerst/aves', + textStyle: TextStyle(fontWeight: FontWeight.bold), + ), + ], ), ), const SizedBox(height: 8), diff --git a/lib/widgets/about/licenses.dart b/lib/widgets/about/licenses.dart index 5c7334b63..9c597d937 100644 --- a/lib/widgets/about/licenses.dart +++ b/lib/widgets/about/licenses.dart @@ -1,11 +1,11 @@ import 'package:aves/utils/constants.dart'; import 'package:aves/utils/durations.dart'; import 'package:aves/widgets/common/icons.dart'; +import 'package:aves/widgets/common/link_chip.dart'; import 'package:aves/widgets/common/menu_row.dart'; import 'package:collection/collection.dart'; import 'package:flutter/material.dart'; import 'package:flutter_staggered_animations/flutter_staggered_animations.dart'; -import 'package:url_launcher/url_launcher.dart'; class Licenses extends StatefulWidget { @override @@ -115,8 +115,6 @@ class LicenseRow extends StatelessWidget { const LicenseRow(this.package); - static const borderRadius = BorderRadius.all(Radius.circular(8)); - @override Widget build(BuildContext context) { final textTheme = Theme.of(context).textTheme; @@ -128,50 +126,17 @@ class LicenseRow extends StatelessWidget { child: Column( crossAxisAlignment: CrossAxisAlignment.start, children: [ - InkWell( - borderRadius: borderRadius, - onTap: () => launch(package.sourceUrl), - child: Padding( - padding: const EdgeInsets.all(8), - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - Text( - package.name, - style: const TextStyle(fontWeight: FontWeight.bold), - ), - const SizedBox(width: 8), - Icon( - AIcons.openInNew, - size: bodyTextStyle.fontSize, - ) - ], - ), - ), + LinkChip( + text: package.name, + url: package.sourceUrl, + textStyle: const TextStyle(fontWeight: FontWeight.bold), ), Padding( padding: const EdgeInsetsDirectional.only(start: 16), - child: InkWell( - borderRadius: borderRadius, - onTap: () => launch(package.licenseUrl), - child: Padding( - padding: const EdgeInsets.all(8.0), - child: Row( - mainAxisSize: MainAxisSize.min, - children: [ - Text( - package.license, - style: TextStyle(color: subColor), - ), - const SizedBox(width: 8), - Icon( - AIcons.openInNew, - size: bodyTextStyle.fontSize, - color: subColor, - ) - ], - ), - ), + child: LinkChip( + text: package.license, + url: package.licenseUrl, + color: subColor, ), ), ], diff --git a/lib/widgets/common/link_chip.dart b/lib/widgets/common/link_chip.dart new file mode 100644 index 000000000..5a50dee38 --- /dev/null +++ b/lib/widgets/common/link_chip.dart @@ -0,0 +1,53 @@ +import 'package:aves/widgets/common/icons.dart'; +import 'package:flutter/material.dart'; +import 'package:url_launcher/url_launcher.dart'; + +class LinkChip extends StatelessWidget { + final String text; + final String url; + final Color color; + final TextStyle textStyle; + + static const borderRadius = BorderRadius.all(Radius.circular(8)); + + const LinkChip({ + Key key, + @required this.text, + @required this.url, + this.color, + this.textStyle, + }) : super(key: key); + + @override + Widget build(BuildContext context) { + final effectiveTextStyle = (textStyle ?? DefaultTextStyle.of(context).style).copyWith( + color: color, + ); + return InkWell( + borderRadius: borderRadius, + onTap: () async { + if (await canLaunch(url)) { + await launch(url); + } + }, + child: Padding( + padding: const EdgeInsets.all(8.0), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Text( + text, + style: effectiveTextStyle, + ), + const SizedBox(width: 8), + Icon( + AIcons.openInNew, + size: Theme.of(context).textTheme.bodyText2.fontSize, + color: color, + ) + ], + ), + ), + ); + } +}