Forked from fedotxxl/flutter_preloading_image_builder.dart
Created
January 24, 2022 14:37
-
-
Save TEGRAXD/e19a8915a3534d7a3e4982561fc0f251 to your computer and use it in GitHub Desktop.
This file contains hidden or 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