diff options
Diffstat (limited to 'lib/widgets/common/identity')
| -rw-r--r-- | lib/widgets/common/identity/aves_app_bar.dart | 293 | ||||
| -rw-r--r-- | lib/widgets/common/identity/aves_caption.dart | 42 | ||||
| -rw-r--r-- | lib/widgets/common/identity/aves_donut.dart | 201 | ||||
| -rw-r--r-- | lib/widgets/common/identity/aves_expansion_tile.dart | 74 | ||||
| -rw-r--r-- | lib/widgets/common/identity/aves_fab.dart | 27 | ||||
| -rw-r--r-- | lib/widgets/common/identity/aves_filter_chip.dart | 426 | ||||
| -rw-r--r-- | lib/widgets/common/identity/aves_icons.dart | 363 | ||||
| -rw-r--r-- | lib/widgets/common/identity/aves_logo.dart | 148 | ||||
| -rw-r--r-- | lib/widgets/common/identity/buttons/captioned_button.dart | 184 | ||||
| -rw-r--r-- | lib/widgets/common/identity/buttons/outlined_button.dart | 43 | ||||
| -rw-r--r-- | lib/widgets/common/identity/buttons/overlay_button.dart | 191 | ||||
| -rw-r--r-- | lib/widgets/common/identity/empty.dart | 74 | ||||
| -rw-r--r-- | lib/widgets/common/identity/highlight_title.dart | 74 | ||||
| -rw-r--r-- | lib/widgets/common/identity/scroll_thumb.dart | 47 |
14 files changed, 2187 insertions, 0 deletions
diff --git a/lib/widgets/common/identity/aves_app_bar.dart b/lib/widgets/common/identity/aves_app_bar.dart new file mode 100644 index 0000000..fc388b9 --- /dev/null +++ b/lib/widgets/common/identity/aves_app_bar.dart @@ -0,0 +1,293 @@ +import 'dart:async'; +import 'dart:math'; + +import 'package:aves/model/settings/settings.dart'; +import 'package:aves/theme/durations.dart'; +import 'package:aves/theme/themes.dart'; +import 'package:aves/widgets/aves_app.dart'; +import 'package:aves/widgets/common/basic/font_size_icon_theme.dart'; +import 'package:aves/widgets/common/basic/gestures/ink_well.dart'; +import 'package:aves/widgets/common/basic/insets.dart'; +import 'package:aves/widgets/common/fx/blurred.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +class AvesAppBar extends StatelessWidget { + final double contentHeight; + final bool pinned; + final Widget? leading; + final Widget title; + final List<Widget> Function(BuildContext context, double maxWidth) actions; + final Widget? bottom; + final Object? transitionKey; + + static const leadingHeroTag = 'appbar-leading'; + static const titleHeroTag = 'appbar-title'; + static const double _titleMinWidth = 96; + + const AvesAppBar({ + super.key, + required this.contentHeight, + required this.pinned, + required this.leading, + required this.title, + required this.actions, + this.bottom, + this.transitionKey, + }); + + @override + Widget build(BuildContext context) { + final theme = Theme.of(context); + final colorScheme = theme.colorScheme; + final textScaler = MediaQuery.textScalerOf(context); + final useTvLayout = settings.useTvLayout; + + Widget? _leading = leading; + if (_leading != null) { + _leading = FontSizeIconTheme( + child: _leading, + ); + } + + Widget _title = FontSizeIconTheme( + child: LayoutBuilder( + builder: (context, constraints) { + return Row( + key: ValueKey(transitionKey), + children: [ + Expanded(child: title), + ...(actions(context, max(0, constraints.maxWidth - _titleMinWidth))), + ], + ); + }, + ), + ); + + final animate = context.select<Settings, bool>((v) => v.animate); + if (animate) { + _title = Hero( + tag: titleHeroTag, + flightShuttleBuilder: _flightShuttleBuilder, + transitionOnUserGestures: true, + child: AnimatedSwitcher( + duration: context.read<DurationsData>().iconAnimation, + child: _title, + ), + ); + + if (_leading != null) { + _leading = Hero( + tag: leadingHeroTag, + flightShuttleBuilder: _flightShuttleBuilder, + transitionOnUserGestures: true, + child: _leading, + ); + } + } + + return SliverPersistentHeader( + floating: !useTvLayout, + pinned: pinned, + delegate: _SliverAppBarDelegate( + height: MediaQuery.paddingOf(context).top + appBarHeightForContentHeight(contentHeight), + child: DirectionalSafeArea( + start: !useTvLayout, + bottom: false, + child: AvesFloatingBar( + builder: (context, backgroundColor, child) => Material( + color: backgroundColor, + child: AInkResponse( + // absorb taps while providing visual feedback + onTap: () {}, + onLongPress: () {}, + containedInkWell: true, + highlightShape: BoxShape.rectangle, + longPressTimeout: settings.longPressTimeout, + child: child, + ), + ), + child: Theme( + data: theme.copyWith( + colorScheme: colorScheme.copyWith( + onSurfaceVariant: colorScheme.onSurface, + ), + ), + child: Column( + children: [ + SizedBox( + height: textScaler.scale(kToolbarHeight), + child: Row( + children: [ + _leading != null + ? Padding( + padding: const EdgeInsets.symmetric(horizontal: 4), + child: _leading, + ) + : const SizedBox(width: 16), + Expanded( + child: DefaultTextStyle( + style: theme.appBarTheme.titleTextStyle!, + child: _title, + ), + ), + ], + ), + ), + if (bottom != null) bottom!, + ], + ), + ), + ), + ), + ), + ); + } + + static Widget _flightShuttleBuilder( + BuildContext flightContext, + Animation<double> animation, + HeroFlightDirection flightDirection, + BuildContext fromHeroContext, + BuildContext toHeroContext, + ) { + final pushing = flightDirection == HeroFlightDirection.push; + Widget popBuilder(context, child) => Opacity(opacity: 1 - animation.value, child: child); + Widget pushBuilder(context, child) => Opacity(opacity: animation.value, child: child); + return Material( + type: MaterialType.transparency, + child: DefaultTextStyle( + style: DefaultTextStyle.of(toHeroContext).style, + child: Stack( + children: [ + AnimatedBuilder( + animation: animation, + builder: pushing ? popBuilder : pushBuilder, + child: fromHeroContext.widget, + ), + AnimatedBuilder( + animation: animation, + builder: pushing ? pushBuilder : popBuilder, + child: toHeroContext.widget, + ), + ], + ), + ), + ); + } + + static double appBarHeightForContentHeight(double contentHeight) => AvesFloatingBar.margin.vertical + contentHeight; +} + +class _SliverAppBarDelegate extends SliverPersistentHeaderDelegate { + final double height; + final Widget child; + + const _SliverAppBarDelegate({ + required this.height, + required this.child, + }); + + @override + double get minExtent => height; + + @override + double get maxExtent => height; + + @override + Widget build(BuildContext context, double shrinkOffset, bool overlapsContent) => child; + + @override + bool shouldRebuild(covariant _SliverAppBarDelegate oldDelegate) => true; +} + +class AvesFloatingBar extends StatefulWidget { + final Widget Function(BuildContext context, Color backgroundColor, Widget? child) builder; + final Widget? child; + + static const margin = EdgeInsets.all(8); + static const borderRadius = BorderRadius.all(Radius.circular(8)); + + const AvesFloatingBar({ + super.key, + required this.builder, + this.child, + }); + + @override + State<AvesFloatingBar> createState() => _AvesFloatingBarState(); +} + +class _AvesFloatingBarState extends State<AvesFloatingBar> with RouteAware { + // prevent expensive blurring when the current page is hidden + final ValueNotifier<bool> _isBlurAllowedNotifier = ValueNotifier(true); + Timer? _blurBlockTimer; + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + final route = ModalRoute.of(context); + if (route is PageRoute) { + AvesApp.pageRouteObserver.subscribe(this, route); + } + } + + @override + void dispose() { + AvesApp.pageRouteObserver.unsubscribe(this); + _isBlurAllowedNotifier.dispose(); + super.dispose(); + } + + @override + void didPopNext() { + // post to prevent single frame flash during hero + _blurBlockTimer?.cancel(); + _blurBlockTimer = null; + WidgetsBinding.instance.addPostFrameCallback((_) { + if (!mounted) return; + _isBlurAllowedNotifier.value = true; + }); + } + + @override + void didPushNext() { + // delay blur disabling, otherwise visual artifacts appear during page transition with Impeller + _blurBlockTimer?.cancel(); + _blurBlockTimer = Timer(ADurations.pageTransitionLoose, () { + if (mounted) { + _isBlurAllowedNotifier.value = false; + } + }); + } + + @override + Widget build(BuildContext context) { + final theme = Theme.of(context); + final backgroundColor = theme.appBarTheme.backgroundColor ?? Themes.firstLayerColor(context); + return ValueListenableBuilder<bool>( + valueListenable: _isBlurAllowedNotifier, + builder: (context, isBlurAllowed, child) { + final blurred = isBlurAllowed && context.select<Settings, bool>((v) => v.enableBlurEffect); + return Container( + foregroundDecoration: BoxDecoration( + border: Border.all( + color: theme.dividerColor, + ), + borderRadius: AvesFloatingBar.borderRadius, + ), + margin: AvesFloatingBar.margin, + child: BlurredRRect( + enabled: blurred, + borderRadius: AvesFloatingBar.borderRadius, + child: widget.builder( + context, + blurred ? backgroundColor.withValues(alpha: .85) : backgroundColor, + widget.child, + ), + ), + ); + }, + ); + } +} diff --git a/lib/widgets/common/identity/aves_caption.dart b/lib/widgets/common/identity/aves_caption.dart new file mode 100644 index 0000000..a47c1ae --- /dev/null +++ b/lib/widgets/common/identity/aves_caption.dart @@ -0,0 +1,42 @@ +import 'package:aves/theme/durations.dart'; +import 'package:aves/widgets/common/basic/text/change_highlight.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +class AvesCaption extends StatelessWidget { + final String data; + + const AvesCaption( + this.data, { + super.key, + }); + + @override + Widget build(BuildContext context) { + final theme = Theme.of(context); + final subtitleStyle = theme.textTheme.bodySmall!; + final subtitleChangeShadowColor = theme.colorScheme.onSurface; + return ChangeHighlightText( + // provide key to refresh on theme brightness change + key: ValueKey(subtitleChangeShadowColor), + data, + style: subtitleStyle.copyWith( + shadows: [ + Shadow( + color: subtitleChangeShadowColor.withAlpha(0), + blurRadius: 0, + ) + ], + ), + changedStyle: subtitleStyle.copyWith( + shadows: [ + Shadow( + color: subtitleChangeShadowColor, + blurRadius: 3, + ) + ], + ), + duration: context.read<DurationsData>().formTextStyleTransition, + ); + } +} diff --git a/lib/widgets/common/identity/aves_donut.dart b/lib/widgets/common/identity/aves_donut.dart new file mode 100644 index 0000000..3ad6bc7 --- /dev/null +++ b/lib/widgets/common/identity/aves_donut.dart @@ -0,0 +1,201 @@ +import 'dart:math'; + +import 'package:aves/model/settings/settings.dart'; +import 'package:aves/theme/colors.dart'; +import 'package:aves/theme/icons.dart'; +import 'package:aves/theme/themes.dart'; +import 'package:charts_flutter/flutter.dart' as charts; +import 'package:collection/collection.dart'; +import 'package:equatable/equatable.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +typedef DatumKeyFormatter = String Function(AvesDonutDatum d); +typedef DatumValueFormatter = String Function(int d); +typedef DatumColorizer = Color Function(BuildContext context, AvesDonutDatum d); +typedef DatumCallback = void Function(AvesDonutDatum d); + +class AvesDonut extends StatefulWidget { + final Widget title; + final Map<String, int> byTypes; + final Duration animationDuration; + final DatumKeyFormatter formatKey; + final DatumValueFormatter formatValue; + final DatumColorizer colorize; + final DatumCallback? onTap; + + const AvesDonut({ + super.key, + required this.title, + required this.byTypes, + required this.animationDuration, + required this.formatKey, + required this.formatValue, + required this.colorize, + this.onTap, + }); + + @override + State<AvesDonut> createState() => _AvesDonutState(); +} + +class _AvesDonutState extends State<AvesDonut> with AutomaticKeepAliveClientMixin { + Map<String, int> get byTypes => widget.byTypes; + + DatumKeyFormatter get formatKey => widget.formatKey; + + DatumValueFormatter get formatValue => widget.formatValue; + + DatumColorizer get colorize => widget.colorize; + + static const avesDonutMinWidth = 124.0; + + @override + Widget build(BuildContext context) { + super.build(context); + + if (byTypes.isEmpty) return const SizedBox(); + + final sum = byTypes.values.sum; + + final seriesData = byTypes.entries.map((kv) { + final type = kv.key; + return AvesDonutDatum( + key: type, + value: kv.value, + ); + }).toList(); + seriesData.sort((d1, d2) { + final c = d2.value.compareTo(d1.value); + return c != 0 ? c : compareAsciiUpperCase(formatKey(d1), formatKey(d2)); + }); + + return AvesColorsProvider( + allowMonochrome: false, + child: LayoutBuilder( + builder: (context, constraints) { + final series = [ + charts.Series<AvesDonutDatum, String>( + id: 'type', + colorFn: (d, i) => charts.ColorUtil.fromDartColor(colorize(context, d)), + domainFn: (d, i) => formatKey(d), + measureFn: (d, i) => d.value, + data: seriesData, + labelAccessorFn: (d, _) => '${formatKey(d)}: ${d.value}', + ), + ]; + + final textScaler = MediaQuery.textScalerOf(context); + final minWidth = textScaler.scale(avesDonutMinWidth); + final availableWidth = constraints.maxWidth; + final dim = max(minWidth, availableWidth / (availableWidth > 4 * minWidth ? 4 : (availableWidth > 2 * minWidth ? 2 : 1))); + + final donut = SizedBox( + width: dim, + height: dim, + child: Stack( + alignment: Alignment.center, + children: [ + ClipRRect( + borderRadius: BorderRadius.all(Radius.circular(dim)), + child: Container( + width: dim * .7, + height: dim * .7, + color: Themes.secondLayerColor(context), + ), + ), + charts.PieChart( + series, + animate: context.select<Settings, bool>((v) => v.animate), + animationDuration: widget.animationDuration, + defaultRenderer: charts.ArcRendererConfig<String>( + arcWidth: 16, + ), + ), + Center( + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + widget.title, + Text( + formatValue(sum), + textAlign: TextAlign.center, + ), + ], + ), + ), + ], + ), + ); + final onTap = widget.onTap; + final legend = SizedBox( + width: dim, + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + crossAxisAlignment: CrossAxisAlignment.start, + children: seriesData + .map((d) => InkWell( + onTap: onTap != null ? () => onTap(d) : null, + borderRadius: const BorderRadius.all(Radius.circular(123)), + child: Row( + mainAxisSize: MainAxisSize.min, + children: [ + Icon(AIcons.circle, fill: 1, color: colorize(context, d)), + const SizedBox(width: 8), + Flexible( + child: Text( + formatKey(d), + overflow: TextOverflow.fade, + softWrap: false, + maxLines: 1, + ), + ), + const SizedBox(width: 8), + Text( + formatValue(d.value), + style: TextStyle( + color: Theme.of(context).colorScheme.onSurfaceVariant, + ), + ), + const SizedBox(width: 4), + ], + ), + )) + .toList(), + ), + ); + final children = [ + donut, + legend, + ]; + return availableWidth > minWidth * 2 + ? Row( + mainAxisSize: MainAxisSize.min, + children: children, + ) + : Column( + mainAxisSize: MainAxisSize.min, + children: children, + ); + }, + ), + ); + } + + @override + bool get wantKeepAlive => true; +} + +@immutable +class AvesDonutDatum extends Equatable { + final String key; + final int value; + + @override + List<Object?> get props => [key, value]; + + const AvesDonutDatum({ + required this.key, + required this.value, + }); +} diff --git a/lib/widgets/common/identity/aves_expansion_tile.dart b/lib/widgets/common/identity/aves_expansion_tile.dart new file mode 100644 index 0000000..ad856f6 --- /dev/null +++ b/lib/widgets/common/identity/aves_expansion_tile.dart @@ -0,0 +1,74 @@ +import 'package:aves/theme/durations.dart'; +import 'package:aves/theme/themes.dart'; +import 'package:aves/widgets/common/identity/highlight_title.dart'; +import 'package:expansion_tile_card/expansion_tile_card.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +class AvesExpansionTile extends StatelessWidget { + final String value; + final Widget? leading; + final String title; + final Color? highlightColor; + final ValueNotifier<String?>? expandedNotifier; + final bool initiallyExpanded, showHighlight; + final List<Widget> children; + + const AvesExpansionTile({ + super.key, + String? value, + this.leading, + required this.title, + this.highlightColor, + this.expandedNotifier, + this.initiallyExpanded = false, + this.showHighlight = true, + required this.children, + }) : value = value ?? title; + + @override + Widget build(BuildContext context) { + final enabled = children.isNotEmpty == true; + Widget titleChild = HighlightTitle( + title: title, + color: highlightColor, + enabled: enabled, + showHighlight: showHighlight, + ); + if (leading != null) { + titleChild = Row( + children: [ + leading!, + const SizedBox(width: 8), + Expanded(child: titleChild), + ], + ); + } + + final animationDuration = context.select<DurationsData, Duration>((v) => v.expansionTileAnimation); + final theme = Theme.of(context); + final colorScheme = theme.colorScheme; + return ExpansionTileCard( + // key is expected by test driver + key: Key('tilecard-$value'), + value: value, + expandedNotifier: expandedNotifier, + title: titleChild, + expandable: enabled, + initiallyExpanded: initiallyExpanded, + finalPadding: const EdgeInsets.symmetric(vertical: 6.0), + baseColor: Themes.firstLayerColor(context), + expandedTextColor: colorScheme.onSurface, + duration: animationDuration, + shadowColor: theme.shadowColor, + child: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const Divider(thickness: 1, height: 1), + const SizedBox(height: 4), + if (enabled) ...children, + ], + ), + ); + } +} diff --git a/lib/widgets/common/identity/aves_fab.dart b/lib/widgets/common/identity/aves_fab.dart new file mode 100644 index 0000000..2c943ca --- /dev/null +++ b/lib/widgets/common/identity/aves_fab.dart @@ -0,0 +1,27 @@ +import 'package:aves/theme/icons.dart'; +import 'package:flutter/material.dart'; + +class AvesFab extends StatelessWidget { + final String tooltip; + final VoidCallback onPressed; + + const AvesFab({ + super.key, + required this.tooltip, + required this.onPressed, + }); + + @override + Widget build(BuildContext context) { + return TooltipTheme( + data: TooltipTheme.of(context).copyWith( + preferBelow: false, + ), + child: FloatingActionButton( + tooltip: tooltip, + onPressed: onPressed, + child: const Icon(AIcons.apply), + ), + ); + } +} diff --git a/lib/widgets/common/identity/aves_filter_chip.dart b/lib/widgets/common/identity/aves_filter_chip.dart new file mode 100644 index 0000000..1bbe9f2 --- /dev/null +++ b/lib/widgets/common/identity/aves_filter_chip.dart @@ -0,0 +1,426 @@ +import 'dart:async'; +import 'dart:math'; + +import 'package:aves/app_mode.dart'; +import 'package:aves/model/covers.dart'; +import 'package:aves/model/filters/filters.dart'; +import 'package:aves/model/filters/rating.dart'; +import 'package:aves/model/settings/enums/accessibility_animations.dart'; +import 'package:aves/model/settings/settings.dart'; +import 'package:aves/theme/colors.dart'; +import 'package:aves/theme/icons.dart'; +import 'package:aves/theme/themes.dart'; +import 'package:aves/view/view.dart'; +import 'package:aves/widgets/collection/filter_bar.dart'; +import 'package:aves/widgets/common/basic/font_size_icon_theme.dart'; +import 'package:aves/widgets/common/basic/gestures/ink_well.dart'; +import 'package:aves/widgets/common/basic/popup/menu_row.dart'; +import 'package:aves/widgets/common/extensions/build_context.dart'; +import 'package:aves/widgets/common/providers/media_query_data_provider.dart'; +import 'package:aves/widgets/filter_grids/common/action_delegates/chip.dart'; +import 'package:aves_model/aves_model.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:provider/provider.dart'; + +typedef AFilterCallback<T extends CollectionFilter> = void Function(T filter); +typedef OffsetFilterCallback<T extends CollectionFilter> = void Function(BuildContext context, T filter, Offset tapPosition); + +enum HeroType { always, onTap, never } + +@immutable +class AvesFilterDecoration { + final Radius radius; + final Widget widget; + + const AvesFilterDecoration({ + required this.radius, + required this.widget, + }); + + BorderRadius get textBorderRadius => BorderRadius.vertical(bottom: radius); + + BorderRadius get chipBorderRadius => BorderRadius.all(radius); +} + +class AvesFilterChip extends StatefulWidget { + final CollectionFilter filter; + final bool showLeading, showText, allowGenericIcon, useFilterColor; + final AvesFilterDecoration? decoration; + final Color? background; + final String? banner; + final Widget? leadingOverride, details; + final double padding; + final double? maxWidth; + final HeroType heroType; + final AFilterCallback? onTap, onRemove; + final OffsetFilterCallback? onLongPress; + + static const double defaultPadding = 6.0; + static const double defaultRadius = 32; + static const double outlineWidth = 2; + static const double minChipHeight = kMinInteractiveDimension; + static const double minChipWidth = kMinInteractiveDimension; + static const double iconSize = 18; + static const double fontSize = 14; + static const double decoratedContentVerticalPadding = 5; + + const AvesFilterChip({ + super.key, + required this.filter, + this.showLeading = true, + this.showText = true, + this.allowGenericIcon = true, + this.useFilterColor = true, + this.decoration, + this.background, + this.banner, + this.leadingOverride, + this.details, + this.padding = defaultPadding, + this.maxWidth, + this.heroType = HeroType.onTap, + this.onTap, + this.onRemove, + this.onLongPress = showDefaultLongPressMenu, + }); + + static double computeMaxWidthForRow( + BuildContext context, { + required int minChipPerRow, + required double chipPadding, + required double rowPadding, + }) { + final mqWidth = MediaQuery.sizeOf(context).width; + final mqHorizontalPadding = MediaQuery.paddingOf(context).horizontal; + return (mqWidth - mqHorizontalPadding - chipPadding * minChipPerRow - rowPadding) / minChipPerRow; + } + + static Future<void> showDefaultLongPressMenu(BuildContext context, CollectionFilter filter, Offset tapPosition) async { + if (context.read<ValueNotifier<AppMode>>().value.canNavigate) { + // remove focus, if any, to prevent the keyboard from showing up + // after the user is done with the popup menu + FocusManager.instance.primaryFocus?.unfocus(); + + final overlay = Overlay.of(context).context.findRenderObject() as RenderBox; + const touchArea = Size(kMinInteractiveDimension, kMinInteractiveDimension); + final actionDelegate = ChipActionDelegate(); + final animations = context.read<Settings>().accessibilityAnimations; + + final selectedAction = await showMenu<ChipAction>( + context: context, + position: RelativeRect.fromRect(tapPosition & touchArea, Offset.zero & overlay.size), + items: [ + PopupMenuItem( + child: Text(filter.getTooltip(context)), + ), + const PopupMenuDivider(), + ...ChipAction.values.where((action) => actionDelegate.isVisible(action, filter: filter)).map((action) { + late String text; + switch (action) { + case ChipAction.reverse: + text = filter.reversed ? context.l10n.chipActionFilterIn : context.l10n.chipActionFilterOut; + case ChipAction.ratingOrGreater: + text = RatingFilter.formatRatingRange(context, (filter as RatingFilter).rating, RatingFilter.opOrGreater); + case ChipAction.ratingOrLower: + text = RatingFilter.formatRatingRange(context, (filter as RatingFilter).rating, RatingFilter.opOrLower); + default: + text = action.getText(context); + } + return PopupMenuItem( + value: action, + child: FontSizeIconTheme( + child: MenuRow(text: text, icon: action.getIcon()), + ), + ); + }), + ], + popUpAnimationStyle: animations.popUpAnimationStyle, + ); + if (selectedAction != null) { + // wait for the popup menu to hide before proceeding with the action + await Future.delayed(animations.popUpAnimationDelay * timeDilation); + actionDelegate.onActionSelected(context, filter, selectedAction); + } + } + } + + @override + State<AvesFilterChip> createState() => _AvesFilterChipState(); +} + +class _AvesFilterChipState extends State<AvesFilterChip> { + final Set<StreamSubscription> _subscriptions = {}; + late Future<Color> _colorFuture; + late Color _outlineColor; + late bool _tapped; + Offset? _tapPosition; + + CollectionFilter get filter => widget.filter; + + double get padding => widget.padding; + + @override + void initState() { + super.initState(); + _tapped = false; + _subscriptions.add(covers.packageChangeStream.listen(_onCoverColorChanged)); + _subscriptions.add(covers.colorChangeStream.listen(_onCoverColorChanged)); + _subscriptions.add(settings.updateStream.where((event) => event.key == SettingKeys.themeColorModeKey).listen((_) { + // delay so that contextual colors reflect the new settings + WidgetsBinding.instance.addPostFrameCallback((_) { + if (!mounted) return; + _onCoverColorChanged(null); + }); + })); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _initColorLoader(); + } + + @override + void didUpdateWidget(covariant AvesFilterChip oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.filter != filter) { + _initColorLoader(); + _tapped = false; + } + } + + @override + void dispose() { + _subscriptions + ..forEach((sub) => sub.cancel()) + ..clear(); + super.dispose(); + } + + void _initColorLoader() { + // For app albums, `filter.color` yields a regular async `Future` the first time + // but it yields a `SynchronousFuture` when called again on a known album. + // This works fine to avoid a frame with no Future data, for new widgets. + // However, when the user moves away and back to a page with a chip using the async future, + // the existing widget FutureBuilder cycles again from the start, with a frame in `waiting` state and no data. + // So we save the result of the Future to a local variable because of this specific case. + _colorFuture = filter.color(context); + _outlineColor = context.read<AvesColorsData>().neutral; + } + + void _onCoverColorChanged(Set<CollectionFilter>? event) { + if (event == null || event.contains(filter)) { + _initColorLoader(); + setState(() {}); + } + } + + @override + Widget build(BuildContext context) { + final decoration = widget.decoration; + final chipBackground = widget.background ?? Themes.firstLayerColor(context); + + final onTap = widget.onTap != null + ? () { + WidgetsBinding.instance.addPostFrameCallback((_) => widget.onTap?.call(filter)); + setState(() => _tapped = true); + } + : null; + final onRemove = widget.onRemove != null + ? () { + WidgetsBinding.instance.addPostFrameCallback((_) => widget.onRemove?.call(filter)); + setState(() => _tapped = true); + } + : null; + final onLongPress = widget.onLongPress != null + ? Feedback.wrapForLongPress(() { + if (_tapPosition != null) { + widget.onLongPress?.call(context, filter, _tapPosition!); + } + }, context) + : null; + + Widget? content; + final showLeading = widget.showLeading; + final showText = widget.showText; + if (showLeading || showText) { + final textScaler = MediaQuery.textScalerOf(context); + final iconSize = textScaler.scale(AvesFilterChip.iconSize); + final leading = showLeading ? widget.leadingOverride ?? filter.iconBuilder(context, iconSize, allowGenericIcon: widget.allowGenericIcon) : null; + final trailing = onRemove != null + ? Theme( + data: Theme.of(context).copyWith( + materialTapTargetSize: MaterialTapTargetSize.shrinkWrap, + ), + child: IconButton( + icon: Icon(AIcons.clear, size: iconSize), + padding: EdgeInsets.zero, + splashRadius: IconTheme.of(context).size, + constraints: const BoxConstraints(), + onPressed: onRemove, + ), + ) + : null; + + content = Row( + mainAxisSize: decoration != null ? MainAxisSize.max : MainAxisSize.min, + mainAxisAlignment: MainAxisAlignment.center, + children: [ + if (leading != null) leading, + if (leading != null && showText) SizedBox(width: padding), + if (showText) + Flexible( + child: Text( + filter.getLabel(context), + style: TextStyle( + fontSize: AvesFilterChip.fontSize, + decoration: filter.reversed ? TextDecoration.lineThrough : null, + decorationThickness: 2, + ), + softWrap: false, + overflow: TextOverflow.fade, + ), + ), + if (trailing != null) ...[ + SizedBox(width: padding), + trailing, + ], + ], + ); + + final details = widget.details; + if (details != null) { + content = Column( + mainAxisSize: MainAxisSize.min, + children: [ + content, + Flexible(child: details), + ], + ); + } + + if (decoration != null) { + content = Align( + alignment: Alignment.bottomCenter, + child: ClipRRect( + borderRadius: decoration.textBorderRadius, + child: Container( + padding: EdgeInsets.symmetric(horizontal: padding * 2, vertical: AvesFilterChip.decoratedContentVerticalPadding), + color: chipBackground, + child: content, + ), + ), + ); + } else { + content = Padding( + padding: EdgeInsets.symmetric(horizontal: padding * 2), + child: content, + ); + } + } + + final borderRadius = decoration?.chipBorderRadius ?? const BorderRadius.all(Radius.circular(AvesFilterChip.defaultRadius)); + final banner = widget.banner; + Widget chip = Container( + constraints: BoxConstraints( + minWidth: AvesFilterChip.minChipWidth, + maxWidth: max( + AvesFilterChip.minChipWidth, + widget.maxWidth ?? + AvesFilterChip.computeMaxWidthForRow( + context, + minChipPerRow: 2, + chipPadding: FilterBar.chipPadding.horizontal, + rowPadding: FilterBar.rowPadding.horizontal, + )), + minHeight: AvesFilterChip.minChipHeight, + ), + child: Stack( + fit: StackFit.passthrough, + children: [ + if (decoration != null) + ClipRRect( + borderRadius: decoration.chipBorderRadius, + child: decoration.widget, + ), + Material( + color: decoration != null ? Colors.transparent : chipBackground, + shape: RoundedRectangleBorder( + borderRadius: borderRadius, + ), + child: AInkResponse( + // as of Flutter v2.8.0, `InkWell` does not have `onLongPressStart` like `GestureDetector`, + // so we get the long press details from the tap instead + onTapDown: onLongPress != null ? (details) => _tapPosition = details.globalPosition : null, + onTap: onTap, + onLongPress: onLongPress, + containedInkWell: true, + highlightShape: BoxShape.rectangle, + borderRadius: borderRadius, + longPressTimeout: settings.longPressTimeout, + child: FutureBuilder<Color>( + future: _colorFuture, + builder: (context, snapshot) { + if (snapshot.hasData) { + _outlineColor = snapshot.data!; + } + return DecoratedBox( + decoration: BoxDecoration( + border: Border.fromBorderSide(BorderSide( + color: widget.useFilterColor ? _outlineColor : context.select<AvesColorsData, Color>((v) => v.neutral), + width: AvesFilterChip.outlineWidth, + )), + borderRadius: borderRadius, + ), + position: DecorationPosition.foreground, + child: content, + ); + }, + ), + ), + ), + if (banner != null) + LayoutBuilder( + builder: (context, constraints) { + return ClipRRect( + borderRadius: borderRadius, + child: Align( + // align to corner the scaled down banner in RTL + alignment: AlignmentDirectional.topStart, + child: Transform( + transform: Matrix4.identity().scaled((constraints.maxHeight / 90 - .4).clamp(.45, 1.0)), + child: Banner( + message: banner.toUpperCase(), + location: BannerLocation.topStart, + color: Theme.of(context).colorScheme.primary, + child: const SizedBox(), + ), + ), + ), + ); + }, + ), + ], + ), + ); + + final animate = context.select<Settings, bool>((v) => v.animate); + if (animate) { + final heroType = widget.heroType; + if (heroType == HeroType.always || (heroType == HeroType.onTap && _tapped)) { + chip = Hero( + tag: filter, + transitionOnUserGestures: true, + child: MediaQueryDataProvider( + child: DefaultTextStyle( + style: const TextStyle(), + child: chip, + ), + ), + ); + } + } + return chip; + } +} diff --git a/lib/widgets/common/identity/aves_icons.dart b/lib/widgets/common/identity/aves_icons.dart new file mode 100644 index 0000000..3f67d63 --- /dev/null +++ b/lib/widgets/common/identity/aves_icons.dart @@ -0,0 +1,363 @@ +import 'package:aves/image_providers/app_icon_image_provider.dart'; +import 'package:aves/model/covers.dart'; +import 'package:aves/model/entry/entry.dart'; +import 'package:aves/model/entry/extensions/multipage.dart'; +import 'package:aves/model/entry/extensions/props.dart'; +import 'package:aves/model/vaults/vaults.dart'; +import 'package:aves/theme/icons.dart'; +import 'package:aves/widgets/common/extensions/build_context.dart'; +import 'package:aves/widgets/common/extensions/theme.dart'; +import 'package:aves/widgets/common/grid/theme.dart'; +import 'package:aves_model/aves_model.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +class VideoIcon extends StatelessWidget { + final AvesEntry entry; + + const VideoIcon({ + super.key, + required this.entry, + }); + + @override + Widget build(BuildContext context) { + final gridTheme = context.watch<GridThemeData>(); + final showDuration = gridTheme.showVideoDuration; + Widget child = OverlayIcon( + icon: entry.is360 ? AIcons.sphericalVideo : AIcons.videoPlay, + text: showDuration ? entry.durationText : null, + iconScale: entry.is360 && showDuration ? .9 : 1, + ); + if (showDuration) { + child = DefaultTextStyle( + style: TextStyle( + fontSize: gridTheme.fontSize, + ), + child: child, + ); + } + return child; + } +} + +class AnimatedImageIcon extends StatelessWidget { + const AnimatedImageIcon({super.key}); + + static const scale = .8; + + @override + Widget build(BuildContext context) { + return const OverlayIcon( + icon: AIcons.animated, + iconScale: scale, + ); + } +} + +class GeoTiffIcon extends StatelessWidget { + const GeoTiffIcon({super.key}); + + @override + Widget build(BuildContext context) { + return const OverlayIcon( + icon: AIcons.geo, + ); + } +} + +class HdrIcon extends StatelessWidget { + const HdrIcon({super.key}); + + @override + Widget build(BuildContext context) { + return const OverlayIcon( + icon: AIcons.hdr, + ); + } +} + +class PanoramaIcon extends StatelessWidget { + const PanoramaIcon({super.key}); + + static const scale = .85; + + @override + Widget build(BuildContext context) { + return const OverlayIcon( + icon: AIcons.panorama, + iconScale: scale, + ); + } +} + +class FavouriteIcon extends StatelessWidget { + const FavouriteIcon({super.key}); + + static const scale = .9; + + @override + Widget build(BuildContext context) { + return const OverlayIcon( + icon: AIcons.favourite, + iconScale: scale, + ); + } +} + +class TagIcon extends StatelessWidget { + final IconData icon; + + const TagIcon._private({required this.icon}); + + factory TagIcon.tagged() => const TagIcon._private(icon: AIcons.tag); + + factory TagIcon.untagged() => TagIcon._private(icon: AIcons.tagUntagged); + + static const scale = .9; + + @override + Widget build(BuildContext context) { + return OverlayIcon( + icon: icon, + iconScale: scale, + relativeOffset: const Offset(.05, .05), + ); + } +} + +class LocationIcon extends StatelessWidget { + final IconData icon; + + const LocationIcon._private({required this.icon}); + + factory LocationIcon.located() => const LocationIcon._private(icon: AIcons.location); + + factory LocationIcon.unlocated() => const LocationIcon._private(icon: AIcons.locationUnlocated); + + @override + Widget build(BuildContext context) { + return OverlayIcon( + icon: icon, + ); + } +} + +class RawIcon extends StatelessWidget { + const RawIcon({super.key}); + + @override + Widget build(BuildContext context) { + return const OverlayIcon( + icon: AIcons.raw, + ); + } +} + +class MotionPhotoIcon extends StatelessWidget { + const MotionPhotoIcon({super.key}); + + static const scale = .8; + + @override + Widget build(BuildContext context) { + return const OverlayIcon( + icon: AIcons.motionPhoto, + iconScale: scale, + ); + } +} + +class MultiPageIcon extends StatelessWidget { + final AvesEntry entry; + + static const scale = .8; + + const MultiPageIcon({ + super.key, + required this.entry, + }); + + @override + Widget build(BuildContext context) { + String? text; + if (entry.isStack) { + text = '${entry.stackedEntries?.length}'; + } + final child = OverlayIcon( + icon: AIcons.multiPage, + iconScale: scale, + text: text, + ); + return DefaultTextStyle( + style: TextStyle( + fontSize: context.select<GridThemeData, double>((t) => t.fontSize), + ), + child: child, + ); + } +} + +class RatingIcon extends StatelessWidget { + final AvesEntry entry; + + const RatingIcon({ + super.key, + required this.entry, + }); + + @override + Widget build(BuildContext context) { + return DefaultTextStyle( + style: TextStyle( + fontSize: context.select<GridThemeData, double>((t) => t.fontSize), + ), + child: OverlayIcon( + icon: AIcons.rating, + text: '${entry.rating}', + ), + ); + } +} + +class TrashIcon extends StatelessWidget { + final int? trashDaysLeft; + + const TrashIcon({ + super.key, + required this.trashDaysLeft, + }); + + @override + Widget build(BuildContext context) { + final child = OverlayIcon( + icon: AIcons.bin, + text: trashDaysLeft != null ? context.l10n.timeDays(trashDaysLeft!) : null, + ); + + return DefaultTextStyle( + style: TextStyle( + fontSize: context.select<GridThemeData, double>((t) => t.fontSize), + ), + child: child, + ); + } +} + +class OverlayIcon extends StatelessWidget { + final IconData icon; + final String? text; + final double iconScale; + final EdgeInsetsGeometry margin; + final Offset? relativeOffset; + + static const defaultMargin = EdgeInsets.only(left: 1, right: 1, bottom: 1); + + const OverlayIcon({ + super.key, + required this.icon, + this.iconScale = 1, + this.text, + // default margin for multiple icons in a `Column` + this.margin = defaultMargin, + this.relativeOffset, + }); + + @override + Widget build(BuildContext context) { + final size = context.select<GridThemeData, double>((t) => t.iconSize); + Widget iconChild = Icon( + icon, + size: size, + ); + + if (relativeOffset != null) { + iconChild = FractionalTranslation( + translation: relativeOffset!, + child: iconChild, + ); + } + + if (iconScale != 1) { + // using a transform is better than modifying the icon size to properly center the scaled icon + iconChild = Transform.scale( + scale: iconScale, + child: iconChild, + ); + } + + iconChild = SizedBox( + width: size, + height: size, + child: iconChild, + ); + + return Container( + margin: margin, + padding: text != null ? EdgeInsetsDirectional.only(end: size / 4) : null, + decoration: BoxDecoration( + color: Theme.of(context).isDark ? const Color(0xAA000000) : const Color(0xCCFFFFFF), + borderRadius: BorderRadius.all(Radius.circular(size)), + ), + child: text == null + ? iconChild + : Row( + mainAxisSize: MainAxisSize.min, + crossAxisAlignment: CrossAxisAlignment.center, + children: [ + iconChild, + const SizedBox(width: 2), + Flexible( + child: Text( + text!, + // consistent with the color used for the icon next to it + style: TextStyle(color: IconTheme.of(context).color), + softWrap: false, + overflow: TextOverflow.fade, + maxLines: 1, + ), + ), + ], + ), + ); + } +} + +class IconUtils { + static Widget? getAlbumIcon({ + required BuildContext context, + required String albumPath, + double? size, + }) { + size ??= IconTheme.of(context).size; + Widget buildIcon(IconData icon) => Icon(icon, size: size); + + switch (covers.effectiveAlbumType(albumPath)) { + case AlbumType.camera: + return buildIcon(AIcons.cameraAlbum); + case AlbumType.screenshots: + case AlbumType.videoCaptures: + return buildIcon(AIcons.screenshotAlbum); + case AlbumType.screenRecordings: + return buildIcon(AIcons.recordingAlbum); + case AlbumType.download: + return buildIcon(AIcons.downloadAlbum); + case AlbumType.app: + final package = covers.effectiveAlbumPackage(albumPath); + return package != null + ? Image( + image: AppIconImage( + packageName: package, + size: size!, + ), + width: size, + height: size, + ) + : null; + case AlbumType.vault: + return buildIcon(vaults.isLocked(albumPath) ? AIcons.locked : AIcons.unlocked); + case AlbumType.regular: + return null; + } + } +} diff --git a/lib/widgets/common/identity/aves_logo.dart b/lib/widgets/common/identity/aves_logo.dart new file mode 100644 index 0000000..2c35137 --- /dev/null +++ b/lib/widgets/common/identity/aves_logo.dart @@ -0,0 +1,148 @@ +import 'package:aves/model/settings/settings.dart'; +import 'package:aves/widgets/common/fx/borders.dart'; +import 'package:aves/widgets/common/fx/colors.dart'; +import 'package:aves_model/aves_model.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +class AvesLogo extends StatelessWidget { + final double size; + + const AvesLogo({ + super.key, + required this.size, + }); + + @override + Widget build(BuildContext context) { + final theme = Theme.of(context); + + Widget child = CustomPaint( + size: Size(size / 1.4, size / 1.4), + painter: AvesLogoPainter(), + ); + if (context.select<Settings, bool>((v) => v.themeColorMode == AvesThemeColorMode.monochrome)) { + final tint = Color.lerp(theme.colorScheme.primary, Colors.white, .5)!; + child = ColorFiltered( + colorFilter: ColorFilter.mode(tint, BlendMode.modulate), + child: ColorFiltered( + colorFilter: MatrixColorFilters.greyscale, + child: child, + ), + ); + } + + return CircleAvatar( + backgroundColor: theme.dividerColor, + radius: size / 2, + child: CircleAvatar( + backgroundColor: Colors.white, + radius: size / 2 - AvesBorder.curvedBorderWidth(context), + child: child, + ), + ); + } +} + +class AvesLogoPainter extends CustomPainter { + @override + void paint(Canvas canvas, Size size) { + final dim = size.width / 100; + final strokePaint = Paint() + ..style = PaintingStyle.stroke + ..color = Colors.black + ..strokeWidth = dim * 3.050970 + ..strokeCap = StrokeCap.round + ..strokeJoin = StrokeJoin.round; + + final path0 = Path(); + path0.moveTo(31.784 * dim, 63.612 * dim); + path0.lineTo(48.252 * dim, 80.08 * dim); + final radius = Radius.elliptical(2.911 * dim, 2.911 * dim); + path0.arcToPoint(Offset(48.252 * dim, 84.196 * dim), radius: radius, rotation: 0, largeArc: false, clockwise: true); + path0.lineTo(40.379000000000005 * dim, 92.069 * dim); + path0.arcToPoint(Offset(19.072000000000006 * dim, 92.069 * dim), radius: Radius.elliptical(15.067 * dim, 15.067 * dim), rotation: 0, largeArc: false, clockwise: true); + path0.lineTo(11.2 * dim, 84.197 * dim); + path0.arcToPoint(Offset(11.2 * dim, 80.08 * dim), radius: radius, rotation: 0, largeArc: false, clockwise: true); + path0.lineTo(27.668 * dim, 63.611999999999995 * dim); + path0.arcToPoint(Offset(31.785 * dim, 63.611999999999995 * dim), radius: radius, rotation: 0, largeArc: false, clockwise: true); + path0.close(); + + final path1 = Path(); + path1.moveTo(56.368 * dim, 39.026 * dim); + path1.lineTo(72.837 * dim, 55.494 * dim); + final radius2 = Radius.elliptical(2.904 * dim, 2.904 * dim); + path1.arcToPoint(Offset(72.837 * dim, 59.611 * dim), radius: radius2, rotation: 0, largeArc: false, clockwise: true); + path1.lineTo(56.367000000000004 * dim, 76.079 * dim); + path1.arcToPoint(Offset(52.252 * dim, 76.079 * dim), radius: radius2, rotation: 0, largeArc: false, clockwise: true); + path1.lineTo(35.784 * dim, 59.611 * dim); + path1.arcToPoint(Offset(35.784 * dim, 55.495 * dim), radius: radius2, rotation: 0, largeArc: false, clockwise: true); + path1.lineTo(52.251999999999995 * dim, 39.027 * dim); + path1.arcToPoint(Offset(56.367999999999995 * dim, 39.027 * dim), radius: radius2, rotation: 0, largeArc: false, clockwise: true); + path1.close(); + + final path2 = Path(); + path2.moveTo(60.37 * dim, 30.908 * dim); + final radius4 = Radius.elliptical(2.91 * dim, 2.91 * dim); + path2.arcToPoint(Offset(60.37 * dim, 35.025 * dim), radius: radius4, rotation: 0, largeArc: false, clockwise: false); + path2.lineTo(76.838 * dim, 51.492 * dim); + path2.arcToPoint(Offset(80.954 * dim, 51.492 * dim), radius: radius4, rotation: 0, largeArc: false, clockwise: false); + path2.lineTo(97.422 * dim, 35.025 * dim); + path2.arcToPoint(Offset(97.422 * dim, 30.907999999999998 * dim), radius: radius4, rotation: 0, largeArc: false, clockwise: false); + path2.lineTo(89.24799999999999 * dim, 22.733999999999998 * dim); + path2.arcToPoint(Offset(68.54399999999998 * dim, 22.733999999999998 * dim), radius: Radius.elliptical(14.64 * dim, 14.64 * dim), rotation: 0, largeArc: false, clockwise: false); + path2.close(); + path2.moveTo(76.624 * dim, 30.695 * dim); + final radius5 = Radius.elliptical(3.213 * dim, 3.213 * dim); + path2.arcToPoint(Offset(81.167 * dim, 30.695 * dim), radius: radius5, rotation: 0, largeArc: false, clockwise: true); + path2.arcToPoint(Offset(81.167 * dim, 35.237 * dim), radius: radius5, rotation: 0, largeArc: false, clockwise: true); + path2.arcToPoint(Offset(76.624 * dim, 35.237 * dim), radius: radius5, rotation: 0, largeArc: false, clockwise: true); + path2.arcToPoint(Offset(76.624 * dim, 30.694000000000003 * dim), radius: radius5, rotation: 0, largeArc: false, clockwise: true); + path2.close(); + + final path3 = Path(); + path3.moveTo(24.305 * dim, 6.96 * dim); + path3.lineTo(48.35 * dim, 31.004 * dim); + path3.arcToPoint(Offset(48.35 * dim, 35.121 * dim), radius: radius, rotation: 0, largeArc: false, clockwise: true); + path3.lineTo(31.882 * dim, 51.588 * dim); + path3.arcToPoint(Offset(27.765 * dim, 51.588 * dim), radius: radius, rotation: 0, largeArc: false, clockwise: true); + path3.lineTo(17.084 * dim, 40.907 * dim); + path3.arcToPoint(Offset(17.084 * dim, 8.75 * dim), radius: Radius.elliptical(22.738 * dim, 22.738 * dim), rotation: 0, largeArc: false, clockwise: true); + path3.lineTo(18.874 * dim, 6.96 * dim); + path3.arcToPoint(Offset(24.305 * dim, 6.96 * dim), radius: Radius.elliptical(3.84 * dim, 3.84 * dim), rotation: 0, largeArc: false, clockwise: true); + path3.close(); + + canvas.drawPath( + path0, + Paint() + ..style = PaintingStyle.fill + ..color = const Color(0xffef435a)); + + canvas.drawPath( + path1, + Paint() + ..style = PaintingStyle.fill + ..color = const Color(0xffe0e0e0)); + + canvas.drawPath( + path2, + Paint() + ..style = PaintingStyle.fill + ..color = const Color(0xffffc11f)); + + canvas.drawPath( + path3, + Paint() + ..style = PaintingStyle.fill + ..color = const Color(0xff1cc8eb)); + + // stroke should be painted over fill + canvas.drawPath(path0, strokePaint); + canvas.drawPath(path1, strokePaint); + canvas.drawPath(path2, strokePaint); + canvas.drawPath(path3, strokePaint); + } + + @override + bool shouldRepaint(covariant CustomPainter oldDelegate) => true; +} diff --git a/lib/widgets/common/identity/buttons/captioned_button.dart b/lib/widgets/common/identity/buttons/captioned_button.dart new file mode 100644 index 0000000..4d6df92 --- /dev/null +++ b/lib/widgets/common/identity/buttons/captioned_button.dart @@ -0,0 +1,184 @@ +import 'package:aves/widgets/common/identity/buttons/overlay_button.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/rendering.dart'; + +typedef CaptionedIconButtonBuilder = Widget Function(BuildContext context, FocusNode focusNode); + +class CaptionedButton extends StatefulWidget { + final Animation<double> scale; + final Widget captionText; + final CaptionedIconButtonBuilder iconButtonBuilder; + final bool autofocus, showCaption; + final VoidCallback? onPressed; + + static const EdgeInsets padding = EdgeInsets.symmetric(horizontal: 8); + static const double iconTextPadding = 8; + + CaptionedButton({ + super.key, + this.scale = kAlwaysCompleteAnimation, + Widget? icon, + CaptionedIconButtonBuilder? iconButtonBuilder, + String? caption, + Widget? captionText, + this.autofocus = false, + this.showCaption = true, + required this.onPressed, + }) : assert(icon != null || iconButtonBuilder != null), + assert(caption != null || captionText != null), + iconButtonBuilder = iconButtonBuilder ?? ((_, focusNode) => IconButton(icon: icon!, onPressed: onPressed, focusNode: focusNode)), + captionText = captionText ?? CaptionedButtonText(text: caption!, enabled: onPressed != null); + + @override + State<CaptionedButton> createState() => _CaptionedButtonState(); + + static double getWidth(BuildContext context) => OverlayButton.getSize(context) + padding.horizontal; + + static Size getSize(BuildContext context, String text, {required bool showCaption}) { + final width = getWidth(context); + var height = width; + if (showCaption) { + final paragraph = RenderParagraph( + TextSpan(text: text, style: CaptionedButtonText._textStyle(context)), + textDirection: TextDirection.ltr, + textScaler: MediaQuery.textScalerOf(context), + maxLines: CaptionedButtonText.maxLines, + )..layout(const BoxConstraints(), parentUsesSize: true); + height += paragraph.getMaxIntrinsicHeight(width) + padding.vertical; + paragraph.dispose(); + } + return Size(width, height); + } + + static double getTelevisionButtonHeight(BuildContext context) { + final text = 'whatever' * 42; + return CaptionedButton.getSize(context, text, showCaption: true).height; + } +} + +class _CaptionedButtonState extends State<CaptionedButton> { + final FocusNode _focusNode = FocusNode(); + final ValueNotifier<bool> _focusedNotifier = ValueNotifier(false); + bool _didAutofocus = false; + + @override + void initState() { + super.initState(); + _updateTraversal(); + _focusNode.addListener(_onFocusChanged); + } + + @override + void didChangeDependencies() { + super.didChangeDependencies(); + _handleAutofocus(); + } + + @override + void didUpdateWidget(covariant CaptionedButton oldWidget) { + super.didUpdateWidget(oldWidget); + if (oldWidget.onPressed != widget.onPressed) { + _updateTraversal(); + } + if (oldWidget.autofocus != widget.autofocus) { + _handleAutofocus(); + } + } + + @override + void dispose() { + _focusNode.dispose(); + _focusedNotifier.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + return SizedBox( + width: CaptionedButton.getWidth(context), + child: Column( + mainAxisSize: MainAxisSize.min, + children: [ + SizedBox(height: CaptionedButton.padding.top), + OverlayButton( + scale: widget.scale, + focusNode: _focusNode, + child: widget.iconButtonBuilder(context, _focusNode), + ), + if (widget.showCaption) ...[ + const SizedBox(height: CaptionedButton.iconTextPadding), + ScaleTransition( + scale: widget.scale, + child: ValueListenableBuilder<bool>( + valueListenable: _focusedNotifier, + builder: (context, focused, child) { + final style = CaptionedButtonText._textStyle(context); + return AnimatedDefaultTextStyle( + style: focused + ? style.copyWith( + color: Theme.of(context).colorScheme.primary, + ) + : style, + duration: const Duration(milliseconds: 200), + child: widget.captionText, + ); + }, + ), + ), + ], + SizedBox(height: CaptionedButton.padding.bottom), + ], + ), + ); + } + + void _handleAutofocus() { + if (!_didAutofocus && widget.autofocus) { + FocusScope.of(context).autofocus(_focusNode); + _didAutofocus = true; + } + } + + void _onFocusChanged() => _focusedNotifier.value = _focusNode.hasFocus; + + void _updateTraversal() { + final enabled = widget.onPressed != null; + _focusNode.skipTraversal = !enabled; + _focusNode.canRequestFocus = enabled; + } +} + +class CaptionedButtonText extends StatelessWidget { + final String text; + final bool enabled; + + static const int maxLines = 2; + + const CaptionedButtonText({ + super.key, + required this.text, + required this.enabled, + }); + + @override + Widget build(BuildContext context) { + var style = DefaultTextStyle.of(context).style; + if (!enabled) { + style = style.copyWith(color: style.color!.withValues(alpha: .2)); + } + + return Text( + text, + style: style, + textAlign: TextAlign.center, + overflow: TextOverflow.ellipsis, + maxLines: maxLines, + ); + } + + static TextStyle _textStyle(BuildContext context) { + // specify `height` for accurate paragraph height measurement + final defaultTextHeight = DefaultTextStyle.of(context).style.height; + return Theme.of(context).textTheme.bodySmall!.copyWith(height: defaultTextHeight); + } +} diff --git a/lib/widgets/common/identity/buttons/outlined_button.dart b/lib/widgets/common/identity/buttons/outlined_button.dart new file mode 100644 index 0000000..851ef93 --- /dev/null +++ b/lib/widgets/common/identity/buttons/outlined_button.dart @@ -0,0 +1,43 @@ +import 'package:flutter/material.dart'; + +class AvesOutlinedButton extends StatelessWidget { + final Widget? icon; + final String label; + final VoidCallback? onPressed; + + const AvesOutlinedButton({ + super.key, + this.icon, + required this.label, + required this.onPressed, + }); + + @override + Widget build(BuildContext context) { + final theme = Theme.of(context); + final foreground = WidgetStateProperty.resolveWith<Color>((states) { + return states.contains(WidgetState.disabled) ? theme.disabledColor : theme.colorScheme.onSurface; + }); + final style = ButtonStyle( + foregroundColor: foreground, + iconColor: foreground, + side: WidgetStateProperty.resolveWith<BorderSide>((states) { + return BorderSide( + color: states.contains(WidgetState.disabled) ? theme.disabledColor : theme.colorScheme.primary, + ); + }), + ); + return icon != null + ? OutlinedButton.icon( + onPressed: onPressed, + style: style, + icon: icon!, + label: Text(label), + ) + : OutlinedButton( + onPressed: onPressed, + style: style, + child: Text(label), + ); + } +} diff --git a/lib/widgets/common/identity/buttons/overlay_button.dart b/lib/widgets/common/identity/buttons/overlay_button.dart new file mode 100644 index 0000000..17fdc16 --- /dev/null +++ b/lib/widgets/common/identity/buttons/overlay_button.dart @@ -0,0 +1,191 @@ +import 'package:aves/model/settings/settings.dart'; +import 'package:aves/theme/themes.dart'; +import 'package:aves/widgets/common/extensions/theme.dart'; +import 'package:aves/widgets/common/fx/blurred.dart'; +import 'package:aves/widgets/common/fx/borders.dart'; +import 'package:flutter/material.dart'; + +class OverlayButton extends StatefulWidget { + final Animation<double> scale; + final BorderRadius? borderRadius; + final FocusNode? focusNode; + final Widget child; + + const OverlayButton({ + super.key, + this.scale = kAlwaysCompleteAnimation, + this.borderRadius, + this.focusNode, + required this.child, + }); + + @override + State<OverlayButton> createState() => _OverlayButtonState(); + + // icon (24) + icon padding (8) + button padding (16) + static double getSize(BuildContext context) => 48; +} + +class _OverlayButtonState extends State<OverlayButton> { + final ValueNotifier<bool> _focusedNotifier = ValueNotifier(false); + + @override + void initState() { + super.initState(); + _registerWidget(widget); + } + + @override + void didUpdateWidget(covariant OverlayButton oldWidget) { + super.didUpdateWidget(oldWidget); + _unregisterWidget(oldWidget); + _registerWidget(widget); + } + + @override + void dispose() { + _unregisterWidget(widget); + _focusedNotifier.dispose(); + super.dispose(); + } + + void _registerWidget(OverlayButton widget) { + widget.focusNode?.addListener(_onFocusChanged); + } + + void _unregisterWidget(OverlayButton widget) { + widget.focusNode?.removeListener(_onFocusChanged); + } + + @override + Widget build(BuildContext context) { + final theme = Theme.of(context); + final colorScheme = theme.colorScheme; + final borderRadius = widget.borderRadius; + + final blurred = settings.enableBlurEffect; + final overlayBackground = Themes.overlayBackgroundColor( + brightness: colorScheme.brightness, + blurred: blurred, + ); + + return Theme( + data: theme.copyWith( + colorScheme: colorScheme.copyWith( + onSurfaceVariant: colorScheme.onSurface, + ), + ), + child: ScaleTransition( + scale: widget.scale, + child: ValueListenableBuilder<bool>( + valueListenable: _focusedNotifier, + builder: (context, focused, child) { + final border = AvesBorder.border( + context, + width: AvesBorder.curvedBorderWidth(context) * (focused ? 3 : 1), + ); + return borderRadius != null + ? BlurredRRect( + enabled: blurred, + borderRadius: borderRadius, + child: Material( + type: MaterialType.button, + borderRadius: borderRadius, + color: overlayBackground, + child: AnimatedContainer( + foregroundDecoration: BoxDecoration( + border: border, + borderRadius: borderRadius, + ), + duration: const Duration(milliseconds: 200), + child: widget.child, + ), + ), + ) + : BlurredOval( + enabled: blurred, + child: Material( + type: MaterialType.circle, + color: overlayBackground, + child: AnimatedContainer( + foregroundDecoration: BoxDecoration( + border: border, + shape: BoxShape.circle, + ), + duration: const Duration(milliseconds: 200), + child: widget.child, + ), + ), + ); + }, + ), + ), + ); + } + + void _onFocusChanged() => _focusedNotifier.value = widget.focusNode?.hasFocus ?? false; +} + +class ScalingOverlayTextButton extends StatelessWidget { + final Animation<double> scale; + final VoidCallback? onPressed; + final Widget child; + + const ScalingOverlayTextButton({ + super.key, + required this.scale, + this.onPressed, + required this.child, + }); + + @override + Widget build(BuildContext context) { + return SizeTransition( + sizeFactor: scale, + child: OverlayTextButton( + onPressed: onPressed, + child: child, + ), + ); + } +} + +class OverlayTextButton extends StatelessWidget { + final VoidCallback? onPressed; + final Widget child; + + const OverlayTextButton({ + super.key, + this.onPressed, + required this.child, + }); + + static const _borderRadius = 123.0; + static final _minSize = WidgetStateProperty.all<Size>(const Size(kMinInteractiveDimension, kMinInteractiveDimension)); + + @override + Widget build(BuildContext context) { + final blurred = settings.enableBlurEffect; + final theme = Theme.of(context); + final foreground = theme.colorScheme.onSurface; + return BlurredRRect.all( + enabled: blurred, + borderRadius: _borderRadius, + child: OutlinedButton( + onPressed: onPressed, + style: ButtonStyle( + backgroundColor: WidgetStateProperty.all<Color>(Themes.overlayBackgroundColor(brightness: theme.brightness, blurred: blurred)), + foregroundColor: WidgetStateProperty.all<Color>(foreground), + overlayColor: theme.isDark ? WidgetStateProperty.all<Color>(Colors.white.withValues(alpha: .12)) : null, + minimumSize: _minSize, + iconColor: WidgetStateProperty.all<Color>(foreground), + side: WidgetStateProperty.all<BorderSide>(AvesBorder.curvedSide(context)), + shape: WidgetStateProperty.all<OutlinedBorder>(const RoundedRectangleBorder( + borderRadius: BorderRadius.all(Radius.circular(_borderRadius)), + )), + ), + child: child, + ), + ); + } +} diff --git a/lib/widgets/common/identity/empty.dart b/lib/widgets/common/identity/empty.dart new file mode 100644 index 0000000..458d7a8 --- /dev/null +++ b/lib/widgets/common/identity/empty.dart @@ -0,0 +1,74 @@ +import 'package:aves/theme/durations.dart'; +import 'package:aves/widgets/common/extensions/media_query.dart'; +import 'package:flutter/material.dart'; +import 'package:flutter/scheduler.dart'; +import 'package:flutter_staggered_animations/flutter_staggered_animations.dart'; +import 'package:provider/provider.dart'; + +class EmptyContent extends StatelessWidget { + final IconData? icon; + final String text; + final Widget? bottom; + final AlignmentGeometry alignment; + final double fontSize; + final bool safeBottom; + + const EmptyContent({ + super.key, + this.icon, + required this.text, + this.bottom, + this.alignment = const FractionalOffset(.5, .35), + this.fontSize = 22, + this.safeBottom = true, + }); + + @override + Widget build(BuildContext context) { + final color = Theme.of(context).colorScheme.primary.withValues(alpha: .5); + final durations = context.watch<DurationsData>(); + return Padding( + padding: safeBottom + ? EdgeInsets.only( + bottom: context.select<MediaQueryData, double>((mq) => mq.effectiveBottomPadding), + ) + : EdgeInsets.zero, + child: Align( + alignment: alignment, + child: Column( + mainAxisSize: MainAxisSize.min, + children: AnimationConfiguration.toStaggeredList( + duration: durations.staggeredAnimation, + delay: durations.staggeredAnimationDelay * timeDilation, + childAnimationBuilder: (child) => SlideAnimation( + verticalOffset: 50.0, + child: FadeInAnimation( + child: child, + ), + ), + children: [ + if (icon != null) ...[ + Icon( + icon, + size: 64, + color: color, + ), + const SizedBox(height: 16) + ], + if (text.isNotEmpty) + Text( + text, + style: TextStyle( + color: color, + fontSize: fontSize, + ), + textAlign: TextAlign.center, + ), + if (bottom != null) bottom!, + ], + ), + ), + ), + ); + } +} diff --git a/lib/widgets/common/identity/highlight_title.dart b/lib/widgets/common/identity/highlight_title.dart new file mode 100644 index 0000000..76647e1 --- /dev/null +++ b/lib/widgets/common/identity/highlight_title.dart @@ -0,0 +1,74 @@ +import 'package:aves/model/settings/settings.dart'; +import 'package:aves/ref/locales.dart'; +import 'package:aves/theme/colors.dart'; +import 'package:aves/theme/themes.dart'; +import 'package:aves/widgets/common/basic/text/outlined.dart'; +import 'package:aves/widgets/common/extensions/build_context.dart'; +import 'package:aves/widgets/common/extensions/theme.dart'; +import 'package:aves/widgets/common/fx/highlight_decoration.dart'; +import 'package:aves_model/aves_model.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +class HighlightTitle extends StatelessWidget { + final String title; + final Color? color; + final double fontSize; + final bool enabled; + final bool showHighlight; + + const HighlightTitle({ + super.key, + required this.title, + this.color, + this.fontSize = 18, + this.enabled = true, + this.showHighlight = true, + }); + + static const disabledColor = Colors.grey; + + static List<Shadow> shadows(BuildContext context) => [ + Shadow( + color: Theme.of(context).isDark ? Colors.black : Colors.white, + offset: const Offset(0, 1), + blurRadius: 2, + ) + ]; + + @override + Widget build(BuildContext context) { + final style = TextStyle( + shadows: shadows(context), + fontSize: fontSize, + letterSpacing: canHaveLetterSpacing(context.locale) ? 1 : 0, + fontFeatures: const [FontFeature.enable('smcp')], + ); + + final colors = context.watch<AvesColorsData>(); + return Align( + alignment: AlignmentDirectional.centerStart, + child: Container( + padding: const EdgeInsets.symmetric(horizontal: 2), + decoration: showHighlight && context.select<Settings, bool>((v) => v.themeColorMode == AvesThemeColorMode.polychrome) + ? HighlightDecoration( + color: enabled ? color ?? colors.fromString(title) : disabledColor, + ) + : null, + margin: const EdgeInsets.symmetric(vertical: 4.0), + child: OutlinedText( + textSpans: [ + TextSpan( + text: title, + style: style, + ), + ], + outlineColor: Themes.firstLayerColor(context), + softWrap: false, + overflow: TextOverflow.fade, + maxLines: 1, + ), + ), + ); + } +} diff --git a/lib/widgets/common/identity/scroll_thumb.dart b/lib/widgets/common/identity/scroll_thumb.dart new file mode 100644 index 0000000..718abf2 --- /dev/null +++ b/lib/widgets/common/identity/scroll_thumb.dart @@ -0,0 +1,47 @@ +import 'package:aves/widgets/common/basic/draggable_scrollbar/arrow_clipper.dart'; +import 'package:aves/widgets/common/basic/draggable_scrollbar/scrollbar.dart'; +import 'package:flutter/material.dart'; + +const double avesScrollThumbHeight = 48; + +// height and background color do not change +// so we do not rely on the builder props +ScrollThumbBuilder avesScrollThumbBuilder({ + required double height, + required Color backgroundColor, +}) { + final scrollThumb = Container( + decoration: const BoxDecoration( + color: Colors.black26, + borderRadius: BorderRadius.all(Radius.circular(12)), + ), + height: height, + margin: _margin, + padding: _padding, + child: ClipPath( + clipper: ArrowClipper(), + child: Container( + width: _width, + decoration: BoxDecoration( + color: backgroundColor, + borderRadius: const BorderRadius.all(Radius.circular(12)), + ), + ), + ), + ); + return (backgroundColor, thumbAnimation, labelAnimation, height, {labelText}) { + return DraggableScrollbar.buildScrollThumbAndLabel( + scrollThumb: scrollThumb, + backgroundColor: backgroundColor, + thumbAnimation: thumbAnimation, + labelAnimation: labelAnimation, + labelText: labelText, + ); + }; +} + +const _margin = EdgeInsetsDirectional.only(end: 1); +const _padding = EdgeInsets.all(2); +const _width = 20.0; + +double get avesScrollThumbWidth => _width + _padding.horizontal + _margin.horizontal; |
