flutter_network_image 0.0.5 flutter_network_image: ^0.0.5 copied to clipboard
ImageProvider for flutter with retry mechanism.
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,
),
),
),
);
}
}