Created
July 25, 2020 06:49
-
-
Save ddikman/8abede8f2d6d6917e7de99bdca7d47a1 to your computer and use it in GitHub Desktop.
A brief overlay progress spinner to use for async functions
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/cupertino.dart'; | |
import 'package:flutter/material.dart'; | |
class LoadingOverlay { | |
BuildContext _context; | |
void hide() { | |
Navigator.of(_context).pop(); | |
} | |
void show() { | |
showDialog( | |
context: _context, | |
barrierDismissible: false, | |
child: _FullScreenLoader()); | |
} | |
Future<T> during<T>(Future<T> future) { | |
show(); | |
return future.whenComplete(() => hide()); | |
} | |
LoadingOverlay._create(this._context); | |
factory LoadingOverlay.of(BuildContext context) { | |
return LoadingOverlay._create(context); | |
} | |
} | |
class _FullScreenLoader extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
decoration: BoxDecoration(color: Color.fromRGBO(0, 0, 0, 0.5)), | |
child: Center(child: CircularProgressIndicator())); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment