Reputation: 25
The argument type 'Widget Function(BuildContext)' can't be assigned to the parameter type 'Widget
Function(BuildContext, Widget)'.
I get the following error while I am using the provider widget in the flutter
import 'package:todoey_flutter/Screens/tasks_screens.dart';
import 'package:todoey_flutter/models/task_data.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
builder: (context)=> TaskData(),
child: MaterialApp(
home:TasksScreen(),
),
);
}
}
The following is the code in the file containing this TaskData class
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'task.dart';
class TaskData extends ChangeNotifier{
List<Task> tasks =[
Task(name: 'buy milk'),
Task(name:'buy eggs'),
Task(name: 'buy bread'),
];
}
Upvotes: 0
Views: 105
Reputation: 54367
https://pub.dev/packages/provider#migration-from-v3x0-to-v400
builder
of classical providers
should be replaced by create
.
You can change builder
to create
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return ChangeNotifierProvider(
create: (context) => TaskData(),
child: MaterialApp(
home: TasksScreen(),
),
);
}
}
Upvotes: 1