Skip to content

Commit aad50ef

Browse files
author
ws
committed
fix crash when entering 000 and pressing +
1 parent d7dce29 commit aad50ef

File tree

2 files changed

+10
-2
lines changed

2 files changed

+10
-2
lines changed

lib/src/base_spin_box.dart

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -141,8 +141,8 @@ mixin SpinBoxMixin<T extends BaseSpinBox> on State<T> {
141141
_controller.value = _controller.value.copyWith(
142142
text: text,
143143
selection: selection.copyWith(
144-
baseOffset: selection.baseOffset - oldOffset + newOffset,
145-
extentOffset: selection.extentOffset - oldOffset + newOffset,
144+
baseOffset: (selection.baseOffset - oldOffset + newOffset).clamp(0, text.length),
145+
extentOffset: (selection.extentOffset - oldOffset + newOffset).clamp(0, text.length),
146146
),
147147
);
148148
}

test/test_spinbox.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -231,6 +231,14 @@ void testInput<S>(TestBuilder builder) {
231231
expect(tester.state(find.byType(S)), hasValue(21));
232232
expect(find.editableText, hasNoSelection);
233233
expect(find.editableText, hasText('21'));
234+
235+
tester.testTextInput.enterText('000');
236+
await tester.idle();
237+
await tester.tap(find.byIcon(TestIcons.increment));
238+
await tester.pumpAndSettle();
239+
expect(tester.state(find.byType(S)), hasValue(1));
240+
expect(find.editableText, hasNoSelection);
241+
expect(find.editableText, hasText('1'));
234242
});
235243

236244
testWidgets('submit', (tester) async {

0 commit comments

Comments
 (0)