简体   繁体   中英

iget the following error while using the flutter Provider widget

    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'),

                        ];
                        }

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(),
      ),
    );
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM