pmatatias / input-quantity

Flutter widget for input quantity item
https://pub.dev/packages/input_quantity
MIT License
12 stars 13 forks source link

How about setting value outside widget? #45

Closed WiRight closed 10 months ago

WiRight commented 10 months ago

In my case i getting new value from another place (for example: websocket) And setting value as initVal has no effect

How set new value outside? (Something like controller?)

pmatatias commented 10 months ago

Hi @WiRight, thank you for submitting the issue.

I think it is caused because the widget is not rebuilt. so initVal doesn't change. for a simple solution, you can force rebuild the InputQty widget every time it receives a new initVal value. to do that, just specify the key property.

InputQty(
    key: ValueKey("$streamedInitVal"), // every different value key will force to rebuild the widget.
    initVal: streamedInitVal,
  ),

I will try to develop a new feature to extract TexteditingController, so that it is available from outside the package. but it may take time

WiRight commented 10 months ago

@pmatatias hey and thanks for the quick response! using key solved my problem now!

pmatatias commented 10 months ago

Glad to help. I'll mark it as closed for now.