What are Future Operations?
Future operations is nothing but operations will take time to execute and return result in the future
So what we need to do in that time of execution?
We can overcome this problem by using asynchronous operations. To handle this operations we can use dart Async/await methods.
Will it possible to apply Asyn/await on widget?
To apply Async/await on widgets is tricky, to overcome this flutter introduced Future Builder widget.
Future builder will calls the future function to wait for the result, and as soon as it produces the result it calls the builder function where we build the widget
The Future builder result has AsyncSnapshot object
This AsyncSnapshot has 3 states
Sample of Future Builder
class FutureWidget extends StatefulWidget { var random = Random(); for (int i = 0; i < 2000; i++) { Future<String> createFutureCalculation(int count) { @override class FutureWidgetState extends State<FutureWidget> { void _onInvokeFuturePressed() { }); @override builder: (BuildContext context, AsyncSnapshot snapshot) { |
Article Contributed By :
|
|
|
|
1676 Views |