Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ImageProvider generated as InvalidType #3525

Closed
yakou32 opened this issue May 4, 2024 · 4 comments
Closed

ImageProvider generated as InvalidType #3525

yakou32 opened this issue May 4, 2024 · 4 comments
Assignees
Labels
bug Something isn't working needs triage

Comments

@yakou32
Copy link

yakou32 commented May 4, 2024

Bug description
I'm using Flutter Riverpod 2.4.9 to generate an ImageProvider object (either FileImage, AssetImage, NetworkImage...), according to some variable.

The generator doesn't compile correctly, the ImageProvider type being replaced by InvalidType.

To Reproduce

Here is a simplified code to reproduce:

// test.dart

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

part 'test.g.dart';

@riverpod
ImageProvider testImage(TestImageRef ref) {
  return const AssetImage('some_valid_path');
}

Expected behavior
The generated file should look like
final testImageProvider = AutoDisposeProvider<ImageProvider>.internal(...
instead of
final testImageProvider = AutoDisposeProvider<InvalidType>.internal(...

Workaround
At the moment, I replace the current type by hand in the generate file.

It is obviously a tedious task; best would be to fix the ImageProvider compatibility issue instead.

Is it because the object class name ImageProvider would interfere with any Riverpod logic?

@yakou32 yakou32 added bug Something isn't working needs triage labels May 4, 2024
@snapsl
Copy link

snapsl commented May 4, 2024

Have you tried Raw<ImageProvider>?

@yakou32
Copy link
Author

yakou32 commented May 4, 2024

Thanks @snapsl I was not aware of that Raw type.

However, it doesn't solve the issue.
Indeed, in the simplified example, there is no Stream nor Future that Raw would disable...

@rrousselGit
Copy link
Owner

This is a known issue with various types.
Only 3.0 fixes the issue, and the fix won't be added to 2.0

@yakou32
Copy link
Author

yakou32 commented May 6, 2024

That's great!

Thank you so much Rémi!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working needs triage
Projects
None yet
Development

No branches or pull requests

3 participants