expand_buttons.dart 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import 'package:fis_i18n/i18n.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:fis_ui/base_define/page.dart';
  4. import 'package:fis_ui/index.dart';
  5. class FExpandedButtons extends FStatefulWidget implements FPage {
  6. final Map<String, void Function()> operates;
  7. final FWidget Function(String, Function) textButton;
  8. final bool canEditReport;
  9. FExpandedButtons(this.operates, this.textButton, this.canEditReport);
  10. @override
  11. FState<FStatefulWidget> createState() {
  12. return FExpandedButtonsState();
  13. }
  14. @override
  15. String get pageName => "FExpandedButtons";
  16. }
  17. class FExpandedButtonsState extends FState<FExpandedButtons> {
  18. bool _isExpandButtons = false;
  19. @override
  20. FWidget build(BuildContext context) {
  21. List<FWidget> children = [
  22. widget.textButton(
  23. i18nBook.common.view.t, widget.operates[i18nBook.common.view.t]!),
  24. if (widget.canEditReport) ...[
  25. widget.textButton(i18nBook.common.modify.t,
  26. widget.operates[i18nBook.common.modify.t]!),
  27. ],
  28. ];
  29. if (_isExpandButtons) {
  30. children = widget.operates.keys
  31. .map((e) => widget.textButton(e, widget.operates[e]!))
  32. .toList();
  33. }
  34. if (children.length % 3 == 0) {
  35. ///占位用,为了让收缩按钮在最右边
  36. children.add(FSizedBox());
  37. }
  38. if (widget.operates.length > 2) {
  39. children.add(
  40. FTextButton(
  41. child: FText(_isExpandButtons
  42. ? i18nBook.measure.collapseGroup.t
  43. : i18nBook.measure.expandGroup.t),
  44. onPressed: () {
  45. setState(() {
  46. _isExpandButtons = !_isExpandButtons;
  47. });
  48. },
  49. style: ButtonStyle(
  50. padding:
  51. MaterialStateProperty.all(EdgeInsets.symmetric(horizontal: 5)),
  52. fixedSize: MaterialStateProperty.all<Size>(
  53. Size(70, 25),
  54. ),
  55. ),
  56. businessParent: widget,
  57. name: "expand button",
  58. ),
  59. );
  60. }
  61. return FWrap(
  62. alignment: WrapAlignment.spaceBetween,
  63. spacing: 10,
  64. runSpacing: 5,
  65. children: children,
  66. );
  67. }
  68. }