diff options
| author | mirror <mirror@localhost> | 2026-11-22 08:41:00 +0900 |
|---|---|---|
| committer | mirror <mirror@localhost> | 2026-11-22 08:41:00 +0900 |
| commit | 449d8b74bd6d9dae98a07254cdfad677b920e7b0 (patch) | |
| tree | c131c3528c4d517f56e19b854a7453fedb097d40 /lib/widgets/common/basic/popup | |
| download | aves-src-master.tar.gz aves-src-master.zip | |
Diffstat (limited to 'lib/widgets/common/basic/popup')
| -rw-r--r-- | lib/widgets/common/basic/popup/container.dart | 35 | ||||
| -rw-r--r-- | lib/widgets/common/basic/popup/expansion_panel.dart | 105 | ||||
| -rw-r--r-- | lib/widgets/common/basic/popup/menu_row.dart | 36 |
3 files changed, 176 insertions, 0 deletions
diff --git a/lib/widgets/common/basic/popup/container.dart b/lib/widgets/common/basic/popup/container.dart new file mode 100644 index 0000000..30a0323 --- /dev/null +++ b/lib/widgets/common/basic/popup/container.dart @@ -0,0 +1,35 @@ +import 'package:flutter/material.dart'; + +class PopupMenuItemContainer<T> extends PopupMenuEntry<T> { + final Widget child; + + const PopupMenuItemContainer({ + super.key, + this.height = kMinInteractiveDimension, + required this.child, + }); + + @override + final double height; + + @override + bool represents(void value) => false; + + @override + State<PopupMenuItemContainer> createState() => _PopupMenuItemContainerState(); +} + +class _PopupMenuItemContainerState extends State<PopupMenuItemContainer> { + @override + Widget build(BuildContext context) { + return TooltipTheme( + data: TooltipTheme.of(context).copyWith( + preferBelow: false, + ), + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 16), + child: widget.child, + ), + ); + } +} diff --git a/lib/widgets/common/basic/popup/expansion_panel.dart b/lib/widgets/common/basic/popup/expansion_panel.dart new file mode 100644 index 0000000..63bc94e --- /dev/null +++ b/lib/widgets/common/basic/popup/expansion_panel.dart @@ -0,0 +1,105 @@ +import 'package:aves/theme/durations.dart'; +import 'package:aves/widgets/common/basic/popup/menu_row.dart'; +import 'package:flutter/material.dart'; +import 'package:provider/provider.dart'; + +class PopupMenuExpansionPanel<T> extends PopupMenuEntry<T> { + final bool enabled; + final String value; + final ValueNotifier<String?>? expandedNotifier; + final IconData icon; + final String title; + final List<PopupMenuEntry<T>> items; + + const PopupMenuExpansionPanel({ + super.key, + this.enabled = true, + this.height = kMinInteractiveDimension, + required this.value, + this.expandedNotifier, + required this.icon, + required this.title, + required this.items, + }); + + @override + final double height; + + @override + bool represents(void value) => false; + + @override + State<PopupMenuExpansionPanel<T>> createState() => _PopupMenuExpansionPanelState<T>(); +} + +class _PopupMenuExpansionPanelState<T> extends State<PopupMenuExpansionPanel<T>> { + final ValueNotifier<String?> _internalExpandedNotifier = ValueNotifier(null); + + ValueNotifier<String?> get expandedNotifier => widget.expandedNotifier ?? _internalExpandedNotifier; + + @override + void dispose() { + _internalExpandedNotifier.dispose(); + super.dispose(); + } + + @override + Widget build(BuildContext context) { + final style = PopupMenuTheme.of(context).labelTextStyle!.resolve( + <WidgetState>{ + if (!widget.enabled) WidgetState.disabled, + }, + )!; + final animationDuration = context.select<DurationsData, Duration>((v) => v.expansionTileAnimation); + + Widget child = ValueListenableBuilder<String?>( + valueListenable: expandedNotifier, + builder: (context, expandedValue, child) { + return ExpansionPanelList( + expansionCallback: (index, isExpanded) { + expandedNotifier.value = isExpanded ? widget.value : null; + }, + animationDuration: animationDuration, + expandedHeaderPadding: EdgeInsets.zero, + elevation: 0, + children: [ + ExpansionPanel( + headerBuilder: (context, isExpanded) { + return DefaultTextStyle( + style: style, + child: IconTheme.merge( + data: IconThemeData( + color: widget.enabled ? null : Theme.of(context).disabledColor, + ), + child: Padding( + padding: const EdgeInsets.symmetric(horizontal: 12), + child: MenuRow( + text: widget.title, + icon: Icon(widget.icon), + ), + ), + ), + ); + }, + body: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + const PopupMenuDivider(height: 0), + ...widget.items, + const PopupMenuDivider(height: 0), + ], + ), + isExpanded: expandedValue == widget.value, + canTapOnHeader: true, + backgroundColor: Colors.transparent, + ), + ], + ); + }, + ); + if (!widget.enabled) { + child = IgnorePointer(child: child); + } + return child; + } +} diff --git a/lib/widgets/common/basic/popup/menu_row.dart b/lib/widgets/common/basic/popup/menu_row.dart new file mode 100644 index 0000000..23f77b4 --- /dev/null +++ b/lib/widgets/common/basic/popup/menu_row.dart @@ -0,0 +1,36 @@ +import 'package:flutter/material.dart'; + +class MenuRow extends StatelessWidget { + final String text; + final Widget? icon; + + const MenuRow({ + super.key, + required this.text, + this.icon, + }); + + static const leadingPadding = EdgeInsetsDirectional.only(end: 12); + + @override + Widget build(BuildContext context) { + return Row( + mainAxisSize: MainAxisSize.min, + children: [ + if (icon != null) + Padding( + padding: leadingPadding, + child: IconTheme.merge( + data: IconThemeData( + color: ListTileTheme.of(context).iconColor, + ), + child: icon!, + ), + ), + Flexible( + child: Text(text), + ), + ], + ); + } +} |
