Created
July 6, 2020 21:25
-
-
Save fedotxxl/aa03b152fdc2e3c5d3573e2a656acfb2 to your computer and use it in GitHub Desktop.
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/widgets.dart'; | |
class PreloadingImageBuilder extends StatefulWidget { | |
final ImageProvider imageProvider; | |
final AsyncWidgetBuilder<dynamic> builder; | |
PreloadingImageBuilder({this.imageProvider, this.builder}); | |
@override | |
_PreloadingImageBuilderState createState() => _PreloadingImageBuilderState(); | |
} | |
class _PreloadingImageBuilderState extends State<PreloadingImageBuilder> { | |
Future future; | |
@override | |
void didChangeDependencies() { | |
super.didChangeDependencies(); | |
if (this.future == null) { | |
this.future = precacheImage(this.widget.imageProvider, context).then((value) => true); | |
} | |
} | |
@override | |
Widget build(BuildContext context) { | |
return FutureBuilder( | |
future: this.future, | |
builder: this.widget.builder, | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment