diff --git a/lib/src/models/config/editor/editor_configurations.dart b/lib/src/models/config/editor/editor_configurations.dart index cb64336a1..d3f72b0cd 100644 --- a/lib/src/models/config/editor/editor_configurations.dart +++ b/lib/src/models/config/editor/editor_configurations.dart @@ -33,6 +33,7 @@ class QuillEditorConfigurations extends Equatable { this.expands = false, this.placeholder, this.readOnly = false, + this.checkBoxReadOnly, this.disableClipboard = false, this.textSelectionThemeData, this.showCursor, @@ -97,6 +98,15 @@ class QuillEditorConfigurations extends Equatable { /// Defaults to `false`. Must not be `null`. final bool readOnly; + /// Override [readOnly] for checkbox. + /// + /// When this is set to `false`, the checkbox can be checked + /// or unchecked while [readOnly] is set to `true`. + /// When this is set to `null`, the [readOnly] value is used. + /// + /// Defaults to `null`. + final bool? checkBoxReadOnly; + /// Disable Clipboard features /// /// when this is set to `true` clipboard can not be used @@ -369,6 +379,7 @@ class QuillEditorConfigurations extends Equatable { QuillController? controller, String? placeholder, bool? readOnly, + bool? checkBoxReadOnly, bool? disableClipboard, bool? scrollable, double? scrollBottomInset, @@ -421,6 +432,7 @@ class QuillEditorConfigurations extends Equatable { controller: controller ?? this.controller, placeholder: placeholder ?? this.placeholder, readOnly: readOnly ?? this.readOnly, + checkBoxReadOnly: checkBoxReadOnly ?? this.checkBoxReadOnly, disableClipboard: disableClipboard ?? this.disableClipboard, scrollable: scrollable ?? this.scrollable, scrollBottomInset: scrollBottomInset ?? this.scrollBottomInset, diff --git a/lib/src/models/config/raw_editor/raw_editor_configurations.dart b/lib/src/models/config/raw_editor/raw_editor_configurations.dart index 726dda0f8..eb1f9def2 100644 --- a/lib/src/models/config/raw_editor/raw_editor_configurations.dart +++ b/lib/src/models/config/raw_editor/raw_editor_configurations.dart @@ -50,6 +50,7 @@ class QuillRawEditorConfigurations extends Equatable { this.scrollable = true, this.padding = EdgeInsets.zero, this.readOnly = false, + this.checkBoxReadOnly, this.disableClipboard = false, this.placeholder, this.onLaunchUrl, @@ -104,6 +105,15 @@ class QuillRawEditorConfigurations extends Equatable { /// Defaults to false. Must not be null. final bool readOnly; + /// Override readOnly for checkbox. + /// + /// When this is set to false, the checkbox can be checked + /// or unchecked while readOnly is set to true. + /// When this is set to null, the readOnly value is used. + /// + /// Defaults to null. + final bool? checkBoxReadOnly; + /// Disable Clipboard features /// /// when this is set to true clipboard can not be used diff --git a/lib/src/widgets/editor/editor.dart b/lib/src/widgets/editor/editor.dart index 4c4ea7cbe..a68d15cee 100644 --- a/lib/src/widgets/editor/editor.dart +++ b/lib/src/widgets/editor/editor.dart @@ -235,6 +235,7 @@ class QuillEditorState extends State scrollBottomInset: configurations.scrollBottomInset, padding: configurations.padding, readOnly: configurations.readOnly, + checkBoxReadOnly: configurations.checkBoxReadOnly, disableClipboard: configurations.disableClipboard, placeholder: configurations.placeholder, onLaunchUrl: configurations.onLaunchUrl, diff --git a/lib/src/widgets/quill/text_block.dart b/lib/src/widgets/quill/text_block.dart index 8fb89191c..c0b6b187a 100644 --- a/lib/src/widgets/quill/text_block.dart +++ b/lib/src/widgets/quill/text_block.dart @@ -74,6 +74,7 @@ class EditableTextBlock extends StatelessWidget { required this.clearIndents, required this.onCheckboxTap, required this.readOnly, + this.checkBoxReadOnly, this.onLaunchUrl, this.customStyleBuilder, this.customLinkPrefixes = const [], @@ -100,6 +101,7 @@ class EditableTextBlock extends StatelessWidget { final bool clearIndents; final Function(int, bool) onCheckboxTap; final bool readOnly; + final bool? checkBoxReadOnly; final List customLinkPrefixes; @override @@ -279,7 +281,7 @@ class EditableTextBlock extends StatelessWidget { return QuillEditorCheckboxPoint( size: fontSize, value: attrs[Attribute.list.key] == Attribute.checked, - enabled: !readOnly, + enabled: !(checkBoxReadOnly ?? readOnly), onChanged: (checked) => onCheckboxTap(line.documentOffset, checked), uiBuilder: defaultStyles.lists?.checkboxUIBuilder, ); diff --git a/lib/src/widgets/raw_editor/raw_editor_state.dart b/lib/src/widgets/raw_editor/raw_editor_state.dart index da6364148..957e61863 100644 --- a/lib/src/widgets/raw_editor/raw_editor_state.dart +++ b/lib/src/widgets/raw_editor/raw_editor_state.dart @@ -998,7 +998,8 @@ class QuillRawEditorState extends EditorState void _handleCheckboxTap(int offset, bool value) { final requestKeyboardFocusOnCheckListChanged = widget.configurations.requestKeyboardFocusOnCheckListChanged; - if (!widget.configurations.readOnly) { + if (!(widget.configurations.checkBoxReadOnly ?? + widget.configurations.readOnly)) { _disableScrollControllerAnimateOnce = true; final currentSelection = controller.selection.copyWith(); final attribute = value ? Attribute.checked : Attribute.unchecked; @@ -1074,6 +1075,7 @@ class QuillRawEditorState extends EditorState clearIndents: clearIndents, onCheckboxTap: _handleCheckboxTap, readOnly: widget.configurations.readOnly, + checkBoxReadOnly: widget.configurations.checkBoxReadOnly, customStyleBuilder: widget.configurations.customStyleBuilder, customLinkPrefixes: widget.configurations.customLinkPrefixes, );