| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283 |
- import 'package:flutter/material.dart';
- import 'package:flutter_bloc/flutter_bloc.dart';
- import 'src/bloc/cashed_image_bloc.dart'
- show
- CashedImageBloc,
- CashedImageGetErrorState,
- CashedImageGetState,
- CashedImageState,
- GetStartImageEvent;
- class CachedNetworkImageWidget extends StatelessWidget {
- final String imageUrl;
- final int count;
- final BoxFit fit;
- final double? width;
- final double? height;
- final Widget? placeholder;
- final Widget? errorWidget;
- final bool cached;
- final String? cachkey;
- final Widget? loadwidget;
- const CachedNetworkImageWidget({
- super.key,
- required this.imageUrl,
- required this.cachkey,
- required this.fit,
- this.count = 10,
- this.height,
- this.width,
- this.errorWidget,
- this.placeholder,
- this.cached = true,
- this.loadwidget = const CircularProgressIndicator(),
- });
- @override
- Widget build(BuildContext context) {
- return BlocProvider(
- create: (context) => CashedImageBloc()
- ..add(
- GetStartImageEvent(
- url: imageUrl,
- cached: cached,
- count: count,
- cachkey: cachkey,
- ),
- ),
- child: Builder(
- builder: (context) {
- return BlocBuilder<CashedImageBloc, CashedImageState>(
- builder: (context, state) {
- if (state is CashedImageGetErrorState) {
- return SizedBox(
- width: width,
- height: height,
- child: errorWidget ?? Center(child: Icon(Icons.error)),
- );
- }
- if (state is CashedImageGetState) {
- return Image.memory(
- state.bytes,
- fit: fit,
- width: width,
- height: height,
- );
- }
- return SizedBox(
- width: width,
- height: height,
- child:
- placeholder ?? Center(child: CircularProgressIndicator()),
- );
- },
- );
- },
- ),
- );
- }
- }
|