3

I'm building a flutter gallery app from this reference Flutter Image Gallery

All works fine but I'm getting error inside Future Builder

This is the error warning I'm getting

The name 'Uint8List' isn't a type so it can't be used as a type argument.
Try correcting the name to an existing type, or defining a type named 'Uint8List'.

And this is the runtime error I'm getting

Error: 'Uint8List' isn't a type.
    return FutureBuilder<Uint8List>(
                         ^^^^^^^^^

This Uint8List is totally new concept for me, don't know what to do.

This is the widget that returns a Future Builder

  @override
  Widget build(BuildContext context) {
    // We're using a FutureBuilder since thumbData is a future
    return FutureBuilder<Uint8List>(
      future: asset.thumbData,
      builder: (_, snapshot) {
        final bytes = snapshot.data;
        // If we have no data, display a spinner
        if (bytes == null) return CircularProgressIndicator();
        // If there's data, display it as an image
        return InkWell(
          onTap: () {
            // TODO: navigate to Image/Video screen
          },
          child: Stack(
            children: [
              // Wrap the image in a Positioned.fill to fill the space
              Positioned.fill(
                child: Image.memory(bytes, fit: BoxFit.cover),
              ),
              // Display a Play icon if the asset is a video
              if (asset.type == AssetType.video)
                Center(
                  child: Container(
                    color: Colors.blue,
                    child: Icon(
                      Icons.play_arrow,
                      color: Colors.white,
                    ),
                  ),
                ),
            ],
          ),
        );
      },
    );
  }

I've search it on google but doesn't get any satisfied answer. Thanks in advance.

You and the web
  • 195
  • 3
  • 12

2 Answers2

2

try this solution:

FutureBuilder<Uint8List>

to

FutureBuilder<dynamic>

or

FutureBuilder<List<int>>
Mahmoud Salah Eldin
  • 1,739
  • 16
  • 21
1

Just leave out the type, the compiler is smart enough to infer that from the type of Future<> you provide:

FutureBuilder(
    future: asset.thumbData,
nvoigt
  • 75,013
  • 26
  • 93
  • 142
  • Yes i appreciate your answer. Can you please briefly explain that why we should not need `` – You and the web Mar 06 '21 at 10:43
  • 1
    I indirectly already did. It is called "type inference", most languages can do that. If you have for example a method `method(T t)`, then when you pass in an `int`, you can just do `method(5)` instead of `method(5)` because the compiler already inferred from your usage that you mean `int`. See https://dart.dev/guides/language/type-system#type-inference – nvoigt Mar 06 '21 at 10:46