view_mode_switcher.dart 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. import 'package:flutter/material.dart';
  2. import 'package:flyinsono/lab/components/rect_icon_button.dart';
  3. class ViewModeSwitcher extends StatefulWidget {
  4. const ViewModeSwitcher({
  5. super.key,
  6. required this.viewMode,
  7. required this.onModeChanged,
  8. });
  9. final ViewMode viewMode;
  10. final ValueChanged onModeChanged;
  11. @override
  12. State<ViewModeSwitcher> createState() => _ViewModeSwitcherState();
  13. }
  14. class _ViewModeSwitcherState extends State<ViewModeSwitcher> {
  15. @override
  16. void initState() {
  17. super.initState();
  18. }
  19. @override
  20. Widget build(BuildContext context) {
  21. return Row(
  22. children: [
  23. RectIconButton(
  24. onPressed: () {
  25. widget.onModeChanged(ViewMode.grid);
  26. },
  27. isSelected: widget.viewMode == ViewMode.grid,
  28. tooltipMessage: "切换为网格视图",
  29. ),
  30. SizedBox(width: 5),
  31. RectIconButton(
  32. onPressed: () {
  33. widget.onModeChanged(ViewMode.list);
  34. },
  35. isSelected: widget.viewMode == ViewMode.list,
  36. icon: Icons.menu_rounded,
  37. tooltipMessage: "切换为列表视图",
  38. ),
  39. ],
  40. );
  41. }
  42. }
  43. enum ViewMode { grid, list }