style_widgets.dart 1.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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(
  16. {required BuildContext context,
  17. required bool isChecked,
  18. required ValueChanged<bool> onChanged}) {
  19. return FlowyEditorCheckbox(
  20. theme: theme,
  21. isChecked: isChecked,
  22. onChanged: onChanged,
  23. );
  24. }
  25. }
  26. class FlowyEditorCheckbox extends StatefulWidget {
  27. final bool isChecked;
  28. final ValueChanged<bool> onChanged;
  29. final AppTheme theme;
  30. const FlowyEditorCheckbox({
  31. required this.theme,
  32. required this.isChecked,
  33. required this.onChanged,
  34. Key? key,
  35. }) : super(key: key);
  36. @override
  37. FlowyEditorCheckboxState createState() => FlowyEditorCheckboxState();
  38. }
  39. class FlowyEditorCheckboxState extends State<FlowyEditorCheckbox> {
  40. late bool isChecked;
  41. @override
  42. void initState() {
  43. isChecked = widget.isChecked;
  44. super.initState();
  45. }
  46. @override
  47. Widget build(BuildContext context) {
  48. final icon = isChecked
  49. ? svgWidget('editor/editor_check')
  50. : svgWidget('editor/editor_uncheck');
  51. return Align(
  52. alignment: Alignment.centerLeft,
  53. child: FlowyIconButton(
  54. onPressed: () {
  55. isChecked = !isChecked;
  56. widget.onChanged(isChecked);
  57. setState(() {});
  58. },
  59. iconPadding: EdgeInsets.zero,
  60. icon: icon,
  61. width: 23,
  62. ),
  63. );
  64. }
  65. }