Answers for "does flutter have a future"

12

flutter future builder

FutureBuilder<String>(
        future: _fetchNetworkCall, // async work
        builder: (BuildContext context, AsyncSnapshot<String> snapshot) {
           switch (snapshot.connectionState) {
             case ConnectionState.waiting: return Text('Loading....');
             default:
               if (snapshot.hasError)
                  return Text('Error: ${snapshot.error}');
               else
              return Text('Result: ${snapshot.data}');
            }
         },
        ),
Posted by: Guest on October-28-2020
1

flutter future

// Step 1: Set the variable in future<void>
// Step 2: Make sure to use the variable on
// async void who await the future

String? test;
Future<void> fetchUserOrder() {
  // Imagine that this function is fetching user info from another service or database.
  return Future.delayed(const Duration(seconds: 1), () => test = "Large Latte");
}

void main() async {
  await fetchUserOrder();
  print('Fetching user order... $test');
}
Posted by: Guest on August-04-2021

Code answers related to "Dart"

Browse Popular Code Answers by Language