style_widgets.dart 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  1. import 'package:flowy_infra/image.dart';
  2. import 'package:flowy_infra/theme.dart';
  3. import 'package:flowy_infra_ui/style_widget/icon_button.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:flutter_quill/flutter_quill.dart';
  6. class StyleWidgetBuilder {
  7. static QuillCheckboxBuilder checkbox(AppTheme theme) {
  8. return EditorCheckboxBuilder(theme);
  9. }
  10. }
  11. class EditorCheckboxBuilder extends QuillCheckboxBuilder {
  12. final AppTheme theme;
  13. EditorCheckboxBuilder(this.theme);
  14. @override
  15. Widget build({required BuildContext context, required bool isChecked, required ValueChanged<bool> onChanged}) {
  16. return FlowyEditorCheckbox(
  17. theme: theme,
  18. isChecked: isChecked,
  19. onChanged: onChanged,
  20. );
  21. }
  22. }
  23. class FlowyEditorCheckbox extends StatefulWidget {
  24. final bool isChecked;
  25. final ValueChanged<bool> onChanged;
  26. final AppTheme theme;
  27. const FlowyEditorCheckbox({
  28. required this.theme,
  29. required this.isChecked,
  30. required this.onChanged,
  31. Key? key,
  32. }) : super(key: key);
  33. @override
  34. _FlowyEditorCheckboxState createState() => _FlowyEditorCheckboxState();
  35. }
  36. class _FlowyEditorCheckboxState extends State<FlowyEditorCheckbox> {
  37. late bool isChecked;
  38. @override
  39. void initState() {
  40. isChecked = widget.isChecked;
  41. super.initState();
  42. }
  43. @override
  44. Widget build(BuildContext context) {
  45. final icon = isChecked ? svgWidget('editor/editor_check') : svgWidget('editor/editor_uncheck');
  46. return Align(
  47. alignment: Alignment.centerLeft,
  48. child: FlowyIconButton(
  49. onPressed: () {
  50. isChecked = !isChecked;
  51. widget.onChanged(isChecked);
  52. setState(() {});
  53. },
  54. iconPadding: EdgeInsets.zero,
  55. icon: icon,
  56. width: 23,
  57. ),
  58. );
  59. }
  60. }