Durante a aula, o Kako passou o TaskInherited para home:
home: TaskInherited(child: const InitialScreen()),
E depois passou a lista de tasks para o ListView da Initial_screen:
body: ListView(
children: const TaskInherited.of(context).taskList,
),
Porém esse "of" que recebe um "context" não existe como construtor do TaskInherited. Eu recebo sempre essa mensagem aqui:
Aqui está o meu TaskInherited:
import 'package:flutter/material.dart';
import 'package:my_flutter_project/components/task.dart';
class TaskInherited extends InheritedWidget {
TaskInherited({
super.key,
required Widget child,
}) : super(child: child);
final List<Task> taskList = [
Task('Aprender Flutter', 'assets/images/dash.png', 5),
Task('Andar de Bike', 'assets/images/bike.webp', 3),
Task('Meditar', 'assets/images/meditar.jpeg', 4),
Task('Ler', 'assets/images/livro.jpg', 1),
Task('Jogar', 'assets/images/jogar.jpg', 2),
];
void newTask (String name, String photo, int difficulty){
taskList.add(Task(name, photo, difficulty));
}
static TaskInherited of(BuildContext context) {
final TaskInherited? result =
context.dependOnInheritedWidgetOfExactType<TaskInherited>();
assert(result != null, 'No TaskInherited found in context');
return result!;
}
@override
bool updateShouldNotify(TaskInherited oldWidget) {
return oldWidget.taskList.length != taskList.length;
}
}