Solucionado (ver solução)
Solucionado
(ver solução)
1
resposta

[Projeto] Resposta desafio

Boa tarde! Apanhei um pouco com o leiaute então acabei deixando um pouco diferente.

Primeiro criei um método para calcular o level global atual:

  void _calculaLevelGlobal() {
    double level = 0;
    for (Task t in TaskInherited.of(context).taskList) {
      level += (t.nivel / 10) * t.dificuldade;
    }
    widget.levelGlobal = level;
  }

Alterei o leiaute da barra do app pra conter o level global, a barra de progresso e o botão pra recarregar:

        appBar: AppBar(
            leading: Container(),
            title: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    const Text('Tarefas'),
                    IconButton(
                        onPressed: () {
                          setState(() {
                            _calculaLevelGlobal();
                          });
                        },
                        icon: const Icon(Icons.refresh),
                    ),
                  ],
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    SizedBox(
                      width: 230,
                      child: LinearProgressIndicator(
                        color: Colors.red,
                        value: widget.levelGlobal / 100,
                      ),
                    ),
                    Text('Level: ${widget.levelGlobal}',
                        style: const TextStyle(fontSize: 12)
                    ),
                  ],
                ),
              ],
            )),

Insira aqui a descrição dessa imagem para ajudar na acessibilidade

Gif no drive: https://drive.google.com/file/d/1HyQsJkEaknzGOF8iwgJVMaP_RTz6t2Cl/view?usp=sharing

1 resposta
solução!
import 'package:flutter/material.dart';
import 'package:primeiro_projeto_flutter/components/task.dart';
import 'package:primeiro_projeto_flutter/data/task_inherited.dart';
import 'package:primeiro_projeto_flutter/screens/form_screen.dart';

class InitialScreen extends StatefulWidget {
  InitialScreen({Key? key}) : super(key: key);

  double levelGlobal = 0;

  @override
  State<InitialScreen> createState() => _InitialScreenState();
}

class _InitialScreenState extends State<InitialScreen> {
  void _calculaLevelGlobal() {
    double level = 0;
    for (Task t in TaskInherited.of(context).taskList) {
      level += (t.nivel / 10) * t.dificuldade;
    }
    widget.levelGlobal = level;
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
        appBar: AppBar(
            leading: Container(),
            title: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceBetween,
                  children: [
                    const Text('Tarefas'),
                    IconButton(
                        onPressed: () {
                          setState(() {
                            _calculaLevelGlobal();
                          });
                        },
                        icon: const Icon(Icons.refresh),
                    ),
                  ],
                ),
                Row(
                  mainAxisAlignment: MainAxisAlignment.spaceAround,
                  children: [
                    SizedBox(
                      width: 230,
                      child: LinearProgressIndicator(
                        color: Colors.red,
                        value: widget.levelGlobal / 100,
                      ),
                    ),
                    Text('Level: ${widget.levelGlobal}',
                        style: const TextStyle(fontSize: 12)
                    ),
                  ],
                ),
              ],
            )),
        body: ListView(
          padding: const EdgeInsets.only(top: 8, bottom: 70),
          children: TaskInherited.of(context).taskList,
        ),
        floatingActionButton: FloatingActionButton(
          onPressed: () {
            Navigator.push(
                context,
                MaterialPageRoute(
                    builder: (ctx) => FormScreen(taskContext: context)));
          },
          child: const Icon(Icons.add),
        ));
  }
}