Created
May 11, 2023 09:53
-
-
Save MelbourneDeveloper/2a18928df560681d150a49c8f913c1f0 to your computer and use it in GitHub Desktop.
Switch Expression Example
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/material.dart'; | |
void main() => runApp( | |
MaterialApp( | |
debugShowCheckedModeBanner: false, | |
home: Scaffold( | |
body: Center( | |
child: FutureBuilder( | |
future: Future<String>.delayed( | |
const Duration(seconds: 3), () => 'Hello World!'), | |
builder: (context, snapshot) => switch (snapshot) { | |
AsyncSnapshot(hasData: true, data: final d) => Text(d!), | |
AsyncSnapshot(hasError: true) => const Text('Error'), | |
AsyncSnapshot() => const CircularProgressIndicator.adaptive() | |
}, | |
), | |
), | |
), | |
), | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment