Answers for "flutter future"

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
0

future as a parameter with async in flutter

FloatingActionButton(
  onPressed: () => getImageFromCam(index),
  tooltip: 'Pick Image',
  child: Icon(Icons.add_a_photo),
);

...

Future<void> getImageFromCam(int index) async {
  // Do whatever you want with `index`.
  final image = await ImagePicker.pickImage(source: ImageSource.camera);
  setState(() => _image = image);
}
Posted by: Guest on December-27-2020

Code answers related to "Dart"

Browse Popular Code Answers by Language