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
class MyWidget extends HookWidget { | |
@override | |
Widget build(BuildContext context) { | |
final future = useMemoized(() { | |
// Future<String> callAsyncFetch() => Future.delayed(Duration(seconds: 3), () => "hi bro"); | |
callAsyncFetch(); // or your own async function | |
}); | |
return FutureBuilder<String>( | |
future: future, | |
builder: (context, snapshot) { |
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
class MyWidget extends StatelessWidget { | |
// Future<String> callAsyncFetch() => Future.delayed(Duration(seconds: 3), () => "hi bro"); | |
@override | |
Widget build(BuildContext context) { | |
// print('building widget'); | |
return FutureProvider<String>( | |
create: (_) { | |
// print('calling future'); | |
return callAsyncFetch(); | |
}, |
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'; | |
main() { | |
runApp(MyApp()); | |
} | |
class MyApp extends StatelessWidget { | |
@override | |
Widget build(context) { | |
return StreamBuilder<void>( |
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
// FutureBuilder *is* a stateful widget | |
class FutureBuilder<T> extends StatefulWidget { | |
// it takes in a `future` and a `builder` | |
const FutureBuilder({ | |
this.future, | |
this.builder | |
}); | |
final Future<T> future; |
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(home: Scaffold(body: Center(child: MyWidget())))); | |
Future<String> callAsyncFetch() => | |
Future.delayed(Duration(seconds: 3), () => "hi bro !"); | |
class MyWidget extends StatelessWidget { |
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(home: Scaffold(body: Center(child: MyWidget())))); | |
Future<String> callAsyncFetch() => | |
Future.delayed(Duration(seconds: 3), () => "hi bro !"); | |
class MyWidget extends StatelessWidget { |
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(home: Scaffold(body: Center(child: MyWidget())))); | |
Future<String> callAsyncFetch() => | |
Future.delayed(Duration(seconds: 3), () => "hi bro !"); | |
class MyWidget extends StatelessWidget { | |
@override |