import 'package:flutter/material.dart';
import 'package:nosso_primeiro_projeto/components/task.dart';
import 'package:nosso_primeiro_projeto/data/task_inherited.dart';
import 'package:nosso_primeiro_projeto/screens/form_screen.dart';
class InitialScreen extends StatefulWidget {
InitialScreen({super.key});
double nivelGlobal = 0;
@override
State<InitialScreen> createState() => _InitialScreenState();
}
class _InitialScreenState extends State<InitialScreen> {
double calcularNivel() {
double nivel = 0;
for (Task task in TaskInherited.of(context)!.taskList) {
nivel += (task.nivel / 10) * task.dificuldade;
}
return widget.nivelGlobal = nivel;
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
toolbarHeight: 80,
title: Column(
children: [
const Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
Text(
'Tarefas',
style: TextStyle(color: Colors.white, fontSize: 24),
),
],
),
Padding(
padding: const EdgeInsets.only(bottom: 8.0),
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
SizedBox(
width: 250,
child: LinearProgressIndicator(
value: widget.nivelGlobal / 100,
color: Colors.white,
),
),
Padding(
padding: const EdgeInsets.only(left: 12.0, right: 10.0),
child: Row(
children: [
Text(
'Level: ${widget.nivelGlobal.toStringAsFixed(2)}',
style: const TextStyle(
color: Colors.white, fontSize: 20),
),
],
),
),
IconButton(
onPressed: () {
setState(() {
calcularNivel();
});
},
icon: const Icon(
Icons.refresh,
color: Colors.white,
size: 25,
),
)
],
),
)
],
),
centerTitle: true,
backgroundColor: Colors.blue,
),
body: ListView(
padding: const EdgeInsets.only(top: 8, bottom: 70),
children: TaskInherited.of(context)!.taskList,
),
floatingActionButton: FloatingActionButton(
onPressed: () {
Navigator.push(
context,
MaterialPageRoute(
builder: (contextNew) => FormScreen(
taskContext: context,
),
),
);
},
backgroundColor: const Color.fromARGB(255, 13, 102, 175),
child: const Icon(Icons.add, color: Colors.white),
),
);
}
}