diff options
Diffstat (limited to 'lib/widgets/about')
| -rw-r--r-- | lib/widgets/about/about_mobile_page.dart | 53 | ||||
| -rw-r--r-- | lib/widgets/about/about_page.dart | 19 | ||||
| -rw-r--r-- | lib/widgets/about/about_tv_page.dart | 211 | ||||
| -rw-r--r-- | lib/widgets/about/app_ref.dart | 101 | ||||
| -rw-r--r-- | lib/widgets/about/bug_report.dart | 220 | ||||
| -rw-r--r-- | lib/widgets/about/credits.dart | 44 | ||||
| -rw-r--r-- | lib/widgets/about/data_usage.dart | 179 | ||||
| -rw-r--r-- | lib/widgets/about/licenses.dart | 139 | ||||
| -rw-r--r-- | lib/widgets/about/policy_page.dart | 64 | ||||
| -rw-r--r-- | lib/widgets/about/title.dart | 37 | ||||
| -rw-r--r-- | lib/widgets/about/translators.dart | 121 | ||||
| -rw-r--r-- | lib/widgets/about/tv_license_page.dart | 396 |
12 files changed, 1584 insertions, 0 deletions
diff --git a/lib/widgets/about/about_mobile_page.dart b/lib/widgets/about/about_mobile_page.dart new file mode 100644 index 0000000..53aee33 --- /dev/null +++ b/lib/widgets/about/about_mobile_page.dart @@ -0,0 +1,53 @@ +import 'package:aves/widgets/about/app_ref.dart'; +import 'package:aves/widgets/about/bug_report.dart'; +import 'package:aves/widgets/about/credits.dart'; +import 'package:aves/widgets/about/data_usage.dart'; +import 'package:aves/widgets/about/licenses.dart'; +import 'package:aves/widgets/about/translators.dart'; +import 'package:aves/widgets/common/basic/insets.dart'; +import 'package:aves/widgets/common/basic/scaffold.dart'; +import 'package:aves/widgets/common/extensions/build_context.dart'; +import 'package:flutter/material.dart'; + +class AboutMobilePage extends StatelessWidget { + const AboutMobilePage({super.key}); + + @override + Widget build(BuildContext context) { + return AvesScaffold( + appBar: AppBar( + title: Text(context.l10n.aboutPageTitle), + ), + body: GestureAreaProtectorStack( + child: SafeArea( + bottom: false, + child: CustomScrollView( + slivers: [ + SliverPadding( + padding: const EdgeInsets.only(top: 16), + sliver: SliverList( + delegate: SliverChildListDelegate( + [ + const AppReference(), + const Divider(), + const BugReport(), + const Divider(), + const AboutDataUsage(), + const Divider(), + const AboutCredits(), + const Divider(), + const AboutTranslators(), + const Divider(), + ], + ), + ), + ), + const Licenses(), + const BottomPaddingSliver(), + ], + ), + ), + ), + ); + } +} diff --git a/lib/widgets/about/about_page.dart b/lib/widgets/about/about_page.dart new file mode 100644 index 0000000..10388dc --- /dev/null +++ b/lib/widgets/about/about_page.dart @@ -0,0 +1,19 @@ +import 'package:aves/model/settings/settings.dart'; +import 'package:aves/widgets/about/about_mobile_page.dart'; +import 'package:aves/widgets/about/about_tv_page.dart'; +import 'package:flutter/material.dart'; + +class AboutPage extends StatelessWidget { + static const routeName = '/about'; + + const AboutPage({super.key}); + + @override + Widget build(BuildContext context) { + if (settings.useTvLayout) { + return const AboutTvPage(); + } else { + return const AboutMobilePage(); + } + } +} diff --git a/lib/widgets/about/about_tv_page.dart b/lib/widgets/about/about_tv_page.dart new file mode 100644 index 0000000..34b8333 --- /dev/null +++ b/lib/widgets/about/about_tv_page.dart @@ -0,0 +1,211 @@ +import 'package:aves/model/device.dart'; +import 'package:aves/theme/themes.dart'; +import 'package:aves/widgets/about/app_ref.dart'; +import 'package:aves/widgets/about/credits.dart'; +import 'package:aves/widgets/about/translators.dart'; +import 'package:aves/widgets/about/tv_license_page.dart'; +import 'package:aves/widgets/common/basic/insets.dart'; +import 'package:aves/widgets/common/basic/scaffold.dart'; +import 'package:aves/widgets/common/behaviour/pop/scope.dart'; +import 'package:aves/widgets/common/behaviour/pop/tv_navigation.dart'; +import 'package:aves/widgets/common/extensions/build_context.dart'; +import 'package:aves/widgets/common/identity/buttons/outlined_button.dart'; +import 'package:aves/widgets/navigation/tv_rail.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +class AboutTvPage extends StatelessWidget { + const AboutTvPage({super.key}); + + @override + Widget build(BuildContext context) { + return AvesScaffold( + body: AvesPopScope( + handlers: [tvNavigationPopHandler], + child: Row( + children: [ + TvRail( + controller: context.read<TvRailController>(), + ), + Expanded( + child: Column( + children: [ + const SizedBox(height: 8), + DirectionalSafeArea( + start: false, + bottom: false, + child: AppBar( + automaticallyImplyLeading: false, + title: Text(context.l10n.aboutPageTitle), + elevation: 0, + primary: false, + ), + ), + Expanded( + child: MediaQuery.removePadding( + context: context, + removeLeft: true, + removeTop: true, + removeRight: true, + removeBottom: true, + child: const _Content(), + ), + ), + ], + ), + ), + ], + ), + ), + ); + } +} + +class _Content extends StatefulWidget { + const _Content(); + + @override + State<_Content> createState() => _ContentState(); +} + +enum _Section { links, credits, translators, licenses } + +class _ContentState extends State<_Content> { + final FocusNode _railFocusNode = FocusNode(); + final ValueNotifier<int> _railIndexNotifier = ValueNotifier(0); + + static const double railWidth = 256; + + @override + void dispose() { + _railIndexNotifier.dispose(); + _railFocusNode.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return ValueListenableBuilder<int>( + valueListenable: _railIndexNotifier, + builder: (context, selectedIndex, child) { + final rail = Focus( + focusNode: _railFocusNode, + skipTraversal: true, + canRequestFocus: false, + child: ConstrainedBox( + constraints: BoxConstraints.loose(const Size.fromWidth(railWidth)), + child: Center( + child: ListView.builder( + itemBuilder: (context, index) { + final isSelected = index == selectedIndex; + final theme = Theme.of(context); + final colors = theme.colorScheme; + return ListTile( + title: DefaultTextStyle( + style: theme.textTheme.bodyLarge!.copyWith( + color: isSelected ? colors.primary : colors.onSurface.withValues(alpha: .64), + ), + child: _getTitle(_Section.values[index]), + ), + selected: isSelected, + contentPadding: const EdgeInsets.symmetric(vertical: 8, horizontal: 24), + onTap: () => _railIndexNotifier.value = index, + shape: const RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(123)), + ), + ); + }, + itemCount: _Section.values.length, + ), + ), + ), + ); + + return Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + rail, + Expanded( + child: MediaQuery.removePadding( + context: context, + removeLeft: !context.isRtl, + removeRight: context.isRtl, + child: _getBody(_Section.values[selectedIndex]), + ), + ), + ], + ); + }, + ); + } + + Widget _getTitle(_Section key) { + switch (key) { + case _Section.links: + return Text('${context.l10n.appName} ${device.packageVersion}'); + case _Section.credits: + return Text(context.l10n.aboutCreditsSectionTitle); + case _Section.translators: + return Text(context.l10n.aboutTranslatorsSectionTitle); + case _Section.licenses: + return Text(context.l10n.aboutLicensesSectionTitle); + } + } + + Widget _getBody(_Section key) { + switch (key) { + case _Section.links: + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: AppReference.buildLinks(context) + .map((v) => Padding( + padding: const EdgeInsets.all(16), + child: v, + )) + .toList(), + ); + case _Section.credits: + return Padding( + padding: const EdgeInsets.all(16), + child: AboutCredits.buildBody(context), + ); + case _Section.translators: + return Padding( + padding: const EdgeInsets.all(16), + child: AboutTranslators.buildBody(context), + ); + case _Section.licenses: + return Padding( + padding: const EdgeInsets.all(16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text(context.l10n.aboutLicensesBanner), + const SizedBox(height: 16), + Center( + child: AvesOutlinedButton( + label: context.l10n.aboutLicensesShowAllButtonLabel, + onPressed: () => Navigator.maybeOf(context)?.push( + MaterialPageRoute( + builder: (context) { + final theme = Theme.of(context); + final listTileTheme = theme.listTileTheme; + return Theme( + data: theme.copyWith( + listTileTheme: listTileTheme.copyWith( + tileColor: Themes.firstLayerColor(context), + ), + ), + child: const TvLicensePage(), + ); + }, + ), + ), + ), + ), + ], + ), + ); + } + } +} diff --git a/lib/widgets/about/app_ref.dart b/lib/widgets/about/app_ref.dart new file mode 100644 index 0000000..d45aa94 --- /dev/null +++ b/lib/widgets/about/app_ref.dart @@ -0,0 +1,101 @@ +import 'package:aves/model/device.dart'; +import 'package:aves/ref/locales.dart'; +import 'package:aves/theme/icons.dart'; +import 'package:aves/widgets/about/policy_page.dart'; +import 'package:aves/widgets/common/basic/link_chip.dart'; +import 'package:aves/widgets/common/extensions/build_context.dart'; +import 'package:aves/widgets/common/identity/aves_logo.dart'; +import 'package:flutter/material.dart'; + +class AppReference extends StatelessWidget { + static const avesGithub = 'https://github.com/deckerst/aves'; + + const AppReference({super.key}); + + @override + Widget build(BuildContext context) { + return Center( + child: Column( + children: [ + _buildAvesLine(context), + const SizedBox(height: 16), + Wrap( + alignment: WrapAlignment.center, + spacing: 16, + crossAxisAlignment: WrapCrossAlignment.center, + children: AppReference.buildLinks(context), + ), + ], + ), + ); + } + + Widget _buildAvesLine(BuildContext context) { + final locale = context.locale; + final textScaler = MediaQuery.textScalerOf(context); + return Row( + mainAxisSize: MainAxisSize.min, + children: [ + AvesLogo( + size: textScaler.scale(_getAppTitleStyle(locale).fontSize!) * 1.3, + ), + const SizedBox(width: 8), + Text( + context.l10n.appName, + style: _getAppTitleStyle(locale), + ), + const SizedBox(width: 8), + Text( + device.packageVersion, + style: _getAppTitleStyle(locale), + ), + ], + ); + } + + TextStyle _getAppTitleStyle(String locale) => TextStyle( + fontSize: 20, + fontWeight: FontWeight.normal, + letterSpacing: canHaveLetterSpacing(locale) ? 1 : 0, + fontFeatures: const [FontFeature.enable('smcp')], + ); + + static List<Widget> buildLinks(BuildContext context) { + final l10n = context.l10n; + return [ + LinkChip( + leading: Icon( + AIcons.github, + size: 24, + ), + text: 'GitHub', + urlString: AppReference.avesGithub, + ), + LinkChip( + leading: Icon( + AIcons.legal, + size: 22, + ), + text: l10n.aboutLinkLicense, + urlString: '${AppReference.avesGithub}/blob/main/LICENSE', + ), + LinkChip( + leading: const Icon( + AIcons.privacy, + size: 22, + ), + text: l10n.aboutLinkPolicy, + onTap: () => _goToPolicyPage(context), + ), + ]; + } + + static void _goToPolicyPage(BuildContext context) { + Navigator.maybeOf(context)?.push( + MaterialPageRoute( + settings: const RouteSettings(name: PolicyPage.routeName), + builder: (context) => const PolicyPage(), + ), + ); + } +} diff --git a/lib/widgets/about/bug_report.dart b/lib/widgets/about/bug_report.dart new file mode 100644 index 0000000..694ef02 --- /dev/null +++ b/lib/widgets/about/bug_report.dart @@ -0,0 +1,220 @@ +import 'dart:convert'; +import 'dart:io'; +import 'dart:ui' as ui; + +import 'package:aves/app_flavor.dart'; +import 'package:aves/flutter_version.dart'; +import 'package:aves/model/device.dart'; +import 'package:aves/model/settings/settings.dart'; +import 'package:aves/ref/locales.dart'; +import 'package:aves/ref/mime_types.dart'; +import 'package:aves/services/common/services.dart'; +import 'package:aves/theme/colors.dart'; +import 'package:aves/theme/durations.dart'; +import 'package:aves/theme/styles.dart'; +import 'package:aves/theme/themes.dart'; +import 'package:aves/widgets/about/app_ref.dart'; +import 'package:aves/widgets/aves_app.dart'; +import 'package:aves/widgets/common/action_mixins/feedback.dart'; +import 'package:aves/widgets/common/extensions/build_context.dart'; +import 'package:aves/widgets/common/fx/borders.dart'; +import 'package:aves/widgets/common/identity/aves_filter_chip.dart'; +import 'package:aves/widgets/common/identity/buttons/outlined_button.dart'; +import 'package:aves_model/aves_model.dart'; +import 'package:connectivity_plus/connectivity_plus.dart'; +import 'package:device_info_plus/device_info_plus.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; +import 'package:intl/intl.dart'; +import 'package:package_info_plus/package_info_plus.dart'; +import 'package:provider/provider.dart'; + +class BugReport extends StatefulWidget { + const BugReport({super.key}); + + @override + State<BugReport> createState() => _BugReportState(); +} + +class _BugReportState extends State<BugReport> { + bool _showInstructions = false; + + @override + Widget build(BuildContext context) { + final animationDuration = context.select<DurationsData, Duration>((v) => v.expansionTileAnimation); + return ExpansionPanelList( + expansionCallback: (index, isExpanded) { + setState(() => _showInstructions = isExpanded); + }, + animationDuration: animationDuration, + expandedHeaderPadding: EdgeInsets.zero, + elevation: 0, + children: [ + ExpansionPanel( + headerBuilder: (context, isExpanded) => ConstrainedBox( + constraints: const BoxConstraints(minHeight: kMinInteractiveDimension), + child: Container( + padding: const EdgeInsets.symmetric(horizontal: 16), + alignment: AlignmentDirectional.centerStart, + child: Text(context.l10n.aboutBugSectionTitle, style: AStyles.knownTitleText), + ), + ), + body: const BugReportContent(), + isExpanded: _showInstructions, + canTapOnHeader: true, + backgroundColor: Colors.transparent, + ), + ], + ); + } +} + +class BugReportContent extends StatefulWidget { + const BugReportContent({super.key}); + + @override + State<BugReportContent> createState() => _BugReportContentState(); +} + +class _BugReportContentState extends State<BugReportContent> with FeedbackMixin { + late Future<String> _infoLoader; + static const bugReportUrl = '${AppReference.avesGithub}/issues/new?labels=type%3Abug&template=bug_report.md'; + + @override + void initState() { + super.initState(); + _infoLoader = _getInfo(context); + } + + @override + Widget build(BuildContext context) { + final l10n = context.l10n; + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + _buildStep(1, l10n.aboutBugSaveLogInstruction, l10n.saveTooltip, _saveLogs), + _buildStep(2, l10n.aboutBugCopyInfoInstruction, l10n.aboutBugCopyInfoButton, _copySystemInfo), + FutureBuilder<String>( + future: _infoLoader, + builder: (context, snapshot) { + final info = snapshot.data; + if (info == null) return const SizedBox(); + + return Container( + decoration: BoxDecoration( + color: Themes.secondLayerColor(context), + border: Border.all( + color: Theme.of(context).dividerColor, + width: AvesBorder.curvedBorderWidth(context), + ), + borderRadius: const BorderRadius.all(Radius.circular(16)), + ), + constraints: const BoxConstraints(maxHeight: 100), + margin: const EdgeInsets.symmetric(vertical: 8), + clipBehavior: Clip.antiAlias, + child: SingleChildScrollView( + padding: const EdgeInsets.all(8), + // to show a scroll bar, we would need to provide a scroll controller + // to both the `Scrollable` and the `Scrollbar`, but + // as of Flutter v3.0.0, `SelectableText` does not allow passing the `scrollController` + child: SelectableText( + info, + textDirection: ui.TextDirection.ltr, + style: Theme.of(context).textTheme.bodySmall, + ), + ), + ); + }, + ), + _buildStep(3, l10n.aboutBugReportInstruction, l10n.aboutBugReportButton, _goToGithub), + const SizedBox(height: 8), + ], + ), + ); + } + + Widget _buildStep(int step, String text, String buttonText, VoidCallback onPressed) { + final isMonochrome = settings.themeColorMode == AvesThemeColorMode.monochrome; + return Padding( + padding: const EdgeInsets.symmetric(vertical: 4), + child: Row( + children: [ + Container( + padding: const EdgeInsets.all(12), + decoration: BoxDecoration( + border: Border.fromBorderSide(BorderSide( + color: isMonochrome ? context.select<AvesColorsData, Color>((v) => v.neutral) : Theme.of(context).colorScheme.primary, + width: AvesFilterChip.outlineWidth, + )), + shape: BoxShape.circle, + ), + child: Text(NumberFormat('0', context.locale).format(step)), + ), + const SizedBox(width: 8), + Expanded(child: Text(text)), + const SizedBox(width: 8), + AvesOutlinedButton( + label: buttonText, + onPressed: onPressed, + ), + ], + ), + ); + } + + Future<String> _getInfo(BuildContext context) async { + final flavor = context.read<AppFlavor>().toString().split('.')[1]; + final packageInfo = await PackageInfo.fromPlatform(); + final androidInfo = await DeviceInfoPlugin().androidInfo; + final mediaQuery = MediaQuery.of(context); + final view = View.of(context); + final supportsHdr = await windowService.supportsHdr(); + final supportsWideGamut = await windowService.supportsWideGamut(); + final connections = await Connectivity().checkConnectivity(); + final storageVolumes = await storageService.getStorageVolumes(); + final storageGrants = await storageService.getGrantedDirectories(); + return [ + 'Package: ${device.packageName}', + 'Installer: ${packageInfo.installerStore}', + 'Aves version: ${device.packageVersion}-$flavor, build ${packageInfo.buildNumber}', + 'Flutter: ${version['channel']} ${version['frameworkVersion']}', + 'Android version: ${androidInfo.version.release}, API ${androidInfo.version.sdkInt}', + 'Android build: ${androidInfo.display}', + 'Device: ${androidInfo.manufacturer} ${androidInfo.model}', + 'Display: pixel ratio=${view.devicePixelRatio}, logical=${mediaQuery.size.width}x${mediaQuery.size.height}, physical=${view.physicalSize.width}x${view.physicalSize.height}', + 'Support: dynamic colors=${device.isDynamicColorAvailable}, geocoder=${device.hasGeocoder}, HDR=$supportsHdr, wide gamut=$supportsWideGamut', + 'Mobile services: ${mobileServices.isServiceAvailable ? 'ready' : 'not available'}', + 'Connectivity: ${connections.map((v) => v.name).join(', ')}', + 'System locales: ${WidgetsBinding.instance.platformDispatcher.locales.join(', ')}', + 'Storage volumes: ${storageVolumes.map((v) => v.path).join(', ')}', + 'Storage grants: ${storageGrants.join(', ')}', + 'Error reporting: ${settings.isErrorReportingAllowed}', + ].join('\n'); + } + + Future<void> _saveLogs() async { + final result = await Process.run('logcat', ['-d']); + final logs = result.stdout; + final success = await storageService.createFile( + 'aves-logs-${DateFormat('yyyyMMdd_HHmmss', asciiLocale).format(DateTime.now())}.txt', + MimeTypes.plainText, + Uint8List.fromList(utf8.encode(logs)), + ); + if (success != null) { + if (success) { + showFeedback(context, FeedbackType.info, context.l10n.genericSuccessFeedback); + } else { + showFeedback(context, FeedbackType.warn, context.l10n.genericFailureFeedback); + } + } + } + + Future<void> _copySystemInfo() async { + await Clipboard.setData(ClipboardData(text: await _infoLoader)); + showFeedback(context, FeedbackType.info, context.l10n.genericSuccessFeedback); + } + + Future<void> _goToGithub() => AvesApp.launchUrl(bugReportUrl); +} diff --git a/lib/widgets/about/credits.dart b/lib/widgets/about/credits.dart new file mode 100644 index 0000000..1aa6e61 --- /dev/null +++ b/lib/widgets/about/credits.dart @@ -0,0 +1,44 @@ +import 'package:aves/widgets/about/title.dart'; +import 'package:aves/widgets/common/basic/link_chip.dart'; +import 'package:aves/widgets/common/extensions/build_context.dart'; +import 'package:flutter/material.dart'; + +class AboutCredits extends StatelessWidget { + const AboutCredits({super.key}); + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + AboutSectionTitle(text: context.l10n.aboutCreditsSectionTitle), + const SizedBox(height: 8), + buildBody(context), + const SizedBox(height: 8), + ], + ), + ); + } + + static Widget buildBody(BuildContext context) { + final l10n = context.l10n; + return Text.rich( + TextSpan( + children: [ + TextSpan(text: l10n.aboutCreditsWorldAtlas1), + const WidgetSpan( + child: LinkChip( + text: 'World Atlas', + urlString: 'https://github.com/topojson/world-atlas', + textStyle: TextStyle(fontWeight: FontWeight.bold), + ), + alignment: PlaceholderAlignment.middle, + ), + TextSpan(text: l10n.aboutCreditsWorldAtlas2), + ], + ), + ); + } +} diff --git a/lib/widgets/about/data_usage.dart b/lib/widgets/about/data_usage.dart new file mode 100644 index 0000000..67d5d52 --- /dev/null +++ b/lib/widgets/about/data_usage.dart @@ -0,0 +1,179 @@ +import 'package:aves/ref/brand_colors.dart'; +import 'package:aves/services/common/services.dart'; +import 'package:aves/theme/colors.dart'; +import 'package:aves/theme/durations.dart'; +import 'package:aves/theme/styles.dart'; +import 'package:aves/utils/file_utils.dart'; +import 'package:aves/widgets/common/action_mixins/feedback.dart'; +import 'package:aves/widgets/common/extensions/build_context.dart'; +import 'package:aves/widgets/common/identity/aves_donut.dart'; +import 'package:aves/widgets/common/identity/buttons/outlined_button.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +class AboutDataUsage extends StatefulWidget { + const AboutDataUsage({super.key}); + + @override + State<AboutDataUsage> createState() => _AboutDataUsageState(); +} + +class _AboutDataUsageState extends State<AboutDataUsage> with FeedbackMixin { + late Future<Map<String, int>> _loader; + bool _isExpanded = false; + + @override + void initState() { + super.initState(); + _reload(); + } + + @override + Widget build(BuildContext context) { + final l10n = context.l10n; + final animationDuration = context.select<DurationsData, Duration>((v) => v.expansionTileAnimation); + return ExpansionPanelList( + expansionCallback: (index, isExpanded) { + setState(() => _isExpanded = isExpanded); + }, + animationDuration: animationDuration, + expandedHeaderPadding: EdgeInsets.zero, + elevation: 0, + children: [ + ExpansionPanel( + headerBuilder: (context, isExpanded) => ConstrainedBox( + constraints: const BoxConstraints(minHeight: kMinInteractiveDimension), + child: Container( + padding: const EdgeInsets.symmetric(horizontal: 16), + alignment: AlignmentDirectional.centerStart, + child: Text(l10n.aboutDataUsageSectionTitle, style: AStyles.knownTitleText), + ), + ), + body: FutureBuilder<Map<String, int>>( + future: _loader, + builder: (context, snapshot) { + final data = snapshot.data; + if (data == null) return const SizedBox(); + + final dataMap = { + DataUsageDonut.bin: data['trash'] ?? 0, + DataUsageDonut.database: data['database'] ?? 0, + DataUsageDonut.vaults: data['vaults'] ?? 0, + DataUsageDonut.misc: data['miscData'] ?? 0, + }; + final flutter = data['flutter'] ?? 0; + if (flutter > 0) { + dataMap[DataUsageDonut.flutter] = flutter; + } + final cacheMap = { + DataUsageDonut.internal: data['internalCache'] ?? 0, + DataUsageDonut.external: data['externalCache'] ?? 0, + }; + return Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + DataUsageDonut( + title: l10n.aboutDataUsageData, + byTypes: dataMap, + animationDuration: animationDuration, + ), + DataUsageDonut( + title: l10n.aboutDataUsageCache, + byTypes: cacheMap, + animationDuration: animationDuration, + ), + Center( + child: AvesOutlinedButton( + label: context.l10n.aboutDataUsageClearCache, + onPressed: () async { + await storageService.deleteTempDirectory(); + await storageService.deleteExternalCache(); + await mediaFetchService.clearImageDiskCache(); + imageCache.clear(); + _reload(); + setState(() {}); + }, + ), + ), + ], + ); + }, + ), + isExpanded: _isExpanded, + canTapOnHeader: true, + backgroundColor: Colors.transparent, + ), + ], + ); + } + + void _reload() { + _loader = storageService.getDataUsage(); + } +} + +class DataUsageDonut extends StatelessWidget { + final String title; + final Map<String, int> byTypes; + final Duration animationDuration; + + // data + static const String bin = 'bin'; + static const String database = 'database'; + static const String flutter = 'flutter'; + static const String vaults = 'vaults'; + static const String misc = 'misc'; + + // cache + static const String internal = 'internal'; + static const String external = 'external'; + + const DataUsageDonut({ + super.key, + required this.title, + required this.byTypes, + required this.animationDuration, + }); + + @override + Widget build(BuildContext context) { + final l10n = context.l10n; + final locale = context.locale; + + return AvesDonut( + title: Text(title), + byTypes: byTypes, + animationDuration: animationDuration, + formatKey: (d) { + switch (d.key) { + case bin: + return l10n.binPageTitle; + case database: + return l10n.aboutDataUsageDatabase; + case flutter: + return 'Flutter'; + case vaults: + return l10n.albumTierVaults; + case misc: + return l10n.aboutDataUsageMisc; + case internal: + return l10n.aboutDataUsageInternal; + case external: + return l10n.aboutDataUsageExternal; + default: + return d.key; + } + }, + formatValue: (v) => formatFileSize(locale, v, round: 0), + colorize: (context, d) { + final colors = context.read<AvesColorsData>(); + Color? color; + switch (d.key) { + case flutter: + color = colors.fromBrandColor(BrandColors.flutter); + } + return color ?? colors.fromString(d.key); + }, + ); + } +} diff --git a/lib/widgets/about/licenses.dart b/lib/widgets/about/licenses.dart new file mode 100644 index 0000000..3661364 --- /dev/null +++ b/lib/widgets/about/licenses.dart @@ -0,0 +1,139 @@ +import 'package:aves/app_flavor.dart'; +import 'package:aves/model/app/dependencies.dart'; +import 'package:aves/ref/brand_colors.dart'; +import 'package:aves/theme/colors.dart'; +import 'package:aves/theme/themes.dart'; +import 'package:aves/widgets/about/title.dart'; +import 'package:aves/widgets/common/basic/link_chip.dart'; +import 'package:aves/widgets/common/extensions/build_context.dart'; +import 'package:aves/widgets/common/identity/aves_expansion_tile.dart'; +import 'package:aves/widgets/common/identity/buttons/outlined_button.dart'; +import 'package:collection/collection.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +class Licenses extends StatefulWidget { + const Licenses({super.key}); + + @override + State<Licenses> createState() => _LicensesState(); +} + +class _LicensesState extends State<Licenses> { + final ValueNotifier<String?> _expandedNotifier = ValueNotifier(null); + late List<Dependency> _platform, _flutterPlugins, _flutterPackages, _dartPackages; + + @override + void initState() { + super.initState(); + _platform = List<Dependency>.from(Dependencies.androidDependencies); + _flutterPlugins = List<Dependency>.from(Dependencies.flutterPlugins(context.read<AppFlavor>())); + _flutterPackages = List<Dependency>.from(Dependencies.flutterPackages); + _dartPackages = List<Dependency>.from(Dependencies.dartPackages); + _sortPackages(); + } + + @override + void dispose() { + _expandedNotifier.dispose(); + super.dispose(); + } + + void _sortPackages() { + int compare(Dependency a, Dependency b) => compareAsciiUpperCase(a.name, b.name); + _platform.sort(compare); + _flutterPlugins.sort(compare); + _flutterPackages.sort(compare); + _dartPackages.sort(compare); + } + + @override + Widget build(BuildContext context) { + final colors = context.watch<AvesColorsData>(); + return SliverPadding( + padding: const EdgeInsets.symmetric(horizontal: 8), + sliver: SliverList( + delegate: SliverChildListDelegate( + [ + _buildHeader(), + const SizedBox(height: 16), + AvesExpansionTile( + title: context.l10n.aboutLicensesAndroidLibrariesSectionTitle, + highlightColor: colors.fromBrandColor(BrandColors.android), + expandedNotifier: _expandedNotifier, + children: _platform.map((package) => _LicenseRow(package: package)).toList(), + ), + AvesExpansionTile( + title: context.l10n.aboutLicensesFlutterPluginsSectionTitle, + highlightColor: colors.fromBrandColor(BrandColors.flutter), + expandedNotifier: _expandedNotifier, + children: _flutterPlugins.map((package) => _LicenseRow(package: package)).toList(), + ), + AvesExpansionTile( + title: context.l10n.aboutLicensesFlutterPackagesSectionTitle, + highlightColor: colors.fromBrandColor(BrandColors.flutter), + expandedNotifier: _expandedNotifier, + children: _flutterPackages.map((package) => _LicenseRow(package: package)).toList(), + ), + AvesExpansionTile( + title: context.l10n.aboutLicensesDartPackagesSectionTitle, + highlightColor: colors.fromBrandColor(BrandColors.flutter), + expandedNotifier: _expandedNotifier, + children: _dartPackages.map((package) => _LicenseRow(package: package)).toList(), + ), + Center( + child: AvesOutlinedButton( + label: context.l10n.aboutLicensesShowAllButtonLabel, + onPressed: () => Navigator.maybeOf(context)?.push( + MaterialPageRoute( + builder: (context) => Theme( + data: Theme.of(context).copyWith( + // as of Flutter v3.22.0, `cardColor` is used as a background color by `LicensePage` + cardColor: Themes.firstLayerColor(context), + ), + child: const LicensePage(), + ), + ), + ), + ), + ), + const SizedBox(height: 16), + ], + ), + ), + ); + } + + Widget _buildHeader() { + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 8), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + AboutSectionTitle(text: context.l10n.aboutLicensesSectionTitle), + const SizedBox(height: 8), + Text(context.l10n.aboutLicensesBanner), + ], + ), + ); + } +} + +class _LicenseRow extends StatelessWidget { + final Dependency package; + + const _LicenseRow({ + required this.package, + }); + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.symmetric(vertical: 4, horizontal: 8), + child: LinkChip( + text: package.name, + urlString: package.sourceUrl, + ), + ); + } +} diff --git a/lib/widgets/about/policy_page.dart b/lib/widgets/about/policy_page.dart new file mode 100644 index 0000000..0621368 --- /dev/null +++ b/lib/widgets/about/policy_page.dart @@ -0,0 +1,64 @@ +import 'package:aves/model/settings/settings.dart'; +import 'package:aves/widgets/common/basic/markdown_container.dart'; +import 'package:aves/widgets/common/basic/scaffold.dart'; +import 'package:aves/widgets/common/extensions/build_context.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/services.dart'; + +class PolicyPage extends StatefulWidget { + static const routeName = '/about/policy'; + + const PolicyPage({super.key}); + + @override + State<PolicyPage> createState() => _PolicyPageState(); +} + +class _PolicyPageState extends State<PolicyPage> { + late Future<String> _termsLoader; + + static const termsPath = 'assets/terms.md'; + static const termsDirection = TextDirection.ltr; + + @override + void initState() { + super.initState(); + _termsLoader = rootBundle.loadString(termsPath); + } + + @override + Widget build(BuildContext context) { + return AvesScaffold( + appBar: AppBar( + automaticallyImplyLeading: !settings.useTvLayout, + title: Text(context.l10n.policyPageTitle), + ), + body: SafeArea( + child: FocusableActionDetector( + autofocus: true, + shortcuts: const { + SingleActivator(LogicalKeyboardKey.arrowUp): ScrollIntent(direction: AxisDirection.up, type: ScrollIncrementType.page), + SingleActivator(LogicalKeyboardKey.arrowDown): ScrollIntent(direction: AxisDirection.down, type: ScrollIncrementType.page), + }, + child: Center( + child: FutureBuilder<String>( + future: _termsLoader, + builder: (context, snapshot) { + if (snapshot.hasError || snapshot.connectionState != ConnectionState.done) return const SizedBox(); + final terms = snapshot.data!; + return Padding( + padding: const EdgeInsets.symmetric(vertical: 8), + child: MarkdownContainer( + scrollController: PrimaryScrollController.of(context), + data: terms, + textDirection: termsDirection, + ), + ); + }, + ), + ), + ), + ), + ); + } +} diff --git a/lib/widgets/about/title.dart b/lib/widgets/about/title.dart new file mode 100644 index 0000000..ece76b3 --- /dev/null +++ b/lib/widgets/about/title.dart @@ -0,0 +1,37 @@ +import 'package:aves/model/settings/settings.dart'; +import 'package:aves/theme/styles.dart'; +import 'package:flutter/material.dart'; + +class AboutSectionTitle extends StatelessWidget { + final String text; + + const AboutSectionTitle({ + super.key, + required this.text, + }); + + @override + Widget build(BuildContext context) { + Widget child = Container( + alignment: AlignmentDirectional.centerStart, + constraints: const BoxConstraints(minHeight: kMinInteractiveDimension), + child: Text(text, style: AStyles.knownTitleText), + ); + + if (settings.useTvLayout) { + child = InkWell( + borderRadius: const BorderRadius.all(Radius.circular(123)), + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 16), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + child, + ], + ), + ), + ); + } + return child; + } +} diff --git a/lib/widgets/about/translators.dart b/lib/widgets/about/translators.dart new file mode 100644 index 0000000..6f935e2 --- /dev/null +++ b/lib/widgets/about/translators.dart @@ -0,0 +1,121 @@ +import 'dart:math'; + +import 'package:aves/model/app/contributors.dart'; +import 'package:aves/theme/text.dart'; +import 'package:aves/widgets/about/title.dart'; +import 'package:aves/widgets/common/basic/text/change_highlight.dart'; +import 'package:aves/widgets/common/extensions/build_context.dart'; +import 'package:collection/collection.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart'; + +class AboutTranslators extends StatelessWidget { + const AboutTranslators({super.key}); + + @override + Widget build(BuildContext context) { + return Padding( + padding: const EdgeInsets.symmetric(horizontal: 16), + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + AboutSectionTitle(text: context.l10n.aboutTranslatorsSectionTitle), + const SizedBox(height: 8), + buildBody(context), + const SizedBox(height: 16), + ], + ), + ); + } + + static Widget buildBody(BuildContext context) { + return _RandomTextSpanHighlighter( + spans: Contributors.translators.map((v) => v.name).toList(), + color: Theme.of(context).colorScheme.onSurface, + ); + } +} + +class _RandomTextSpanHighlighter extends StatefulWidget { + final List<String> spans; + final Color color; + + const _RandomTextSpanHighlighter({ + required this.spans, + required this.color, + }); + + @override + State<_RandomTextSpanHighlighter> createState() => _RandomTextSpanHighlighterState(); +} + +class _RandomTextSpanHighlighterState extends State<_RandomTextSpanHighlighter> with SingleTickerProviderStateMixin { + late final AnimationController _controller; + late final CurvedAnimation _animation; + late final Animation<TextStyle> _animatedStyle; + late final TextStyle _baseStyle; + int _highlightedIndex = 0; + + @override + void initState() { + super.initState(); + + final color = widget.color; + _baseStyle = TextStyle( + color: color.withValues(alpha: .7), + shadows: [ + Shadow( + color: color.withValues(alpha: 0), + blurRadius: 0, + ) + ], + ); + final highlightStyle = TextStyle( + color: color.withValues(alpha: 1), + shadows: [ + Shadow( + color: color.withValues(alpha: 1), + blurRadius: 3, + ) + ], + ); + + _controller = AnimationController( + duration: const Duration(seconds: 1), + vsync: this, + ) + ..addListener(() => setState(() {})) + ..addStatusListener((status) { + if (status == AnimationStatus.forward) { + _highlightedIndex = Random().nextInt(widget.spans.length); + } + }) + ..repeat(reverse: true); + _animation = CurvedAnimation( + parent: _controller, + curve: Curves.easeInOutCubic, + ); + _animatedStyle = ShadowedTextStyleTween(begin: _baseStyle, end: highlightStyle).animate(_animation); + } + + @override + void dispose() { + _animation.dispose(); + _controller.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return Text.rich( + TextSpan( + children: [ + ...widget.spans.expandIndexed((i, v) => [ + if (i != 0) const TextSpan(text: AText.separator), + TextSpan(text: '${Unicode.FSI}$v${Unicode.PDI}', style: i == _highlightedIndex ? _animatedStyle.value : _baseStyle), + ]) + ], + ), + ); + } +} diff --git a/lib/widgets/about/tv_license_page.dart b/lib/widgets/about/tv_license_page.dart new file mode 100644 index 0000000..7efb673 --- /dev/null +++ b/lib/widgets/about/tv_license_page.dart @@ -0,0 +1,396 @@ +import 'dart:developer' show Flow, Timeline; + +import 'package:aves/theme/themes.dart'; +import 'package:aves/widgets/common/basic/scaffold.dart'; +import 'package:aves/widgets/common/behaviour/intents.dart'; +import 'package:flutter/foundation.dart'; +import 'package:flutter/material.dart' hide Flow; +import 'package:flutter/scheduler.dart'; +import 'package:flutter/services.dart'; + +// as of Flutter v3.7.7, `LicensePage` is not designed for Android TV +// and gets rejected from Google Play review: +// ``` +// Your app’s text is cut off at the edge of the screen. +// Apps should not display any text or functionality that is partially cut off by the edges of the screen. +// For example, your app (version code 94) in the "Show All Licenses" section text is cut off from the bottom of the screen. +// ``` +class TvLicensePage extends StatefulWidget { + const TvLicensePage({super.key}); + + @override + State<TvLicensePage> createState() => _TvLicensePageState(); +} + +class _TvLicensePageState extends State<TvLicensePage> { + final FocusNode _railFocusNode = FocusNode(); + final ScrollController _detailsScrollController = ScrollController(); + final ValueNotifier<int> _railIndexNotifier = ValueNotifier(0); + + static const double railWidth = 256; + + final Future<_LicenseData> licenses = LicenseRegistry.licenses + .fold<_LicenseData>( + _LicenseData(), + (prev, license) => prev..addLicense(license), + ) + .then((licenseData) => licenseData..sortPackages()); + + @override + void dispose() { + _railIndexNotifier.dispose(); + _railFocusNode.dispose(); + _detailsScrollController.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return AvesScaffold( + appBar: AppBar( + automaticallyImplyLeading: false, + title: Text(MaterialLocalizations.of(context).licensesPageTitle), + ), + body: ValueListenableBuilder<int>( + valueListenable: _railIndexNotifier, + builder: (context, selectedIndex, child) { + return FutureBuilder<_LicenseData>( + future: licenses, + builder: (context, snapshot) { + final data = snapshot.data; + if (data == null) { + return const Center( + child: CircularProgressIndicator(), + ); + } + + final packages = data.packages; + final rail = Focus( + focusNode: _railFocusNode, + skipTraversal: true, + canRequestFocus: false, + child: ConstrainedBox( + constraints: BoxConstraints.loose(const Size.fromWidth(railWidth)), + child: ListView.builder( + itemBuilder: (context, index) { + final packageName = packages[index]; + final bindings = data.packageLicenseBindings[packageName]!; + final isSelected = index == selectedIndex; + final theme = Theme.of(context); + return Ink( + color: isSelected ? theme.highlightColor : Themes.firstLayerColor(context), + child: ListTile( + title: Text(packageName), + subtitle: Text(MaterialLocalizations.of(context).licensesPackageDetailText(bindings.length)), + selected: isSelected, + onTap: () => _railIndexNotifier.value = index, + ), + ); + }, + itemCount: packages.length, + ), + ), + ); + + final packageName = packages[selectedIndex]; + final bindings = data.packageLicenseBindings[packageName]!; + + return SafeArea( + child: Row( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const SizedBox(width: 16), + rail, + Expanded( + child: FocusableActionDetector( + shortcuts: const { + SingleActivator(LogicalKeyboardKey.arrowUp): ScrollIntent(direction: AxisDirection.up, type: ScrollIncrementType.page), + SingleActivator(LogicalKeyboardKey.arrowDown): ScrollIntent(direction: AxisDirection.down, type: ScrollIncrementType.page), + }, + actions: { + ScrollIntent: ScrollControllerAction(scrollController: _detailsScrollController), + }, + child: KeyedSubtree( + key: Key(packageName), + child: _PackageLicensePage( + packageName: packageName, + licenseEntries: bindings.map((i) => data.licenses[i]).toList(growable: false), + scrollController: _detailsScrollController, + ), + ), + ), + ), + ], + ), + ); + }, + ); + }, + ), + ); + } +} + +// adapted from Flutter `_LicenseData` in `/material/about.dart` +class _LicenseData { + final List<LicenseEntry> licenses = <LicenseEntry>[]; + final Map<String, List<int>> packageLicenseBindings = <String, List<int>>{}; + final List<String> packages = <String>[]; + + // Special treatment for the first package since it should be the package + // for delivered application. + String? firstPackage; + + void addLicense(LicenseEntry entry) { + // Before the license can be added, we must first record the packages to + // which it belongs. + for (final String package in entry.packages) { + _addPackage(package); + // Bind this license to the package using the next index value. This + // creates a contract that this license must be inserted at this same + // index value. + packageLicenseBindings[package]!.add(licenses.length); + } + licenses.add(entry); // Completion of the contract above. + } + + /// Add a package and initialize package license binding. This is a no-op if + /// the package has been seen before. + void _addPackage(String package) { + if (!packageLicenseBindings.containsKey(package)) { + packageLicenseBindings[package] = <int>[]; + firstPackage ??= package; + packages.add(package); + } + } + + /// Sort the packages using some comparison method, or by the default manner, + /// which is to put the application package first, followed by every other + /// package in case-insensitive alphabetical order. + void sortPackages([int Function(String a, String b)? compare]) { + packages.sort(compare ?? + (a, b) { + // Based on how LicenseRegistry currently behaves, the first package + // returned is the end user application license. This should be + // presented first in the list. So here we make sure that first package + // remains at the front regardless of alphabetical sorting. + if (a == firstPackage) { + return -1; + } + if (b == firstPackage) { + return 1; + } + return a.toLowerCase().compareTo(b.toLowerCase()); + }); + } +} + +// adapted from Flutter `_PackageLicensePage` in `/material/about.dart` +class _PackageLicensePage extends StatefulWidget { + const _PackageLicensePage({ + required this.packageName, + required this.licenseEntries, + required this.scrollController, + }); + + final String packageName; + final List<LicenseEntry> licenseEntries; + final ScrollController? scrollController; + + @override + _PackageLicensePageState createState() => _PackageLicensePageState(); +} + +class _PackageLicensePageState extends State<_PackageLicensePage> { + @override + void initState() { + super.initState(); + _initLicenses(); + } + + final List<Widget> _licenses = <Widget>[]; + bool _loaded = false; + + Future<void> _initLicenses() async { + int debugFlowId = -1; + assert(() { + final Flow flow = Flow.begin(); + Timeline.timeSync('_initLicenses()', () {}, flow: flow); + debugFlowId = flow.id; + return true; + }()); + for (final LicenseEntry license in widget.licenseEntries) { + if (!mounted) return; + assert(() { + Timeline.timeSync('_initLicenses()', () {}, flow: Flow.step(debugFlowId)); + return true; + }()); + final List<LicenseParagraph> paragraphs = await SchedulerBinding.instance.scheduleTask<List<LicenseParagraph>>( + license.paragraphs.toList, + Priority.animation, + debugLabel: 'License', + ); + if (!mounted) return; + setState(() { + _licenses.add(const Padding( + padding: EdgeInsets.all(18), + child: Divider(), + )); + for (final LicenseParagraph paragraph in paragraphs) { + if (paragraph.indent == LicenseParagraph.centeredIndent) { + _licenses.add(Padding( + padding: const EdgeInsets.only(top: 16), + child: Text( + paragraph.text, + style: const TextStyle(fontWeight: FontWeight.bold), + textAlign: TextAlign.center, + ), + )); + } else { + assert(paragraph.indent >= 0); + _licenses.add(Padding( + padding: EdgeInsetsDirectional.only(top: 8, start: 16.0 * paragraph.indent), + child: Text(paragraph.text), + )); + } + } + }); + } + setState(() { + _loaded = true; + }); + assert(() { + Timeline.timeSync('Build scheduled', () {}, flow: Flow.end(debugFlowId)); + return true; + }()); + } + + @override + Widget build(BuildContext context) { + assert(debugCheckHasMaterialLocalizations(context)); + final MaterialLocalizations localizations = MaterialLocalizations.of(context); + final ThemeData theme = Theme.of(context); + final String title = widget.packageName; + final String subtitle = localizations.licensesPackageDetailText(widget.licenseEntries.length); + final double pad = _getGutterSize(context); + final EdgeInsets padding = EdgeInsets.only(left: pad, right: pad, bottom: pad); + final List<Widget> listWidgets = <Widget>[ + ..._licenses, + if (!_loaded) + const Padding( + padding: EdgeInsets.symmetric(vertical: 24), + child: Center( + child: CircularProgressIndicator(), + ), + ), + ]; + + final Widget page; + if (widget.scrollController == null) { + page = Scaffold( + appBar: AppBar( + title: _PackageLicensePageTitle( + title: title, + subtitle: subtitle, + theme: theme.useMaterial3 ? theme.textTheme : theme.primaryTextTheme, + titleTextStyle: theme.appBarTheme.titleTextStyle, + foregroundColor: theme.appBarTheme.foregroundColor, + ), + ), + body: Center( + child: Material( + color: Themes.firstLayerColor(context), + elevation: 4.0, + child: Container( + constraints: BoxConstraints.loose(const Size.fromWidth(600.0)), + child: Localizations.override( + locale: const Locale('en', 'US'), + context: context, + child: ScrollConfiguration( + // A Scrollbar is built-in below. + behavior: ScrollConfiguration.of(context).copyWith(scrollbars: false), + child: Scrollbar( + child: ListView( + primary: true, + padding: padding, + children: listWidgets, + ), + ), + ), + ), + ), + ), + ), + ); + } else { + page = CustomScrollView( + controller: widget.scrollController, + slivers: <Widget>[ + SliverAppBar( + automaticallyImplyLeading: false, + pinned: true, + backgroundColor: Themes.firstLayerColor(context), + title: _PackageLicensePageTitle( + title: title, + subtitle: subtitle, + theme: theme.textTheme, + titleTextStyle: theme.textTheme.titleLarge, + ), + ), + SliverPadding( + padding: padding, + sliver: SliverList( + delegate: SliverChildBuilderDelegate( + (context, index) => Localizations.override( + locale: const Locale('en', 'US'), + context: context, + child: listWidgets[index], + ), + childCount: listWidgets.length, + ), + ), + ), + ], + ); + } + return DefaultTextStyle( + style: theme.textTheme.bodySmall!, + child: page, + ); + } +} + +class _PackageLicensePageTitle extends StatelessWidget { + const _PackageLicensePageTitle({ + required this.title, + required this.subtitle, + required this.theme, + this.titleTextStyle, + this.foregroundColor, + }); + + final String title; + final String subtitle; + final TextTheme theme; + final TextStyle? titleTextStyle; + final Color? foregroundColor; + + @override + Widget build(BuildContext context) { + final TextStyle? effectiveTitleTextStyle = titleTextStyle ?? theme.titleLarge; + return Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: <Widget>[ + Text(title, style: effectiveTitleTextStyle?.copyWith(color: foregroundColor)), + Text(subtitle, style: theme.titleSmall?.copyWith(color: foregroundColor)), + ], + ); + } +} + +const int _materialGutterThreshold = 720; +const double _wideGutterSize = 24.0; +const double _narrowGutterSize = 12.0; + +double _getGutterSize(BuildContext context) => MediaQuery.sizeOf(context).width >= _materialGutterThreshold ? _wideGutterSize : _narrowGutterSize; |
