build method
dynamic
build( - dynamic context
)
Implementation
@override
Widget build(BuildContext context) {
return FutureBuilder<Map<String, dynamic>>(
future: _loadAllStats(),
builder: (context, snapshot) {
if (snapshot.connectionState == ConnectionState.waiting) {
return const Center(child: CircularProgressIndicator());
}
if (snapshot.hasError) {
devtools.log("Error: ${snapshot.error}");
return const Center(child: Text('Error loading statistics'));
}
final stats = snapshot.data!;
final weekTasks = stats['weekTasks'] as int;
final monthTasks = stats['monthTasks'] as int;
final avgPerDay = stats['avgPerDay'] as double;
final totalTasks = stats['totalTasks'] as int;
final avgCompletion = stats['avgCompletion'] as double;
return Column(
children: [
Text(
"Your Statistics",
style: TextStyle(
fontSize: 25,
fontWeight: FontWeight.bold,
color: primaryColor,
),
),
const SizedBox(height: 20),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'$weekTasks tasks done 💥',
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
),
),
Text("just this week"),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
'$monthTasks tasks 🚀',
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
),
),
Text(
monthTasks > 20
? "this month alone!"
: "this month, warming up?",
),
],
),
],
),
const SizedBox(height: 30),
Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Text(
'${avgPerDay.toStringAsFixed(1)} tasks/day 🔥',
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
),
),
Text(
avgPerDay > 1.0
? "you're on a roll!"
: "one at a time...",
),
],
),
Column(
crossAxisAlignment: CrossAxisAlignment.end,
children: [
Text(
'$totalTasks total 😮',
style: TextStyle(
fontSize: 22,
fontWeight: FontWeight.bold,
),
),
Text(
totalTasks > 50
? "are you human?"
: "getting started, huh?",
),
],
),
],
),
const SizedBox(height: 30),
Column(
children: [
Text(
'${avgCompletion.toStringAsFixed(1)} hours avg ⏳',
style: TextStyle(fontSize: 22, fontWeight: FontWeight.bold),
),
Text("to complete a task"),
],
),
],
);
},
);
}