Creio que haja alguma solução mais viável e prática para esse desafio, mas abaixo estará o GIF do projeto funcionando, o Código e o link para o repositório, respectivamente:
Dentro de _InicialScreenState adicionei os seguintes atributos, função e operador lógico:
double globalLevel = 0;
double progressBarValue = 0;
void refreshLevelPage() {
setState(() {
globalLevel = 0; //para resetar os valores armazenados em cache
progressBarValue = 0; //para resetar os valores armazenados em cache
for (var task in TaskInherited.of(context)?.taskList ?? []) {
final taskLevel = (task.nivel * task.dificuldade) / 10;
globalLevel += taskLevel;
}
progressBarValue = globalLevel / 100;
});
}
A tela do app ficou da seguinte forma:
appBar: AppBar(
leading: Icon(Icons.add_task, color: Colors.white),
backgroundColor: Colors.blue,
title: Text(
' Tarefas',
style: TextStyle(color: Colors.white, fontSize: 20),
),
bottom: PreferredSize(
preferredSize: Size.fromHeight(15),
child: Padding(
padding: EdgeInsets.symmetric(horizontal: 30),
child: Row(
children: [
SizedBox(
width: 180,
child: LinearProgressIndicator(
backgroundColor: Colors.grey,
color: Colors.white,
value: progressBarValue,
),
),
Padding(
padding: const EdgeInsets.all(8),
child: Text(
'Level Global: ${globalLevel.toStringAsFixed(2)}',
style: TextStyle(color: Colors.white, fontSize: 16),
),
),
],
),
),
),
actions: [
Padding(
padding: const EdgeInsets.only(right: 50.0),
child: IconButton(
icon: Icon(Icons.loop),
onPressed: () {
refreshLevelPage();
},
),
),
],
),
Para ver como o projeto está funcionando acesse meu repositório: https://github.com/DantasMatheus/app_flutter