Skip to content

Commit

Permalink
Add checkBoxReadOnly property (#1836)
Browse files Browse the repository at this point in the history
  • Loading branch information
gklamm authored Apr 26, 2024
1 parent 08d2a2e commit 75d3b80
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 2 deletions.
12 changes: 12 additions & 0 deletions lib/src/models/config/editor/editor_configurations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -369,6 +379,7 @@ class QuillEditorConfigurations extends Equatable {
QuillController? controller,
String? placeholder,
bool? readOnly,
bool? checkBoxReadOnly,
bool? disableClipboard,
bool? scrollable,
double? scrollBottomInset,
Expand Down Expand Up @@ -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,
Expand Down
10 changes: 10 additions & 0 deletions lib/src/models/config/raw_editor/raw_editor_configurations.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions lib/src/widgets/editor/editor.dart
Original file line number Diff line number Diff line change
Expand Up @@ -235,6 +235,7 @@ class QuillEditorState extends State<QuillEditor>
scrollBottomInset: configurations.scrollBottomInset,
padding: configurations.padding,
readOnly: configurations.readOnly,
checkBoxReadOnly: configurations.checkBoxReadOnly,
disableClipboard: configurations.disableClipboard,
placeholder: configurations.placeholder,
onLaunchUrl: configurations.onLaunchUrl,
Expand Down
4 changes: 3 additions & 1 deletion lib/src/widgets/quill/text_block.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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 <String>[],
Expand All @@ -100,6 +101,7 @@ class EditableTextBlock extends StatelessWidget {
final bool clearIndents;
final Function(int, bool) onCheckboxTap;
final bool readOnly;
final bool? checkBoxReadOnly;
final List<String> customLinkPrefixes;

@override
Expand Down Expand Up @@ -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,
);
Expand Down
4 changes: 3 additions & 1 deletion lib/src/widgets/raw_editor/raw_editor_state.dart
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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,
);
Expand Down

0 comments on commit 75d3b80

Please sign in to comment.