provider
provider copied to clipboard
Records not supported on WASM
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
- Create a new Flutter project with web support.
- Run
flutter pub add provider
- 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<Record>.value(
value: (name: 'Hello, World!'),
child: const MaterialApp(
home: MyHomePage(),
),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
print('build 0');
final record = context.read<Record>();
print('build 1');
return Scaffold(
body: Center(
child: Text(record.name),
),
);
}
}
- Run
flutter run -d chrome --wasm
to run the app on Chrome using WASM. - Note that the page cannot be built, and
build 0
is printed to the console butbuild 1
is not. - 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.