2023-07-30 13:09:41 +02:00
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
|
|
|
|
class MacroWidget extends StatelessWidget {
|
|
|
|
final double? amount;
|
|
|
|
final double? calories;
|
2023-07-30 20:44:50 +02:00
|
|
|
final double? fiber;
|
2023-07-30 13:09:41 +02:00
|
|
|
final double protein;
|
|
|
|
final double carb;
|
|
|
|
final double fat;
|
|
|
|
final TextStyle style;
|
2023-07-30 14:40:45 +02:00
|
|
|
final Widget? child;
|
2023-07-30 13:09:41 +02:00
|
|
|
|
|
|
|
const MacroWidget({
|
|
|
|
Key? key,
|
|
|
|
this.calories,
|
|
|
|
this.amount,
|
2023-07-30 14:40:45 +02:00
|
|
|
this.child,
|
2023-07-30 20:44:50 +02:00
|
|
|
this.fiber,
|
2023-07-30 13:09:41 +02:00
|
|
|
required this.protein,
|
|
|
|
required this.carb,
|
|
|
|
required this.fat,
|
|
|
|
required this.style,
|
|
|
|
}) : super(key: key);
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
var elements = <Widget>[
|
2023-08-28 14:45:32 +02:00
|
|
|
Expanded(
|
|
|
|
flex: 1,
|
|
|
|
child: Text(
|
|
|
|
"C: ${carb.toStringAsFixed(1)}g",
|
|
|
|
style: style,
|
|
|
|
textAlign: TextAlign.center,
|
2023-07-30 13:09:41 +02:00
|
|
|
),
|
|
|
|
),
|
2023-08-28 14:45:32 +02:00
|
|
|
Expanded(
|
|
|
|
flex: 1,
|
|
|
|
child: Text(
|
|
|
|
"F: ${fat.toStringAsFixed(1)}g",
|
|
|
|
style: style,
|
|
|
|
textAlign: TextAlign.center,
|
2023-07-30 13:09:41 +02:00
|
|
|
),
|
|
|
|
),
|
2023-08-28 14:45:32 +02:00
|
|
|
Expanded(
|
|
|
|
flex: 1,
|
|
|
|
child: Text(
|
|
|
|
"P: ${protein.toStringAsFixed(1)}g",
|
|
|
|
style: style,
|
|
|
|
textAlign: TextAlign.center,
|
2023-07-30 13:09:41 +02:00
|
|
|
),
|
|
|
|
),
|
|
|
|
];
|
|
|
|
|
2023-07-30 20:44:50 +02:00
|
|
|
if (fiber != null) {
|
|
|
|
elements.add(
|
|
|
|
Expanded(
|
|
|
|
flex: 1,
|
|
|
|
child: Text(
|
|
|
|
"f: ${fiber!.toStringAsFixed(1)}g",
|
|
|
|
style: style,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
2023-07-30 13:09:41 +02:00
|
|
|
if (calories != null) {
|
|
|
|
elements.add(
|
|
|
|
Expanded(
|
|
|
|
flex: 1,
|
|
|
|
child: Text(
|
|
|
|
"${calories!.toStringAsFixed(1)} kcal",
|
|
|
|
style: style,
|
|
|
|
textAlign: TextAlign.center,
|
|
|
|
),
|
2023-07-30 20:44:50 +02:00
|
|
|
),
|
|
|
|
);
|
2023-07-30 13:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
if (amount != null) {
|
|
|
|
elements.add(
|
|
|
|
Expanded(
|
|
|
|
flex: 1,
|
|
|
|
child: Text(
|
2023-07-30 13:21:45 +02:00
|
|
|
"${amount!.toStringAsFixed(1)}g",
|
2023-07-30 13:09:41 +02:00
|
|
|
style: style,
|
|
|
|
textAlign: TextAlign.center,
|
2023-08-28 14:45:32 +02:00
|
|
|
),
|
2023-07-30 20:44:50 +02:00
|
|
|
),
|
|
|
|
);
|
2023-07-30 13:09:41 +02:00
|
|
|
}
|
|
|
|
|
2023-07-30 14:40:45 +02:00
|
|
|
if (child != null) {
|
|
|
|
elements.add(
|
|
|
|
Expanded(
|
|
|
|
flex: 1,
|
|
|
|
child: child!,
|
2023-07-30 20:44:50 +02:00
|
|
|
),
|
|
|
|
);
|
2023-07-30 14:40:45 +02:00
|
|
|
}
|
|
|
|
|
2023-07-30 20:44:50 +02:00
|
|
|
if (elements.length < 4) {
|
2023-07-30 13:09:41 +02:00
|
|
|
elements.add(
|
2023-07-30 20:44:50 +02:00
|
|
|
const Expanded(
|
2023-07-30 13:09:41 +02:00
|
|
|
flex: 1,
|
2023-07-30 20:44:50 +02:00
|
|
|
child: Text(""),
|
|
|
|
),
|
|
|
|
);
|
2023-07-30 13:09:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return Padding(
|
|
|
|
padding: const EdgeInsets.only(
|
|
|
|
top: 4.0,
|
|
|
|
bottom: 4.0,
|
|
|
|
left: 8.0,
|
|
|
|
right: 8.0,
|
|
|
|
),
|
|
|
|
child: Row(
|
|
|
|
children: elements,
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|