I'm currently working on a Flutter app for user login and registration, and I'm using the GetX state management library and API for this purpose. However, I'm encountering an error, and I'm seeking assistance in resolving it.

[Get] the improper use of a GetX has been detected.
      You should only use GetX or Obx for the specific widget that will be updated.
      If you are seeing this error, you probably did not insert any observable variables into GetX/Obx
      or insert them outside the scope that GetX considers suitable for an update
      (example: GetX => HeavyWidget => variableObservable).
      If you need to update a parent widget and a child widget, wrap each one in an Obx/GetX.

this is my RegisterPage

import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'controller.dart';

class RegisterPage extends StatelessWidget {
  final controller = Get.put(RegisterPageController());

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Register Page"),
      ),
      body: Obx(() => ListView(
            padding: EdgeInsets.all(20),
            children: [
              TextFormField(
                controller: controller.cUsername,
                decoration: InputDecoration(
                  border: OutlineInputBorder(),
                  hintText: "Masukkan Username anda",
                  labelText: "Username",
                ),
              ),
              SizedBox(height: 20),
              TextFormField(
                controller: controller.cPass,
                decoration: InputDecoration(
                  border: OutlineInputBorder(),
                  hintText: "Masukkan Password",
                  labelText: "Password",
                ),
              ),
              SizedBox(height: 20),
              TextFormField(
                controller: controller.cFullname,
                decoration: InputDecoration(
                  border: OutlineInputBorder(),
                  hintText: "Masukkan Nama Lengkap anda",
                  labelText: "Nama Lengkap",
                ),
              ),
              SizedBox(height: 20),
              TextFormField(
                controller: controller.cEmail,
                decoration: InputDecoration(
                  border: OutlineInputBorder(),
                  hintText: "Masukkan Email anda",
                  labelText: "Email",
                ),
              ),
              SizedBox(height: 20),
              ElevatedButton(
                onPressed: () {
                  controller.registerUser();
                },
                child: Text("Register"),
              ),
            ],
          )),
    );
  }
}

and this my code in controller Page

class RegisterPageController extends GetxController {
  TextEditingController? cUsername;
  TextEditingController? cPass;
  TextEditingController? cFullname;
  TextEditingController? cEmail;

  @override
  void onInit() {
    // TODO: implement onInit
    super.onInit();
    cUsername = new TextEditingController();
    cPass = new TextEditingController();
    cFullname = new TextEditingController();
    cEmail = new TextEditingController();
  }

  registerUser() async {
    final baseUrl = 'https://mediadwi.com/api/latihan/register-user';
    final response = await http.post(Uri.parse(baseUrl), body: {
      'username': cUsername?.text,
      'password': cPass?.text,
      'full_name': cFullname?.text,
      'email': cEmail?.text
    });
    try {
      if (response.statusCode == 200) {
        Get.to(() => LoginPage());
        Get.snackbar("Selamat", "Pembuatan akun anda Sukses, ");
      } else {
        Get.snackbar('Maaf', 'Akun anda gagal dibuat');
      }
    } catch (e) {
      print(e);
    }
  }
}

this is my splashscreen https://pastebin.com/YXNpum7e
In my main i connected to my splashscreen

2

There are 2 answers

0
Harsh Moradiya On

You just have to just remove the obx widget because there is no one variable that is obs.

I hope this will help you.

0
MURTUZA ZAFAR On

remove Obx on listview. noted: if your are using reactive variable like .obs so you need to wrap widget from obx