rrousselGit / provider

InheritedWidgets, but simple
https://pub.dev/packages/provider
MIT License
5.11k stars 512 forks source link

Records not supported on WASM #890

Open putnokiabel opened 2 months ago

putnokiabel commented 2 months ago

Describe the bug When using a provider with a record type (e.g. typedef ExampleRecord = ({String name});), the provider is not found when compiling to WASM.

To Reproduce

  1. Create a new Flutter project with web support.
  2. Run flutter pub add provider
  3. Replace main.dart with the following:
    
    import 'package:flutter/material.dart';

import 'package:provider/provider.dart';

typedef Record = ({String name});

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

class MyApp extends StatelessWidget { const MyApp({super.key});

// This widget is the root of your application. @override Widget build(BuildContext context) { return Provider.value( value: (name: 'Hello, World!'), child: const MaterialApp( home: MyHomePage(), ), ); } }

class MyHomePage extends StatefulWidget { const MyHomePage({super.key});

@override State createState() => _MyHomePageState(); }

class _MyHomePageState extends State { @override Widget build(BuildContext context) { print('build 0'); final record = context.read(); print('build 1');

return Scaffold(
  body: Center(
    child: Text(record.name),
  ),
);

} }



4. Run `flutter run -d chrome --wasm` to run the app on Chrome using WASM.
5. Note that the page cannot be built, and `build 0` is printed to the console but `build 1` is not.
6. Note that running the project with the exact same code works on web (e.g. `flutter run -d chrome`) as well as on Android and iOS but not on WASM.

**Expected behavior**
I expected the provider to be found just like it is on CanvasKit, Android, iOS, etc.

Not sure if this is a bug within just Provider, or it's something deeper related to the Flutter framework itself.
rrousselGit commented 2 months ago

That's most definitely an SDK issue, not a provider bug.

putnokiabel commented 2 months ago

Thank you @rrousselGit ! In that case, could you help me submit an issue for this on https://github.com/flutter/flutter , or help construct a code example without the use of Provider? Unfortunately I'm not sure how this example would translate to the underlying APIs of the Flutter SDK.

rrousselGit commented 2 months ago

I don't really have the time for this, sorry.

I'd suggest trying to keep your example as is. It's probably small enough.