skip to Main Content

What I am doing wrong?

import 'package:get/get.dart';
import 'package:flutter/foundation.dart';

class TextControllers extends GetxController {
  Rx<TextEditingController> userInputController = TextEditingController().obs;
}
  • Error: Type ‘TextEditingController’ not found.
    Rx<TextEditingController> userInputController = TextEditingController().obs;

I am using:

dependencies:
  get: ^4.6.5

2

Answers


  1. I think you want to change the text asap text controller has new text.
    for that, you should make an obs String.

    RxString text = ''.obs;
    

    then in the onChanged property, assign the TextField value to it, like this:

    TextField(
        onChanged: (value) {
          text.value = value;
        },
        );
    
    Login or Signup to reply.
  2. maybe you can use this way:

      var sentence = <sentences>[].obs;
      Rx<TextEditingController> titleController =
          TextEditingController(text: "").obs;
    
      @override
      void onReady() {
        getSingleSentence("55");
        super.onReady();
      }
    
      void getSingleSentence(String id) async {
        var tmp = await Api.getSingleEnglish(id);
        sentence.value = [sentences.fromJson(tmp.data)];
        titleController.value =
            TextEditingController(text: sentence[0].original.toString());
      }
    }
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search