0

ストアで何かが変更されたときに TextEditingController のテキストを更新しようとしています。フローは次のとおりです。ユーザーがバーコードをスキャンし、スキャンしたバーコードをテキストフィールドに表示する必要があります。このフィールドに手動でバーコードを入力して店舗に渡すオプションもあります。そのため、コントローラーが必要です。

ウィジェット

  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),
              ),
            ),
          )

店舗

String setBarcodeReceivedFromDevice(String barcodeToCheck) {
    return barcodeToCheck;
  }

テキストは更新されません。助けてください!

4

0 に答える 0