toolbar.dart 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. import 'dart:io';
  2. import 'package:flutter/material.dart';
  3. /* -------------------------------- Constant -------------------------------- */
  4. typedef OnImageSelectCallback = Future<String> Function(File file);
  5. final double kToolbarButtonDefaultSize = 18.0;
  6. /* --------------------------------- Toolbar -------------------------------- */
  7. class EditorToolbar extends StatefulWidget implements PreferredSizeWidget {
  8. const EditorToolbar({
  9. required this.children,
  10. this.customToolbarHeight,
  11. this.customButtonHeight,
  12. Key? key,
  13. }) : super(key: key);
  14. final double? customButtonHeight;
  15. final double? customToolbarHeight;
  16. final List<Widget> children;
  17. @override
  18. Size get preferredSize {
  19. return Size.fromHeight(customToolbarHeight ??
  20. customButtonHeight ??
  21. kToolbarButtonDefaultSize * 2);
  22. }
  23. @override
  24. _EditorToolbarState createState() => _EditorToolbarState();
  25. }
  26. class _EditorToolbarState extends State<EditorToolbar> {
  27. @override
  28. Widget build(BuildContext context) {
  29. return Container(
  30. padding: const EdgeInsets.symmetric(horizontal: 8),
  31. constraints: BoxConstraints.tightFor(height: widget.preferredSize.height),
  32. color: Theme.of(context).canvasColor,
  33. child: CustomScrollView(
  34. scrollDirection: Axis.horizontal,
  35. slivers: [
  36. SliverFillRemaining(
  37. hasScrollBody: false,
  38. child: Row(
  39. mainAxisAlignment: MainAxisAlignment.spaceEvenly,
  40. children: widget.children,
  41. ),
  42. )
  43. ],
  44. ),
  45. );
  46. }
  47. }