Minha tela inicial
import 'package:alura_flutter_curso_1/data/task_inherited.dart';
import 'package:alura_flutter_curso_1/screens/form_screen.dart';
import 'package:flutter/material.dart';
class InitialScreen extends StatefulWidget {
const InitialScreen({Key? key}) : super(key: key);
@override
State<InitialScreen> createState() => _InitialScreenState();
}
class _InitialScreenState extends State<InitialScreen> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Flutter: Primeiros Passos'),
leading: Icon(Icons.add_task),
),
body: Container(
color: Color.fromARGB(255, 208, 221, 237),
child: ListView(
children: TaskInherited.of(context).taskList,
),
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.push(
context, MaterialPageRoute(builder: (context) => FormScreen()));
},
backgroundColor: Colors.blue[100],
child: const Icon(Icons.add),
),
);
}
}
meu main que esta com erro na hom...
void main() {
runApp(const MyApp());
}
class MyApp extends StatefulWidget {
const MyApp({Key? key}) : super(key: key);
@override
State<MyApp> createState() => _MyAppState();
}
class _MyAppState extends State<MyApp> {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: TaskInherited(child: const InitialScreen(),),
);
}
}
e meu task inherited
class TaskInherited extends InheritedWidget {
TaskInherited({super.key, required this.child}) : super(child: child);
final TaskInherited child;
final List<Tasks> taskList = [
Tasks('Estudar Flutter', 'assets/images/flutter.png', 3),
Tasks('Andar de Bike', 'assets/images/bike.webp', 2),
Tasks('Ler 50 páginas', 'assets/images/ler.jpg', 1),
Tasks('Meditar', 'assets/images/meditar.jpeg', 4),
Tasks('Jogar', 'assets/images/jogar.jpg', 0),
];
void newTasks(String name, String image, int difficulty) {
taskList.add(Tasks(name, image, 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;
}
}