Skip to content

Generic TypeDef does not work with custom class #28072

@PandaGeek1024

Description

@PandaGeek1024

Steps to Reproduce

Maybe this is more a dart specific issue, but since I found this while developing flutter app so I decided to post it here. I have written a small example try to reproduce the issue.

So basically I want to create a generic class(Test<T, F>) but with some variable(_cellBuilder) has an external typedef type(CellBuilder<F>) outside the class. testA with String assigned runs fine, but testB failed just as the screenshot shows.

And when I remove <Product> from testB, I get a different error.

type '(Product) => Widget is not a subtype of type (dynamic) => Widget

Quite confusing. Any help please?

image

void main() {

  testA<String>(String content) {
    print(content);
  }

  Widget testB<Product>(Product item) {
    print(item.a);
  }

  testWidgets('Counter increments smoke test', (WidgetTester tester) async {
    Test<int, Product> c = Test(testA, testB);
    c.eval();
  });
}

class Product {
 final String a;
 Product(this.a);
}

typedef CellBuilder<F> = Widget Function(F item);
typedef testString<T>(T text);

class Test<T, F> {
  final testString _f;
  final CellBuilder _cellBuilder;
  Test(testString this._f, CellBuilder this._cellBuilder);
  eval() {
    _f("hello");
    _cellBuilder(Product("world"));
  }
}

Logs

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions