flutter_network_image 0.0.6+1 flutter_network_image: ^0.0.6+1 copied to clipboard
flutter package that provides a robust ImageProvider that 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 StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
appBar: AppBar(
title: const Text('Flutter Demo'),
),
body: Center(
child: Image(
image: NetworkImageProvider(
'https://example.com/image.png',
retryWhen: (Attempt attempt) => attempt.counter < 10,
),
loadingBuilder: (context, child, loadingProgress) {
if (loadingProgress == null) {
return child;
}
return CircularProgressIndicator(
value: loadingProgress.cumulativeBytesLoaded /
(loadingProgress.expectedTotalBytes ?? 1),
);
},
width: 300,
),
),
),
);
}
}