bottom_action_bar_widget.dart 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. import 'package:expandable/expandable.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:photos/ui/components/bottom_action_bar/action_bar_widget.dart';
  4. import 'package:photos/ui/components/icon_button_widget.dart';
  5. import 'package:photos/ui/settings/common_settings.dart';
  6. class BottomActionBarWidget extends StatefulWidget {
  7. final Widget? textWidget;
  8. final List<Widget>? iconButtons;
  9. final Widget expandedMenu;
  10. const BottomActionBarWidget({
  11. required this.expandedMenu,
  12. this.textWidget,
  13. this.iconButtons,
  14. super.key,
  15. });
  16. @override
  17. State<BottomActionBarWidget> createState() => _BottomActionBarWidgetState();
  18. }
  19. class _BottomActionBarWidgetState extends State<BottomActionBarWidget> {
  20. final ExpandableController _expandableController =
  21. ExpandableController(initialExpanded: false);
  22. @override
  23. Widget build(BuildContext context) {
  24. //todo : restric width of column
  25. return Container(
  26. padding: const EdgeInsets.only(top: 4, bottom: 36),
  27. child: Column(
  28. mainAxisSize: MainAxisSize.min,
  29. children: [
  30. ExpandableNotifier(
  31. controller: _expandableController,
  32. child: ExpandablePanel(
  33. theme: getExpandableTheme(context),
  34. header: Padding(
  35. padding: EdgeInsets.symmetric(
  36. horizontal: widget.textWidget == null ? 12 : 0,
  37. ),
  38. child: ActionBarWidget(
  39. textWidget: widget.textWidget,
  40. iconButtons: _iconButtons(),
  41. ),
  42. ),
  43. expanded: widget.expandedMenu,
  44. collapsed: const SizedBox.shrink(),
  45. controller: _expandableController,
  46. ),
  47. ),
  48. ],
  49. ),
  50. );
  51. }
  52. List<Widget> _iconButtons() {
  53. final isExpanded = _expandableController.expanded;
  54. final iconButtons = <Widget?>[
  55. ...?widget.iconButtons,
  56. AnimatedSwitcher(
  57. duration: const Duration(milliseconds: 200),
  58. switchInCurve: Curves.easeInOutExpo,
  59. child: isExpanded
  60. ? IconButtonWidget(
  61. key: ValueKey<bool>(isExpanded),
  62. onTap: () {
  63. _expandableController.value = false;
  64. setState(() {});
  65. },
  66. icon: Icons.expand_more_outlined,
  67. iconButtonType: IconButtonType.primary,
  68. )
  69. : IconButtonWidget(
  70. key: ValueKey<bool>(isExpanded),
  71. onTap: () {
  72. _expandableController.value = true;
  73. setState(() {});
  74. },
  75. icon: Icons.more_horiz_outlined,
  76. iconButtonType: IconButtonType.primary,
  77. ),
  78. ),
  79. ];
  80. iconButtons.removeWhere((element) => element == null);
  81. return iconButtons as List<Widget>;
  82. }
  83. }