forked from eatvio/eatvio_app
feat(diary): Diary ID is passed on calendar click, new layouts for calendar, fixed nutrition chart
This commit is contained in:
@@ -1,11 +1,10 @@
|
||||
// ignore_for_file: unused_local_variable
|
||||
|
||||
import 'package:eatvio_app/features/calendar/models/calendar_model.dart';
|
||||
import 'package:eatvio_app/features/calendar/presentation/bloc/calendar_cubit.dart';
|
||||
import 'package:eatvio_app/features/calendar/presentation/bloc/calendar_state.dart';
|
||||
import 'package:eatvio_app/core/app_export.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:table_calendar/table_calendar.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
||||
@@ -54,7 +53,7 @@ class CalendarScreen extends StatelessWidget {
|
||||
toolbarHeight: 0,
|
||||
automaticallyImplyLeading: false,
|
||||
),
|
||||
backgroundColor: Color.fromARGB(255, 240, 242, 245),
|
||||
backgroundColor: Colors.white,
|
||||
resizeToAvoidBottomInset: true,
|
||||
body: SizedBox(
|
||||
width: double.maxFinite,
|
||||
@@ -83,82 +82,154 @@ class CalendarScreen extends StatelessWidget {
|
||||
}
|
||||
|
||||
_buildCalendarBody(BuildContext context, CalendarStateLoaded state) {
|
||||
return Container(
|
||||
margin: EdgeInsets.symmetric(horizontal: 16.h, vertical: 16.h),
|
||||
padding: EdgeInsets.symmetric(
|
||||
horizontal: 24.h,
|
||||
vertical: 12.v,
|
||||
),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withOpacity(0.5),
|
||||
spreadRadius: 2,
|
||||
blurRadius: 5,
|
||||
offset: Offset(0, 3),
|
||||
return ListView.separated(
|
||||
padding: EdgeInsets.all(8),
|
||||
shrinkWrap: true,
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
separatorBuilder: (context, index) {
|
||||
return SizedBox(
|
||||
height: 2.v,
|
||||
);
|
||||
},
|
||||
itemCount: state.calendarList.length,
|
||||
itemBuilder: (context, index) {
|
||||
Map<String, dynamic> diary = {};
|
||||
if (state.calendarList[index].diary is List<dynamic>) {
|
||||
diary['status'] = 'Скоро';
|
||||
} else if (state.calendarList[index].diary is Map<String, dynamic>) {
|
||||
diary = state.calendarList[index].diary as Map<String, dynamic>;
|
||||
}
|
||||
return InkWell(
|
||||
borderRadius: BorderRadiusStyle.circleBorder8,
|
||||
onTap: () => GoRouter.of(context).go(
|
||||
'/diary-screen',
|
||||
extra: diary['id'].toString(),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: TableCalendar(
|
||||
locale: 'ru_RU',
|
||||
firstDay: DateTime.utc(2010, 10, 16),
|
||||
lastDay: DateTime.utc(2030, 3, 14),
|
||||
focusedDay: DateTime.now(),
|
||||
startingDayOfWeek: StartingDayOfWeek.monday,
|
||||
calendarBuilders: CalendarBuilders(
|
||||
selectedBuilder: (context, day, focusedDay) =>
|
||||
_buildCellDate(context, day, focusedDay: focusedDay, state),
|
||||
defaultBuilder: (context, day, focusedDay) =>
|
||||
_buildCellDate(context, day, state),
|
||||
todayBuilder: (context, day, focusedDay) =>
|
||||
_buildCellDate(context, day, state),
|
||||
),
|
||||
),
|
||||
child: Ink(
|
||||
padding: EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadiusStyle.circleBorder8,
|
||||
color: getBackgroundColor(diary['state']),
|
||||
),
|
||||
child: Row(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Expanded(
|
||||
child: Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
Text(
|
||||
formatDate(state.calendarList[index].date),
|
||||
style: theme.textTheme.titleMedium,
|
||||
),
|
||||
SizedBox(height: 2.v),
|
||||
if (diary['state'] != null)
|
||||
Row(children: [
|
||||
Container(
|
||||
padding: EdgeInsets.all(
|
||||
4.0), // Отступы внутри контейнера
|
||||
decoration: BoxDecoration(
|
||||
color: diary['state'] == 'finished'
|
||||
? Color.fromRGBO(1, 154, 62, 1)
|
||||
: Color.fromRGBO(154, 74, 1, 1),
|
||||
borderRadius: BorderRadius.circular(
|
||||
24.0), // Закругленные углы
|
||||
),
|
||||
child: Text(
|
||||
_getStateText(diary['state'] ?? ''),
|
||||
style: CustomTextStyles
|
||||
.titleSmallBold, // Предполагается, что текст белый
|
||||
),
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
if (diary['state'] == 'started')
|
||||
Container(
|
||||
padding: EdgeInsets.all(
|
||||
4.0), // Отступы внутри контейнера
|
||||
decoration: BoxDecoration(
|
||||
color: Color.fromRGBO(13, 110, 253, 1),
|
||||
borderRadius: BorderRadius.circular(
|
||||
24.0), // Закругленные углы
|
||||
),
|
||||
child: Text(
|
||||
'Заполнить отчет',
|
||||
style: CustomTextStyles
|
||||
.titleSmallBold, // Предполагается, что текст белый
|
||||
),
|
||||
),
|
||||
if (diary['state'] == 'finished')
|
||||
Container(
|
||||
padding: EdgeInsets.all(
|
||||
4.0), // Отступы внутри контейнера
|
||||
decoration: BoxDecoration(
|
||||
color: Color.fromRGBO(13, 110, 253, 1),
|
||||
borderRadius: BorderRadius.circular(
|
||||
24.0), // Закругленные углы
|
||||
),
|
||||
child: Text(
|
||||
'Изменить отчет',
|
||||
style: CustomTextStyles
|
||||
.titleSmallBold, // Предполагается, что текст белый
|
||||
),
|
||||
),
|
||||
]),
|
||||
if (state.calendarList[index].diary is List<dynamic>)
|
||||
Container(
|
||||
padding:
|
||||
EdgeInsets.all(4.0), // Отступы внутри контейнера
|
||||
decoration: BoxDecoration(
|
||||
color: Color.fromRGBO(108, 117, 125, 1),
|
||||
borderRadius: BorderRadius.circular(
|
||||
24.0), // Закругленные углы
|
||||
),
|
||||
child: Text(
|
||||
'Cкоро',
|
||||
style: CustomTextStyles
|
||||
.titleSmallBold, // Предполагается, что текст белый
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Widget _buildCellDate(
|
||||
BuildContext context, DateTime day, CalendarStateLoaded state,
|
||||
{DateTime? focusedDay}) {
|
||||
final String dayString = day.toIso8601String().split('T').first;
|
||||
final List<CalendarModel> calendarModels = state.calendarList;
|
||||
|
||||
// Находим первую модель, соответствующую дате
|
||||
final CalendarModel model = calendarModels.firstWhere(
|
||||
(model) => model.date == dayString,
|
||||
orElse: () => CalendarModel(date: dayString, diary: {}));
|
||||
|
||||
Color? bgclr; // Объявляем переменную bgclr здесь
|
||||
|
||||
final Map<String, dynamic> diary = model.diary as Map<String, dynamic>;
|
||||
if (model.diary is Map<String, dynamic>) {
|
||||
if (diary['state'] == "started") {
|
||||
bgclr = Colors.grey;
|
||||
} else if (diary['state'] == "finished") {
|
||||
bgclr = Colors.green;
|
||||
} else {
|
||||
bgclr = Colors.white;
|
||||
}
|
||||
} else {
|
||||
bgclr = Colors.white; // Значение по умолчанию, если diary не является Map
|
||||
String _getStateText(String state) {
|
||||
switch (state) {
|
||||
case 'finished':
|
||||
return 'Готово';
|
||||
case 'started':
|
||||
return 'В процессе';
|
||||
default:
|
||||
return ''; // Возвращаем пустую строку, если состояние не распознано
|
||||
}
|
||||
}
|
||||
|
||||
String formatDate(String dateString) {
|
||||
// Преобразуем строку в объект DateTime
|
||||
DateTime dateTime = DateTime.parse(dateString);
|
||||
|
||||
// Форматируем дату
|
||||
String formattedDate = DateFormat('d MMMM', 'ru_RU').format(dateTime);
|
||||
|
||||
// Возвращаем результат в нужном формате
|
||||
return '$formattedDate';
|
||||
}
|
||||
|
||||
Color getBackgroundColor(String? status) {
|
||||
switch (status) {
|
||||
case 'finished':
|
||||
return Color.fromRGBO(1, 154, 62, .1);
|
||||
case 'started':
|
||||
return Color.fromRGBO(154, 74, 1, .1);
|
||||
default:
|
||||
return Color.fromRGBO(126, 136, 151, .1);
|
||||
}
|
||||
|
||||
return GestureDetector(
|
||||
onTap: () => GoRouter.of(context).pushNamed(
|
||||
'diaryScreen',
|
||||
extra: diary['id'],
|
||||
),
|
||||
child: Container(
|
||||
margin: const EdgeInsets.all(5),
|
||||
alignment: Alignment.center,
|
||||
decoration: BoxDecoration(
|
||||
shape: (day == focusedDay) ? BoxShape.circle : BoxShape.rectangle,
|
||||
color: bgclr,
|
||||
borderRadius: (day == focusedDay) ? null : BorderRadius.circular(4),
|
||||
),
|
||||
child: Text(day.day.toString(), style: TextStyle(color: Colors.black)),
|
||||
));
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user