1

I am trying to update a text in TextEditingController when something changes in store. The flow is: user scans a barcode and I have to show the scanned barcode in a textfield. There is also an option to enter a barcode manually to this field and then pass to the store, that's why I need a controller.

The widget

  final TextEditingController _controller = TextEditingController(text: '');

 @override
  void initState() {
    super.initState();
    this.widget.findMyItemStore.startScanBarcodeWidget();
      _controller.addListener(() {
        this.widget.findMyItemStore.setBarcodeReceivedFromDevice(_controller.text);
    });
  }

@override
  Widget build(BuildContext context) {
    return Padding(
            padding: EdgeInsets.symmetric(horizontal: 0, vertical: 16),
            child: Observer(
              builder: (_) => TextField(
                style: TextStyle(color: CustomColors.text_black),
                controller: _controller,
                onChanged: (String? value) => _onBarcodeTextChanged(value),
                decoration: InputDecoration(border: InputBorder.none, hintText: '1234567890', hintStyle: TextStyle(color: CustomColors.text_grey), fillColor: CustomColors.background_white, filled: true),
              ),
            ),
          )

The store

String setBarcodeReceivedFromDevice(String barcodeToCheck) {
    return barcodeToCheck;
  }

The text is never updated. Please, help!

InnaZis
  • 79
  • 1
  • 2
  • 14

0 Answers0