0

I need to realise row of TextField widgets. I did it. But now I want to get actual value TextEditingController from State my TextField. How I can do this?

Its my Stateful widget:

class _UnRecognition extends StatefulWidget {
  final String text;
  const _UnRecognition({Key? key, required this.text}) : super(key: key);

  @override
  State<StatefulWidget> createState() => _UnRecognitionState();
}

class _UnRecognitionState extends State<_UnRecognition> {
  final TextEditingController editWordController = TextEditingController();

  @override
  void initState() {
    editWordController.text = widget.text;
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return IntrinsicWidth(
      child: TextField(
        controller: editWordController,
      ),
    );
  }

Its, where i want to use my variable:

 void _SomeMethodOutsideWidget() {
    for (var obj in ListOfWidget) {
       if (obj is _UnRecognition) {
        **this I get access obj.editWordController.text**          
    }
  }
}
Борис
  • 13
  • 2

1 Answers1

0

you need to learn the providers: https://pub.dev/packages/provider

basically it is used to retrieve values ​​in the contexts of Statefull Widgets

you can find many tutorial of state managment provider on youtube

karak002
  • 36
  • 5