Obrigado @Leonardo Vieira Valério, sem a sua solução eu não teria conseguido. O title do AppBar ficou devendo ainda, porém deu preguiça.
import 'package:flutter/material.dart';
import 'package:nosso_primeiro_projeto/data/task_inherited.dart';
import '../components/task.dart';
import 'form_screen.dart';
class InitialScreen extends StatefulWidget {
InitialScreen({Key? key}) : super(key: key);
double nivelGlobal = 0;
@override
State<InitialScreen> createState() => _InitialScreenState();
}
class _InitialScreenState extends State<InitialScreen> {
double calculaNivelGlobal() {
double level = 0;
for (Task task in TaskInherited.of(context).taskList) {
level += (task.nivel / 10) * task.dificuldade;
}
return widget.nivelGlobal = level;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
leading: Container(),
title: Column(
children: [
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text('Tarefas'),
IconButton(
onPressed: () {
setState(() {
calculaNivelGlobal();
});
},
icon: const Icon(Icons.refresh)),
],
),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
SizedBox(
width: 200,
child: LinearProgressIndicator(
color: Colors.white,
value: widget.nivelGlobal / 10,
),
),
Text(
'Level: ${widget.nivelGlobal.toStringAsFixed(2)}',
style: const TextStyle(
fontSize: 12,
),
),
],
),
],
),
),
body: ListView(
padding: const EdgeInsets.only(top: 8, bottom: 75),
children: TaskInherited.of(context).taskList,
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (contextNew) => FormScreen(
//Precisou-se criar um novo contexto aqui
taskContext: context,
),
),
);
},
child: const Icon(Icons.add),
),
);
}
}