I want to remove a content from a Widget based on a conditional logic.
Below is my Widget tree,
return MaterialApp(
    home: Scaffold(
    body: Container(
    margin: EdgeInsets.all(120.0),
    child: Align(
      alignment: Alignment.center,
      child: Column(
        children: <Widget>[
          Text("Loading...");
        ],
      ),
    ),
  ),
));
Lets say I have a variable which fetches value from SharePreferences and if the value is "Hide" then Text widget encapsulated inside must be hidden. Otherwise it should display the text fetched from the SP.
The catch here is that the Text will initially display "Loading..." for a specific duration and then after that it must behave dynamically based on the condition.
I have tried with Timer and setState() but couldn't really make it work. Kindly assist if anyone has a solution for this. 
Jordan Davies is right. You need a FutureBuilder or StreamBuilder.
return MaterialApp(
        home: Scaffold(
      body: Container(
        margin: EdgeInsets.all(120.0),
        child: Center(
            child: FutureBuilder(
                future: Future.delayed(Duration(seconds: 3)),
                builder: (c, s) => s.connectionState == ConnectionState.done
                    ? Text("Loaded")
                    : Text("Loading..."))),
      ),
    ));
Just replace Future.delayed with your function.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With