The argument type 'Widget Function(BuildContext)' can't be assigned to the parameter type 'Widget
Function(BuildContext, Widget)'.
在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(),
),
);
}
}
以下是包含TaskData类的文件中的代码
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'),
];
}
答案 0 :(得分:1)
https://pub.dev/packages/provider#migration-from-v3x0-to-v400
经典builder
的{{1}}应该替换为providers
。
您可以将create
更改为builder
create