flutter_network_image 0.0.8 flutter_network_image: ^0.0.8 copied to clipboard
flutter package that provides an ImageProvider automatically retries failed network image loads, ensuring smooth image loading on mobile and web platforms.
import 'package:flutter/material.dart';
import 'package:flutter_network_image/flutter_network_image.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter network image demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: const Text('Flutter network image demo'),
),
body: Center(
child: Image(
width: 300,
height: 300,
fit: BoxFit.cover,
image: NetworkImageProvider(
'https://example.com/image.png',
retryWhen: (Attempt attempt) => attempt.counter < 10,
),
frameBuilder: (context, child, frame, wasSynchronouslyLoaded) {
if (frame != null) {
return child;
}
return const CircularProgressIndicator();
},
errorBuilder: (context, error, stackTrace) {
return const Text('Loading image failed!');
},
),
),
),
);
}
}