Skip to content

Assert issue when starting from negative value #98

@D4n4m1

Description

@D4n4m1

Hello, i have noticed the same issue. The Source Code where it happens is here, within SpinBoxMixin of the base_spin_box.dart file in the Function :

void _updateController(double oldValue, double newValue) {
  final text = _formatText(newValue);
  final selection = _controller.selection;
  final oldOffset = value.isNegative ? 1 : 0;
  final newOffset = _parseValue(text).isNegative ? 1 : 0;

  _controller.value = _controller.value.copyWith(
    text: text,
    selection: selection.copyWith(
      baseOffset: selection.baseOffset - oldOffset + newOffset, <--  have to be >=-1
      extentOffset: selection.extentOffset - oldOffset + newOffset, <-- have to be >=-1
    ),
  );
}

"The initial selection is TextSelection.collapsed(offset: -1)." => selection.baseOffset = -1.
So, if the value < 0 is negative, then oldOffset = 1, and if the newValue = 0 so the newOffset = 0. summing it up, ends with baseOffset = -2 and analog extentOffset = -2.

The fix would be, to check it.

const TextRange({
    required this.start,
    required this.end,
  }) : assert(start >= -1),
       assert(end >= -1);

Originally posted by @D4n4m1 in #19 (comment)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions