Flutter-Ernaehrungsapp/lib/android/components/circular/circular_component.dart

41 lines
1.2 KiB
Dart

import 'package:ernaehrung/android/config/statistics.dart';
import 'package:ernaehrung/android/models/user.dart';
import 'package:flutter/material.dart';
import 'package:hive/hive.dart';
import 'package:percent_indicator/circular_percent_indicator.dart';
class CircularLoadingComponent extends StatelessWidget {
CircularLoadingComponent({Key? key}) : super(key: key);
final int? targetCaolries = Hive.box<User>("USER_BOX").get("USER")?.kalorien;
@override
Widget build(BuildContext context) {;
return ValueListenableBuilder(
valueListenable: StatisticsService.instance.eatenCalories,
builder: (context, value, child) {
double progress = double.parse((value / targetCaolries!).toStringAsFixed(1));
progress = progress > 1.0 ? 1.0 : progress;
return Column(
mainAxisAlignment: MainAxisAlignment.center,
children: [
CircularPercentIndicator(
animation: true,
radius: 60.0,
lineWidth: 5.0,
percent: progress,
center: Text(
"$value/$targetCaolries Kcal",
textAlign: TextAlign.center,
),
progressColor: Colors.lightGreen,
),
],
);
},
);
}
}