'How to display only one of the two widgets using Getx?

i have a listView and a submit form.When the data was received from the server, if the list was empty, the form must be displayed, otherwise the listView will be displayed. my screen:

Scaffold(
    body:Column(
    children: [
            AddBlockItem<T>()
            ProjectBlockList<T>(),
    ],
  );
  );

AddBlockItem is my submit form and ProjectBlockList is my listView.

my controller:

class AddProjectBlockController extends ModifyProjectBlockController {


 final AddProjectBlockRepository _repository = AddProjectBlockRepository();
     @override
  void onInit() {
    super.onInit();
    
    getProjectBlocks();
  }

}

 @override
  Future<void> getProjectBlocks() async {
    final resultOrException =
        await _repository.getBlocksByProjectId(_addProjectController.projectId);

    return resultOrException.fold(
      (final exception) => projectBlockList.showError(true),
      (final result) {
        projectBlockList.key.currentState?.addAll(result.elements);

        if (result.elements.length < 15) {
          projectBlockList.hasMoreData.value = false;
        } else {
          projectBlockList.offset++;
        }
      },
    );
  }

ModifyProjectBlockController extends GetxController.



Solution 1:[1]

Refer this code. getx_controller_example I have displayed an image when no data found otherwise I have displayed a listview.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 DholaHardik