Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

flutter CachedNetworkImage doesn't work as expected

Tags:

flutter

I'm trying to work with cached images. I followed this https://flutter.dev/docs/cookbook/images/cached-images, but it doesn't work.

CachedNetworkImage throws error: "The argument type 'CircularProgressIndicator' can't be assigned to the parameter type '(BuildContext, String) → Widget'. (argument_type_not_assignable at [hello2] lib/main.dart:21)"

Below is the problem code:

import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';

void main() {
  runApp(MyApp());
}

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    final title = 'Cached Images';

    return MaterialApp(
      title: title,
      home: Scaffold(
        appBar: AppBar(
          title: Text(title),
        ),
        body: Center(
          child: CachedNetworkImage(
            placeholder: CircularProgressIndicator(),
            imageUrl:
            'https://picsum.photos/250?image=9',
          ),
        ),
      ),
    );
  }
}
```dart

like image 665
hu2ren Avatar asked Aug 26 '26 23:08

hu2ren


1 Answers

Reinstall your application and then Run again, It worked for me

CachedNetworkImage(
            placeholder: (context, url) => CircularProgressIndicator(),
            imageUrl: 'https://picsum.photos/250?image=9',
          )
like image 59
samad shukr Avatar answered Aug 28 '26 12:08

samad shukr



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!