forked from eatvio/eatvio_app
93 lines
3.2 KiB
Dart
93 lines
3.2 KiB
Dart
import 'package:collection/collection.dart';
|
|
import 'package:eatvio_app/core/theme/theme_helper.dart';
|
|
import 'package:eatvio_app/features/diary/presentation/bloc/diary_cubit.dart';
|
|
import 'package:eatvio_app/features/diary/presentation/bloc/diary_state.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_bloc/flutter_bloc.dart';
|
|
|
|
class MealButtonWidget extends StatefulWidget {
|
|
final int mealNumber;
|
|
const MealButtonWidget({
|
|
super.key,
|
|
required this.mealNumber,
|
|
});
|
|
|
|
@override
|
|
State<MealButtonWidget> createState() => _MealButtonWidgetState();
|
|
}
|
|
|
|
class _MealButtonWidgetState extends State<MealButtonWidget> {
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return BlocBuilder<DiaryCubit, DiaryState>(
|
|
builder: (context, state) {
|
|
if (state is DiaryStateLoaded) {
|
|
final consultantComment = state.consultantReview?.consultantComments.mealsComments.firstWhereOrNull(
|
|
(element) => element.typeNo == widget.mealNumber,
|
|
);
|
|
|
|
final Color bgColor;
|
|
if (state.selectedMeal == widget.mealNumber) {
|
|
bgColor = appTheme.blueA400;
|
|
} else if (consultantComment != null) {
|
|
bgColor = appTheme.commentBg;
|
|
} else {
|
|
bgColor = const Color(0xFFF1F2F6);
|
|
}
|
|
return InkWell(
|
|
onTap: () {
|
|
context.read<DiaryCubit>().setSelectedMeal(widget.mealNumber);
|
|
},
|
|
borderRadius: BorderRadius.circular(100),
|
|
child: Ink(
|
|
width: MediaQuery.of(context).size.width / 5 - (96 / 5),
|
|
height: 32,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(100),
|
|
color: bgColor,
|
|
),
|
|
child: Center(
|
|
child: Text(
|
|
'${widget.mealNumber}',
|
|
style: TextStyle(
|
|
color: state.selectedMeal == widget.mealNumber ? Colors.white : const Color(0xFF6D6F71),
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
if (state is DiaryStateLoadedTomorrowWithDiet) {
|
|
return InkWell(
|
|
onTap: () {
|
|
context.read<DiaryCubit>().setSelectedMeal(widget.mealNumber);
|
|
},
|
|
borderRadius: BorderRadius.circular(100),
|
|
child: Ink(
|
|
width: MediaQuery.of(context).size.width / 5 - (96 / 5),
|
|
height: 32,
|
|
decoration: BoxDecoration(
|
|
borderRadius: BorderRadius.circular(100),
|
|
color: state.selectedMeal == widget.mealNumber ? appTheme.blueA400 : const Color(0xFFF1F2F6),
|
|
),
|
|
child: Center(
|
|
child: Text(
|
|
'${widget.mealNumber}',
|
|
style: TextStyle(
|
|
color: state.selectedMeal == widget.mealNumber ? Colors.white : const Color(0xFF6D6F71),
|
|
fontSize: 16,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
),
|
|
),
|
|
),
|
|
);
|
|
}
|
|
return const SizedBox.shrink();
|
|
},
|
|
);
|
|
}
|
|
}
|