Skip to content

Instantly share code, notes, and snippets.

@fedotxxl
Created July 6, 2020 21:25
Show Gist options
  • Save fedotxxl/aa03b152fdc2e3c5d3573e2a656acfb2 to your computer and use it in GitHub Desktop.
Save fedotxxl/aa03b152fdc2e3c5d3573e2a656acfb2 to your computer and use it in GitHub Desktop.
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