forked from eatvio/eatvio_app
refactor:
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import 'package:eatvio_app/core/app_export.dart';
|
||||
import 'package:eatvio_app/features/calendar/presentation/bloc/calendar_state.dart';
|
||||
import 'package:eatvio_app/features/calendar/repositories/calendar_repository.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
|
||||
class CalendarCubit extends Cubit<CalendarState> {
|
||||
final CalendarRepository calendarRepository;
|
||||
|
||||
@@ -1,46 +1,52 @@
|
||||
// ignore_for_file: unused_local_variable
|
||||
|
||||
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:eatvio_app/locator_service.dart';
|
||||
import 'package:eatvio_app/theme/app_decoration.dart';
|
||||
import 'package:eatvio_app/theme/custom_text_style.dart';
|
||||
import 'package:eatvio_app/theme/theme_helper.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:intl/intl.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_form_builder/flutter_form_builder.dart';
|
||||
|
||||
// ignore: must_be_immutable
|
||||
class CalendarScreen extends StatelessWidget {
|
||||
CalendarScreen({Key? key}) : super(key: key);
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
return BlocBuilder<CalendarCubit, CalendarState>(
|
||||
builder: (context, state) {
|
||||
if (state is CalendarStateLoaded) {
|
||||
return _buildCalendar(context, state);
|
||||
} else if (state is CalendarStateLoading) {
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
);
|
||||
} else if (state is CalendarStateError) {
|
||||
return Scaffold(
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Center(
|
||||
child: Text(state.errorMessage),
|
||||
return BlocProvider<CalendarCubit>(
|
||||
create: (context) => sl<CalendarCubit>()..loadCalendarList(),
|
||||
child: BlocBuilder<CalendarCubit, CalendarState>(
|
||||
builder: (context, state) {
|
||||
if (state is CalendarStateLoaded) {
|
||||
return _buildCalendar(context, state);
|
||||
} else if (state is CalendarStateLoading) {
|
||||
return Scaffold(
|
||||
body: Center(
|
||||
child: CircularProgressIndicator(),
|
||||
),
|
||||
),
|
||||
);
|
||||
} else
|
||||
return Scaffold(
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Center(
|
||||
child: Text("Неопределенная ошибка"),
|
||||
);
|
||||
} else if (state is CalendarStateError) {
|
||||
return Scaffold(
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Center(
|
||||
child: Text(state.errorMessage),
|
||||
),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
);
|
||||
} else
|
||||
return Scaffold(
|
||||
body: Padding(
|
||||
padding: const EdgeInsets.all(16),
|
||||
child: Center(
|
||||
child: Text("Неопределенная ошибка"),
|
||||
),
|
||||
),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -101,8 +107,7 @@ class CalendarScreen extends StatelessWidget {
|
||||
padding: EdgeInsets.all(8),
|
||||
decoration: BoxDecoration(
|
||||
borderRadius: BorderRadiusStyle.circleBorder8,
|
||||
color: state.calendarList[index]
|
||||
.is_current_day_included_in_the_chosen_diet_progression
|
||||
color: state.calendarList[index].is_current_day_included_in_the_chosen_diet_progression
|
||||
? Color.fromRGBO(59, 130, 246, .2)
|
||||
: Color.fromRGBO(126, 136, 151, .1),
|
||||
),
|
||||
@@ -119,36 +124,28 @@ class CalendarScreen extends StatelessWidget {
|
||||
style: theme.textTheme.titleMedium,
|
||||
),
|
||||
SizedBox(height: 4),
|
||||
if (state.calendarList[index]
|
||||
.is_current_day_included_in_the_chosen_diet_progression)
|
||||
if (state.calendarList[index].is_current_day_included_in_the_chosen_diet_progression)
|
||||
Container(
|
||||
padding: EdgeInsets.all(
|
||||
4.0), // Отступы внутри контейнера
|
||||
padding: EdgeInsets.all(4.0), // Отступы внутри контейнера
|
||||
decoration: BoxDecoration(
|
||||
color: Color.fromRGBO(13, 110, 253, 1),
|
||||
borderRadius: BorderRadius.circular(
|
||||
24.0), // Закругленные углы
|
||||
borderRadius: BorderRadius.circular(24.0), // Закругленные углы
|
||||
),
|
||||
child: Text(
|
||||
'Посмотреть диету на день',
|
||||
style: CustomTextStyles
|
||||
.titleSmallBold, // Предполагается, что текст белый
|
||||
style: CustomTextStyles.titleSmallBold, // Предполагается, что текст белый
|
||||
),
|
||||
),
|
||||
if (!state.calendarList[index]
|
||||
.is_current_day_included_in_the_chosen_diet_progression)
|
||||
if (!state.calendarList[index].is_current_day_included_in_the_chosen_diet_progression)
|
||||
Container(
|
||||
padding: EdgeInsets.all(
|
||||
4.0), // Отступы внутри контейнера
|
||||
padding: EdgeInsets.all(4.0), // Отступы внутри контейнера
|
||||
decoration: BoxDecoration(
|
||||
color: Color.fromRGBO(108, 117, 125, 1),
|
||||
borderRadius: BorderRadius.circular(
|
||||
24.0), // Закругленные углы
|
||||
borderRadius: BorderRadius.circular(24.0), // Закругленные углы
|
||||
),
|
||||
child: Text(
|
||||
'Cкоро',
|
||||
style: CustomTextStyles
|
||||
.titleSmallBold, // Предполагается, что текст белый
|
||||
style: CustomTextStyles.titleSmallBold, // Предполагается, что текст белый
|
||||
),
|
||||
),
|
||||
],
|
||||
@@ -188,50 +185,39 @@ class CalendarScreen extends StatelessWidget {
|
||||
SizedBox(height: 4),
|
||||
Row(children: [
|
||||
Container(
|
||||
padding: EdgeInsets.all(
|
||||
4.0), // Отступы внутри контейнера
|
||||
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), // Закругленные углы
|
||||
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, // Предполагается, что текст белый
|
||||
style: CustomTextStyles.titleSmallBold, // Предполагается, что текст белый
|
||||
),
|
||||
),
|
||||
SizedBox(width: 4),
|
||||
if (diary['state'] == 'started')
|
||||
Container(
|
||||
padding: EdgeInsets.all(
|
||||
4.0), // Отступы внутри контейнера
|
||||
padding: EdgeInsets.all(4.0), // Отступы внутри контейнера
|
||||
decoration: BoxDecoration(
|
||||
color: Color.fromRGBO(13, 110, 253, 1),
|
||||
borderRadius: BorderRadius.circular(
|
||||
24.0), // Закругленные углы
|
||||
borderRadius: BorderRadius.circular(24.0), // Закругленные углы
|
||||
),
|
||||
child: Text(
|
||||
'Заполнить отчет',
|
||||
style: CustomTextStyles
|
||||
.titleSmallBold, // Предполагается, что текст белый
|
||||
style: CustomTextStyles.titleSmallBold, // Предполагается, что текст белый
|
||||
),
|
||||
),
|
||||
if (diary['state'] == 'finished')
|
||||
Container(
|
||||
padding: EdgeInsets.all(
|
||||
4.0), // Отступы внутри контейнера
|
||||
padding: EdgeInsets.all(4.0), // Отступы внутри контейнера
|
||||
decoration: BoxDecoration(
|
||||
color: Color.fromRGBO(13, 110, 253, 1),
|
||||
borderRadius: BorderRadius.circular(
|
||||
24.0), // Закругленные углы
|
||||
borderRadius: BorderRadius.circular(24.0), // Закругленные углы
|
||||
),
|
||||
child: Text(
|
||||
'Изменить отчет',
|
||||
style: CustomTextStyles
|
||||
.titleSmallBold, // Предполагается, что текст белый
|
||||
style: CustomTextStyles.titleSmallBold, // Предполагается, что текст белый
|
||||
),
|
||||
),
|
||||
]),
|
||||
|
||||
Reference in New Issue
Block a user