mardi 27 novembre 2018

How to build widgets based on if-else statement?

I need to build a widget based on the data as example shown below. I need to run the CircularProgressIndicator first. My problem is that I need to get data from Server 1. If Server 1 has no data stop CircularProgressIndicator and show “No Registration Found” Widget. If Server 1 has data then get details data from Server 2. If Server 2 has no data show “Temporarily Data is not available” Widget. If Server 2 has Data then show "Server 2 Data Widget"

Run loading animation widget (CircularProgressIndicator)
    - Get Data from Server 1
        - If Server 1 Data is okay
            - Get Data from Server 2 using Server 1 Data item value
                - If Server 2 Data is okay
                    - Show Server 2 Data Widget
                - Else
                    - Show “Temporarily Data is not available” Widget
       - Else
            - Show “No Registration Found” Widget

I try to create a Boolean variable and in main build Widget I try to show the page. But I am keep getting error and keep shows the “No Registration Found” Widget and few seconds later when I ger Server 2 Data using setState it shows the "Server 2 Data Widget". But it never shows the CircularProgressIndicator. Any idea how to build the widgets base on the if else statement as I explained above.

bool _runLoading = true;
bool _data1 = false;
bool _data2 = false;

    return _runLoading == true
        ? _buildLoadingAnimation
        : _data2 == true
          ? _buildServer2Data
          : _buildNoDataFound

Aucun commentaire:

Enregistrer un commentaire