Skip to content

Commit

Permalink
Fix according to review
Browse files Browse the repository at this point in the history
  • Loading branch information
WinXaito committed Mar 28, 2023
1 parent fa60614 commit 1b275b0
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 12 deletions.
4 changes: 1 addition & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
## [next]

- Add `NumberBox` widget. ([#560](https://github.com/bdlukaa/fluent_ui/issues/560) [#771](https://github.com/bdlukaa/fluent_ui/pull/771))
- Add `min`/`max` properties to the `NumberBox` widget. ([#789](https://github.com/bdlukaa/fluent_ui/pull/789))
- Allow `NumberBox` Widget to accept int and double values and mathematical expressions. ([#789](https://github.com/bdlukaa/fluent_ui/pull/789))
- Add `NumberBox` widget. ([#560](https://github.com/bdlukaa/fluent_ui/issues/560) [#771](https://github.com/bdlukaa/fluent_ui/pull/771) [#789](https://github.com/bdlukaa/fluent_ui/pull/789))
- Add support for `routerConfig` to `FluentApp.router` ([#781](https://github.com/bdlukaa/fluent_ui/issues/781))
- Add source code for `Show InfoBar` in example application. ([#785](https://github.com/bdlukaa/fluent_ui/pull/785))
- Make `color` optional in `FluentApp.router`. ([#782](https://github.com/bdlukaa/fluent_ui/issues/782))
Expand Down
19 changes: 10 additions & 9 deletions lib/src/controls/form/number_box.dart
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@ class NumberBoxState<T extends num> extends State<NumberBox<T>> {
_dismissOverlay();
focusNode!.removeListener(_handleFocusChanged);
_internalNode?.dispose();
controller.dispose();
super.dispose();
}

Expand Down Expand Up @@ -266,7 +267,7 @@ class NumberBoxState<T extends num> extends State<NumberBox<T>> {

if (oldWidget.value != widget.value) {
if (widget.value != null) {
updateController(widget.value!);
_updateController(widget.value!);
} else {
controller.text = '';
}
Expand Down Expand Up @@ -425,34 +426,34 @@ class NumberBoxState<T extends num> extends State<NumberBox<T>> {
void incrementSmall() {
final value = (num.tryParse(controller.text) ?? widget.value ?? 0) +
widget.smallChange;
updateController(value);
_updateController(value);
updateValue();
}

void decrementSmall() {
final value = (num.tryParse(controller.text) ?? widget.value ?? 0) -
widget.smallChange;
updateController(value);
_updateController(value);
updateValue();
}

void incrementLarge() {
final value = (num.tryParse(controller.text) ?? widget.value ?? 0) +
widget.largeChange;
updateController(value);
_updateController(value);
updateValue();
}

void decrementLarge() {
final value = (num.tryParse(controller.text) ?? widget.value ?? 0) -
widget.largeChange;
updateController(value);
_updateController(value);
updateValue();
}

void updateController(num value) {
void _updateController(num value) {
controller
..text = format(value) ?? ''
..text = _format(value) ?? ''
..selection = TextSelection.collapsed(offset: controller.text.length);
}

Expand Down Expand Up @@ -484,7 +485,7 @@ class NumberBoxState<T extends num> extends State<NumberBox<T>> {
value = value?.toDouble();
}

controller.text = format(value) ?? '';
controller.text = _format(value) ?? '';
}
previousValidValue = value;

Expand All @@ -493,7 +494,7 @@ class NumberBoxState<T extends num> extends State<NumberBox<T>> {
}
}

String? format(num? value) {
String? _format(num? value) {
if (value == null) return null;
if (value is int) {
return value.toString();
Expand Down

0 comments on commit 1b275b0

Please sign in to comment.