Skip to content

Instantly share code, notes, and snippets.

@fedotxxl
Created July 6, 2020 21:19
Show Gist options
  • Save fedotxxl/29dc358df3a182c6c986b212df29e1f9 to your computer and use it in GitHub Desktop.
Save fedotxxl/29dc358df3a182c6c986b212df29e1f9 to your computer and use it in GitHub Desktop.
import 'package:evtrip/utils/my_future_nullable_builder.dart';
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);
}
}
@override
Widget build(BuildContext context) {
return MyFutureNullableBuilder(
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