rrousselGit / riverpod

A reactive caching and data-binding framework. Riverpod makes working with asynchronous code a breeze.
https://riverpod.dev
MIT License
5.82k stars 888 forks source link

Generics in Notifier generated #3490

Open Arpit1496 opened 1 month ago

Arpit1496 commented 1 month ago

II am on latest dev branch of riverpod generator and yet I am facing issues for generics. The code builder leaves "Generics" in 2 functions:

1). _copyWith: The create Function parameter does not consider Generics and generates a compile time error.

ListBlocProvider _copyWith( ListBloc Function() create, )

2). == override: The first condition of == does not consider generics and hence 2 objects are never equal and generate a compile time error.

@override bool operator ==(Object other) { return other is ListBlocProvider && other.runtimeType == runtimeType && other.getData == getData; }

A sample error message is added for better understanding.

THIS IS WHAT "SHOULD" BE GENERATED: image

BUT THIS IS WHAT IS GENERATED: image

rrousselGit commented 1 month ago

Please share your provider definition. The generated code isn't useful to me without seeing the code that generated this.

Arpit1496 commented 1 month ago

BASE:

image

import 'package:astra_ui/state/list_state.dart'; import 'package:fast_immutable_collections/fast_immutable_collections.dart'; import 'package:riverpod_annotation/riverpod_annotation.dart';

part 'test.g.dart';

typedef ListDataGetter<Model, Sort, Cursor> = Future<(IList, Cursor)> Function({ Map<String, dynamic> filters, Sort? sort, Cursor? cursor, });

@riverpod class ListBloc<Model, Sort, Cursor> extends _$ListBloc<Model, Sort, Cursor> { @override ListState<Model, Sort, Cursor> build({ required String type, required ListDataGetter<Model, Sort, Cursor> getData, String? parentId, }) { return ListState<Model, Sort, Cursor>( data: [].lock, loading: true, parentId: parentId, ); } }