Search code examples
flutterdartflutter-getx

i have getx improper use error, but i think i used properly controller value


i have flutter(dart) getx improper use error, but i think i used properly controller value An error occurred suddenly (improper use)

the other side, it is used properly,

plz check below codes...

the getx controller

class BoardController extends GetxController {

String title = "".obs();
String org_title = "".obs();
String menu_2cd = "".obs();
String menu_1cd = "".obs();
bool drawer_checked = false.obs();
bool resultdata = false.obs();

@override
void onInit() async {
super.onInit();
}
}

``screen` the error part ocuured

boardController

why the error is occured??????

i used changable values,

class BoardContent extends StatefulWidget {

  String query;
  String doc_cate;
  String title;
  BoardContent({Key? key, required this.title, required this.query, required this.doc_cate}) : super(key: key);

  @override
  State<BoardContent> createState() => _BoardContentState();
}

class _BoardContentState extends State<BoardContent> {
  int currentPage = 1;
  int totalPages = 1;
  late BoardController boardController;

  @override
  void initState() {
    boardController = Get.put(BoardController());


    super.initState();
  }

// i think here is the error part
  @override
  Widget build(BuildContext context) {

    return LayoutBuilder(builder: (context, constraint) {
      return WillPopScope(
          onWillPop: () async {
            return Future.value(false);
          },
          child:
          GetX<BoardController>(builder: (controller){
            return GestureDetector(
                behavior: HitTestBehavior.opaque,
                onTap: () {
                  FocusScope.of(context).unfocus();
                },
                child:  Column(
                  children: [
                    Expanded(flex:1,child: Text('${boardController.title}')),
                  ],
                ));
          },)
      );});}
  }
--should i use the rxstring and obx(()=> widget??

Solution

  • Declare the title variable as:

    RxString title = "".obs;
    

    and you can use it whether with Getx or Obx widget.