Closed artandor closed 2 months ago
Hi @artandor , thank you for use this package.
you can listen the value changes from onQtyChanged
InputQty(
maxVal: 100,
initVal: 0,
minVal: -100,
steps: 10,
onQtyChanged: (val) { <<<<<<<<< here
print(val);
},
),
Isn't it a fairly bad practice to setState inside a onChange ? Sorry for the questions, i'm mostly junior with flutter
can you provide any snippet code? i may can help based on your code
For sure, here it is
InputQty.int(
minVal: 10,
maxVal: 100,
initVal: 10,
steps: 10,
onQtyChanged: (quantity) {
setState(() {
_creditsToBuy = quantity;
});
},
messageBuilder:
(num minVal, num maxVal, num? value) {
if (value == null) return null;
if (value > minVal) {
return Text(
"Value must be higher than $minVal",
style: const TextStyle(color: Colors.red),
textAlign: TextAlign.center,
);
} else if (value < maxVal) {
return Text(
'Cannot buy more than $maxVal credits',
style: const TextStyle(color: Colors.red),
textAlign: TextAlign.center,
);
} else {
return null;
}
},
qtyFormProps:
const QtyFormProps(enableTyping: false),
decoration: const QtyDecorationProps(
isBordered: false,
borderShape: BorderShapeBtn.circle,
width: 12)),
in that case, you are right. calling setState will rebuild the widget. actually there is some options
ValueNotifier
read this https://api.flutter.dev/flutter/widgets/ValueListenableBuilder-class.htmlhi @artandor , I just released new version. now you can use your own controller. I will close this issue.
feel free to re-open or raise new issue if you need any helps. Thank you
Hi ! Help needed 😄
I don't understand how to retrieve the value from the field, considering the controller inside of it is private. How can i provide a controller to the field so that i can listen to changes ?
Thanks in advance