Skip to content

Feature: Add checkBoxReadOnly property which can override readOnly for checkbox #249

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion lib/doc-tree/services/doc-tree.service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ class DocTreeService {

// Updates the checkbox positioned at [offset] in document by changing its attribute according to [value].
void _handleCheckboxTap(int offset, bool value) {
if (!state.config.readOnly) {
if (!(state.config.checkBoxReadOnly ?? state.config.readOnly)) {
state.scrollAnimation.disabled = true;
final attribute = value ? AttributesAliasesM.checked : AttributesAliasesM.unchecked;

Expand Down
4 changes: 2 additions & 2 deletions lib/doc-tree/widgets/editable-text-block.dart
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ class EditableTextBlock extends StatelessWidget {
return CheckboxPoint(
size: 14,
value: true,
enabled: !_state.config.readOnly,
enabled: !(_state.config.checkBoxReadOnly ?? _state.config.readOnly),
onChanged: (checked) => onCheckboxTap(lineOffset, checked),
uiBuilder: styles.lists?.checkboxUIBuilder,
);
Expand All @@ -228,7 +228,7 @@ class EditableTextBlock extends StatelessWidget {
return CheckboxPoint(
size: 14,
value: false,
enabled: !_state.config.readOnly,
enabled: !(_state.config.checkBoxReadOnly ?? _state.config.readOnly),
onChanged: (checked) => onCheckboxTap(lineOffset, checked),
uiBuilder: styles.lists?.checkboxUIBuilder,
);
Expand Down
9 changes: 9 additions & 0 deletions lib/editor/models/editor-cfg.model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ class EditorConfigM {
// The text remains selectable.
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 `true`, the checkbox cannot be checked or unchecked while [readOnly] is set to `false`.
// When this is set to `null`, the [readOnly] value is used.
final bool? checkBoxReadOnly;

// Content to be displayed when there is no content in the Delta document
final String? placeholder;

Expand Down Expand Up @@ -198,6 +204,7 @@ class EditorConfigM {
this.padding = EdgeInsets.zero,
this.autoFocus = false,
this.readOnly = false,
this.checkBoxReadOnly,
this.expands = false,
this.paintCursorAboveText,
this.placeholder,
Expand Down Expand Up @@ -254,6 +261,7 @@ class EditorConfigM {
bool? autoFocus,
bool? paintCursorAboveText,
bool? readOnly,
bool? checkBoxReadOnly,
String? placeholder,
bool? enableInteractiveSelection,
double? minHeight,
Expand Down Expand Up @@ -299,6 +307,7 @@ class EditorConfigM {
autoFocus: autoFocus ?? this.autoFocus,
paintCursorAboveText: paintCursorAboveText ?? this.paintCursorAboveText,
readOnly: readOnly ?? this.readOnly,
checkBoxReadOnly: checkBoxReadOnly ?? this.checkBoxReadOnly,
placeholder: placeholder ?? this.placeholder,
enableInteractiveSelection: enableInteractiveSelection ?? this.enableInteractiveSelection,
minHeight: minHeight ?? this.minHeight,
Expand Down