my plans and my diets

This commit is contained in:
Username1548
2024-12-23 15:36:00 +07:00
parent 15a6ff44ef
commit 5ef1f3a660
52 changed files with 3857 additions and 573 deletions

View File

@@ -0,0 +1,207 @@
import 'package:easy_debounce/easy_debounce.dart';
import 'package:eatvio_app/core/const.dart';
import 'package:eatvio_app/features/my_plans/presentation/cubit/my_plans_state.dart';
import 'package:eatvio_app/features/my_plans/repositories/my_diets_repository.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class MyPlansCubit extends Cubit<MyPlansState> {
final MyPlansRepository myPlansRepository;
int currentDraftPage = 1;
int currentActivePage = 1;
late int lastDraftPage;
late int lastPersonalPage;
late int lastActivePage;
bool isLoadingDraft = false;
bool isLoadingActive = false;
String? _activeQuery;
String? _draftQuery;
static const List<int?> _durationValues = [null, ...durationValues];
static const List<String?> _types = [null, ...planTypeValues];
MyPlansCubit({required this.myPlansRepository}) : super(MyPlansState());
void changePriceFilter(int minPrice, int maxPrice, {bool disableDebounce = false}) {
if (state.selectedStateIndex == 0) {
emit(state.copyWith(activeFilterState: state.activeFilterState.copyWith(priceFilter: (minPrice, maxPrice)), error: null));
EasyDebounce.debounce(
'loadPlans',
Duration(seconds: disableDebounce ? 0 : 1),
() => loadPlans(
query: _activeQuery,
),
);
} else if (state.selectedStateIndex == 1) {
emit(state.copyWith(draftFilterState: state.draftFilterState.copyWith(priceFilter: (minPrice, maxPrice)), error: null));
EasyDebounce.debounce(
'loadPlans',
Duration(seconds: disableDebounce ? 0 : 1),
() => loadPlans(
query: _draftQuery,
),
);
}
}
void changeTypeFilter(int index) {
if (state.selectedStateIndex == 0) {
emit(state.copyWith(activeFilterState: state.activeFilterState.copyWith(typeIndex: index), error: null));
EasyDebounce.debounce(
'loadPlans',
Duration(seconds: 1),
() => loadPlans(
query: _activeQuery,
),
);
} else if (state.selectedStateIndex == 1) {
emit(state.copyWith(draftFilterState: state.draftFilterState.copyWith(typeIndex: index), error: null));
EasyDebounce.debounce(
'loadPlans',
Duration(seconds: 1),
() => loadPlans(
query: _draftQuery,
),
);
}
}
void changeDurationFilter(int index) {
if (state.selectedStateIndex == 0) {
emit(state.copyWith(activeFilterState: state.activeFilterState.copyWith(durationIndex: index), error: null));
EasyDebounce.debounce(
'loadPlans',
Duration(seconds: 1),
() => loadPlans(
query: _activeQuery,
),
);
} else if (state.selectedStateIndex == 1) {
emit(state.copyWith(draftFilterState: state.draftFilterState.copyWith(durationIndex: index), error: null));
EasyDebounce.debounce(
'loadPlans',
Duration(seconds: 1),
() => loadPlans(
query: _draftQuery,
),
);
}
}
void changeSelectedStateIndex(int index) {
emit(state.copyWith(selectedStateIndex: index));
}
Future<void> loadPlans({
String? query,
}) async {
switch (state.selectedStateIndex) {
case 0:
await _loadActivePlans(query: query);
break;
case 1:
await _loadDraftPlans(query: query);
break;
}
}
Future<void> loadAllPlans() async {
emit(state.copyWith(isLoading: true));
await _loadActivePlans();
await _loadDraftPlans();
emit(state.copyWith(isLoading: false));
}
Future<void> _loadActivePlans({String? query}) async {
try {
_activeQuery = query;
final type = _types[state.activeFilterState.typeIndex];
final duration = _durationValues[state.activeFilterState.durationIndex];
final minPrice = state.activeFilterState.priceFilter.$1;
final maxPrice = state.activeFilterState.priceFilter.$2;
final plansPagination = await myPlansRepository.getPlans(
query: query,
duration: duration,
maxPrice: maxPrice,
minPrice: minPrice,
types: type,
);
lastActivePage = plansPagination.meta.lastPage;
final minPlanPrice = plansPagination.meta.totalMinPrice ?? 0;
final maxPlanPrice = plansPagination.meta.totalMaxPrice ?? 0;
if (state.activeFilterState.priceFilter.$1 == null || state.activeFilterState.priceFilter.$2 == null) {
emit(
state.copyWith(
activeFilterState: state.activeFilterState.copyWith(priceFilter: (minPlanPrice, maxPlanPrice)),
),
);
}
emit(
state.copyWith(
activePlans: plansPagination.data,
isLoading: isLoadingActive,
error: null,
minActivePlanPrice: minPlanPrice,
maxActivePlanPrice: maxPlanPrice,
),
);
} catch (e) {
emit(
state.copyWith(error: e.toString()),
);
}
}
Future<void> _loadDraftPlans({String? query}) async {
try {
_draftQuery = query;
final type = _types[state.draftFilterState.typeIndex];
final duration = _durationValues[state.draftFilterState.durationIndex];
final minPrice = state.draftFilterState.priceFilter.$1;
final maxPrice = state.draftFilterState.priceFilter.$2;
final plansPagination = await myPlansRepository.getPlans(
query: query,
duration: duration,
maxPrice: maxPrice,
minPrice: minPrice,
types: type,
);
lastDraftPage = plansPagination.meta.lastPage;
final minPlanPrice = plansPagination.meta.totalMinPrice ?? 0;
final maxPlanPrice = plansPagination.meta.totalMaxPrice ?? 0;
if (state.draftFilterState.priceFilter.$1 == null || state.draftFilterState.priceFilter.$2 == null) {
emit(
state.copyWith(
draftFilterState: state.draftFilterState.copyWith(priceFilter: (minPlanPrice, maxPlanPrice)),
),
);
}
emit(
state.copyWith(
draftPlans: plansPagination.data,
isLoading: isLoadingDraft,
error: null,
minDraftPlanPrice: minPlanPrice,
maxDraftPlanPrice: maxPlanPrice,
),
);
} catch (e) {
emit(
state.copyWith(error: e.toString()),
);
}
}
Future<bool> deletePlan(String slug) async {
try {
await myPlansRepository.deletePlan(slug);
await loadAllPlans();
return true;
} catch (e) {
emit(
state.copyWith(error: e.toString()),
);
return false;
}
}
}

View File

@@ -0,0 +1,36 @@
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
import 'package:eatvio_app/features/feed/presentation/bloc/plans_cubit/plans_state.dart';
import 'package:freezed_annotation/freezed_annotation.dart';
part 'my_plans_state.freezed.dart';
@freezed
class MyPlansState with _$MyPlansState {
factory MyPlansState({
@Default([]) List<PlanModel> activePlans,
@Default([]) List<PlanModel> draftPlans,
@Default(false) bool isLoading,
@Default(null) String? error,
@Default(0) int selectedStateIndex,
@Default(0) int minActivePlanPrice,
@Default(0) int maxActivePlanPrice,
@Default(0) int minDraftPlanPrice,
@Default(0) int maxDraftPlanPrice,
@Default(
const PlansFilterState(
priceFilter: (null, null),
durationIndex: 0,
typeIndex: 0,
),
)
PlansFilterState activeFilterState,
@Default(
const PlansFilterState(
priceFilter: (null, null),
durationIndex: 0,
typeIndex: 0,
),
)
PlansFilterState draftFilterState,
}) = _MyPlansState;
}

View File

@@ -0,0 +1,424 @@
// coverage:ignore-file
// GENERATED CODE - DO NOT MODIFY BY HAND
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'my_plans_state.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
T _$identity<T>(T value) => value;
final _privateConstructorUsedError = UnsupportedError(
'It seems like you constructed your class using `MyClass._()`. This constructor is only meant to be used by freezed and you are not supposed to need it nor use it.\nPlease check the documentation here for more information: https://github.com/rrousselGit/freezed#adding-getters-and-methods-to-our-models');
/// @nodoc
mixin _$MyPlansState {
List<PlanModel> get activePlans => throw _privateConstructorUsedError;
List<PlanModel> get draftPlans => throw _privateConstructorUsedError;
bool get isLoading => throw _privateConstructorUsedError;
String? get error => throw _privateConstructorUsedError;
int get selectedStateIndex => throw _privateConstructorUsedError;
int get minActivePlanPrice => throw _privateConstructorUsedError;
int get maxActivePlanPrice => throw _privateConstructorUsedError;
int get minDraftPlanPrice => throw _privateConstructorUsedError;
int get maxDraftPlanPrice => throw _privateConstructorUsedError;
PlansFilterState get activeFilterState => throw _privateConstructorUsedError;
PlansFilterState get draftFilterState => throw _privateConstructorUsedError;
/// Create a copy of MyPlansState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
$MyPlansStateCopyWith<MyPlansState> get copyWith =>
throw _privateConstructorUsedError;
}
/// @nodoc
abstract class $MyPlansStateCopyWith<$Res> {
factory $MyPlansStateCopyWith(
MyPlansState value, $Res Function(MyPlansState) then) =
_$MyPlansStateCopyWithImpl<$Res, MyPlansState>;
@useResult
$Res call(
{List<PlanModel> activePlans,
List<PlanModel> draftPlans,
bool isLoading,
String? error,
int selectedStateIndex,
int minActivePlanPrice,
int maxActivePlanPrice,
int minDraftPlanPrice,
int maxDraftPlanPrice,
PlansFilterState activeFilterState,
PlansFilterState draftFilterState});
$PlansFilterStateCopyWith<$Res> get activeFilterState;
$PlansFilterStateCopyWith<$Res> get draftFilterState;
}
/// @nodoc
class _$MyPlansStateCopyWithImpl<$Res, $Val extends MyPlansState>
implements $MyPlansStateCopyWith<$Res> {
_$MyPlansStateCopyWithImpl(this._value, this._then);
// ignore: unused_field
final $Val _value;
// ignore: unused_field
final $Res Function($Val) _then;
/// Create a copy of MyPlansState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? activePlans = null,
Object? draftPlans = null,
Object? isLoading = null,
Object? error = freezed,
Object? selectedStateIndex = null,
Object? minActivePlanPrice = null,
Object? maxActivePlanPrice = null,
Object? minDraftPlanPrice = null,
Object? maxDraftPlanPrice = null,
Object? activeFilterState = null,
Object? draftFilterState = null,
}) {
return _then(_value.copyWith(
activePlans: null == activePlans
? _value.activePlans
: activePlans // ignore: cast_nullable_to_non_nullable
as List<PlanModel>,
draftPlans: null == draftPlans
? _value.draftPlans
: draftPlans // ignore: cast_nullable_to_non_nullable
as List<PlanModel>,
isLoading: null == isLoading
? _value.isLoading
: isLoading // ignore: cast_nullable_to_non_nullable
as bool,
error: freezed == error
? _value.error
: error // ignore: cast_nullable_to_non_nullable
as String?,
selectedStateIndex: null == selectedStateIndex
? _value.selectedStateIndex
: selectedStateIndex // ignore: cast_nullable_to_non_nullable
as int,
minActivePlanPrice: null == minActivePlanPrice
? _value.minActivePlanPrice
: minActivePlanPrice // ignore: cast_nullable_to_non_nullable
as int,
maxActivePlanPrice: null == maxActivePlanPrice
? _value.maxActivePlanPrice
: maxActivePlanPrice // ignore: cast_nullable_to_non_nullable
as int,
minDraftPlanPrice: null == minDraftPlanPrice
? _value.minDraftPlanPrice
: minDraftPlanPrice // ignore: cast_nullable_to_non_nullable
as int,
maxDraftPlanPrice: null == maxDraftPlanPrice
? _value.maxDraftPlanPrice
: maxDraftPlanPrice // ignore: cast_nullable_to_non_nullable
as int,
activeFilterState: null == activeFilterState
? _value.activeFilterState
: activeFilterState // ignore: cast_nullable_to_non_nullable
as PlansFilterState,
draftFilterState: null == draftFilterState
? _value.draftFilterState
: draftFilterState // ignore: cast_nullable_to_non_nullable
as PlansFilterState,
) as $Val);
}
/// Create a copy of MyPlansState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$PlansFilterStateCopyWith<$Res> get activeFilterState {
return $PlansFilterStateCopyWith<$Res>(_value.activeFilterState, (value) {
return _then(_value.copyWith(activeFilterState: value) as $Val);
});
}
/// Create a copy of MyPlansState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$PlansFilterStateCopyWith<$Res> get draftFilterState {
return $PlansFilterStateCopyWith<$Res>(_value.draftFilterState, (value) {
return _then(_value.copyWith(draftFilterState: value) as $Val);
});
}
}
/// @nodoc
abstract class _$$MyPlansStateImplCopyWith<$Res>
implements $MyPlansStateCopyWith<$Res> {
factory _$$MyPlansStateImplCopyWith(
_$MyPlansStateImpl value, $Res Function(_$MyPlansStateImpl) then) =
__$$MyPlansStateImplCopyWithImpl<$Res>;
@override
@useResult
$Res call(
{List<PlanModel> activePlans,
List<PlanModel> draftPlans,
bool isLoading,
String? error,
int selectedStateIndex,
int minActivePlanPrice,
int maxActivePlanPrice,
int minDraftPlanPrice,
int maxDraftPlanPrice,
PlansFilterState activeFilterState,
PlansFilterState draftFilterState});
@override
$PlansFilterStateCopyWith<$Res> get activeFilterState;
@override
$PlansFilterStateCopyWith<$Res> get draftFilterState;
}
/// @nodoc
class __$$MyPlansStateImplCopyWithImpl<$Res>
extends _$MyPlansStateCopyWithImpl<$Res, _$MyPlansStateImpl>
implements _$$MyPlansStateImplCopyWith<$Res> {
__$$MyPlansStateImplCopyWithImpl(
_$MyPlansStateImpl _value, $Res Function(_$MyPlansStateImpl) _then)
: super(_value, _then);
/// Create a copy of MyPlansState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline')
@override
$Res call({
Object? activePlans = null,
Object? draftPlans = null,
Object? isLoading = null,
Object? error = freezed,
Object? selectedStateIndex = null,
Object? minActivePlanPrice = null,
Object? maxActivePlanPrice = null,
Object? minDraftPlanPrice = null,
Object? maxDraftPlanPrice = null,
Object? activeFilterState = null,
Object? draftFilterState = null,
}) {
return _then(_$MyPlansStateImpl(
activePlans: null == activePlans
? _value._activePlans
: activePlans // ignore: cast_nullable_to_non_nullable
as List<PlanModel>,
draftPlans: null == draftPlans
? _value._draftPlans
: draftPlans // ignore: cast_nullable_to_non_nullable
as List<PlanModel>,
isLoading: null == isLoading
? _value.isLoading
: isLoading // ignore: cast_nullable_to_non_nullable
as bool,
error: freezed == error
? _value.error
: error // ignore: cast_nullable_to_non_nullable
as String?,
selectedStateIndex: null == selectedStateIndex
? _value.selectedStateIndex
: selectedStateIndex // ignore: cast_nullable_to_non_nullable
as int,
minActivePlanPrice: null == minActivePlanPrice
? _value.minActivePlanPrice
: minActivePlanPrice // ignore: cast_nullable_to_non_nullable
as int,
maxActivePlanPrice: null == maxActivePlanPrice
? _value.maxActivePlanPrice
: maxActivePlanPrice // ignore: cast_nullable_to_non_nullable
as int,
minDraftPlanPrice: null == minDraftPlanPrice
? _value.minDraftPlanPrice
: minDraftPlanPrice // ignore: cast_nullable_to_non_nullable
as int,
maxDraftPlanPrice: null == maxDraftPlanPrice
? _value.maxDraftPlanPrice
: maxDraftPlanPrice // ignore: cast_nullable_to_non_nullable
as int,
activeFilterState: null == activeFilterState
? _value.activeFilterState
: activeFilterState // ignore: cast_nullable_to_non_nullable
as PlansFilterState,
draftFilterState: null == draftFilterState
? _value.draftFilterState
: draftFilterState // ignore: cast_nullable_to_non_nullable
as PlansFilterState,
));
}
}
/// @nodoc
class _$MyPlansStateImpl implements _MyPlansState {
_$MyPlansStateImpl(
{final List<PlanModel> activePlans = const [],
final List<PlanModel> draftPlans = const [],
this.isLoading = false,
this.error = null,
this.selectedStateIndex = 0,
this.minActivePlanPrice = 0,
this.maxActivePlanPrice = 0,
this.minDraftPlanPrice = 0,
this.maxDraftPlanPrice = 0,
this.activeFilterState = const PlansFilterState(
priceFilter: (null, null), durationIndex: 0, typeIndex: 0),
this.draftFilterState = const PlansFilterState(
priceFilter: (null, null), durationIndex: 0, typeIndex: 0)})
: _activePlans = activePlans,
_draftPlans = draftPlans;
final List<PlanModel> _activePlans;
@override
@JsonKey()
List<PlanModel> get activePlans {
if (_activePlans is EqualUnmodifiableListView) return _activePlans;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_activePlans);
}
final List<PlanModel> _draftPlans;
@override
@JsonKey()
List<PlanModel> get draftPlans {
if (_draftPlans is EqualUnmodifiableListView) return _draftPlans;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_draftPlans);
}
@override
@JsonKey()
final bool isLoading;
@override
@JsonKey()
final String? error;
@override
@JsonKey()
final int selectedStateIndex;
@override
@JsonKey()
final int minActivePlanPrice;
@override
@JsonKey()
final int maxActivePlanPrice;
@override
@JsonKey()
final int minDraftPlanPrice;
@override
@JsonKey()
final int maxDraftPlanPrice;
@override
@JsonKey()
final PlansFilterState activeFilterState;
@override
@JsonKey()
final PlansFilterState draftFilterState;
@override
String toString() {
return 'MyPlansState(activePlans: $activePlans, draftPlans: $draftPlans, isLoading: $isLoading, error: $error, selectedStateIndex: $selectedStateIndex, minActivePlanPrice: $minActivePlanPrice, maxActivePlanPrice: $maxActivePlanPrice, minDraftPlanPrice: $minDraftPlanPrice, maxDraftPlanPrice: $maxDraftPlanPrice, activeFilterState: $activeFilterState, draftFilterState: $draftFilterState)';
}
@override
bool operator ==(Object other) {
return identical(this, other) ||
(other.runtimeType == runtimeType &&
other is _$MyPlansStateImpl &&
const DeepCollectionEquality()
.equals(other._activePlans, _activePlans) &&
const DeepCollectionEquality()
.equals(other._draftPlans, _draftPlans) &&
(identical(other.isLoading, isLoading) ||
other.isLoading == isLoading) &&
(identical(other.error, error) || other.error == error) &&
(identical(other.selectedStateIndex, selectedStateIndex) ||
other.selectedStateIndex == selectedStateIndex) &&
(identical(other.minActivePlanPrice, minActivePlanPrice) ||
other.minActivePlanPrice == minActivePlanPrice) &&
(identical(other.maxActivePlanPrice, maxActivePlanPrice) ||
other.maxActivePlanPrice == maxActivePlanPrice) &&
(identical(other.minDraftPlanPrice, minDraftPlanPrice) ||
other.minDraftPlanPrice == minDraftPlanPrice) &&
(identical(other.maxDraftPlanPrice, maxDraftPlanPrice) ||
other.maxDraftPlanPrice == maxDraftPlanPrice) &&
(identical(other.activeFilterState, activeFilterState) ||
other.activeFilterState == activeFilterState) &&
(identical(other.draftFilterState, draftFilterState) ||
other.draftFilterState == draftFilterState));
}
@override
int get hashCode => Object.hash(
runtimeType,
const DeepCollectionEquality().hash(_activePlans),
const DeepCollectionEquality().hash(_draftPlans),
isLoading,
error,
selectedStateIndex,
minActivePlanPrice,
maxActivePlanPrice,
minDraftPlanPrice,
maxDraftPlanPrice,
activeFilterState,
draftFilterState);
/// Create a copy of MyPlansState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@override
@pragma('vm:prefer-inline')
_$$MyPlansStateImplCopyWith<_$MyPlansStateImpl> get copyWith =>
__$$MyPlansStateImplCopyWithImpl<_$MyPlansStateImpl>(this, _$identity);
}
abstract class _MyPlansState implements MyPlansState {
factory _MyPlansState(
{final List<PlanModel> activePlans,
final List<PlanModel> draftPlans,
final bool isLoading,
final String? error,
final int selectedStateIndex,
final int minActivePlanPrice,
final int maxActivePlanPrice,
final int minDraftPlanPrice,
final int maxDraftPlanPrice,
final PlansFilterState activeFilterState,
final PlansFilterState draftFilterState}) = _$MyPlansStateImpl;
@override
List<PlanModel> get activePlans;
@override
List<PlanModel> get draftPlans;
@override
bool get isLoading;
@override
String? get error;
@override
int get selectedStateIndex;
@override
int get minActivePlanPrice;
@override
int get maxActivePlanPrice;
@override
int get minDraftPlanPrice;
@override
int get maxDraftPlanPrice;
@override
PlansFilterState get activeFilterState;
@override
PlansFilterState get draftFilterState;
/// Create a copy of MyPlansState
/// with the given fields replaced by the non-null parameter values.
@override
@JsonKey(includeFromJson: false, includeToJson: false)
_$$MyPlansStateImplCopyWith<_$MyPlansStateImpl> get copyWith =>
throw _privateConstructorUsedError;
}

View File

@@ -0,0 +1,189 @@
import 'package:easy_debounce/easy_debounce.dart';
import 'package:eatvio_app/core/locator_service.dart';
import 'package:eatvio_app/core/theme/custom_text_style.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/core/widgets/add_item_button.dart';
import 'package:eatvio_app/core/widgets/custom_search_bar.dart';
import 'package:eatvio_app/core/widgets/loader.dart';
import 'package:eatvio_app/features/create_plan/presentation/create_plan_screen.dart';
import 'package:eatvio_app/features/feed/presentation/widgets/filter_badge.dart';
import 'package:eatvio_app/features/feed/presentation/widgets/plans_filter_bottom_sheet.dart';
import 'package:eatvio_app/features/my_plans/presentation/cubit/my_plans_cubit.dart';
import 'package:eatvio_app/features/my_plans/presentation/cubit/my_plans_state.dart';
import 'package:eatvio_app/features/my_plans/presentation/widgets/my_plan_widget.dart';
import 'package:eatvio_app/features/my_plans/presentation/widgets/my_plans_tab.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:go_router/go_router.dart';
class MyPlansScreen extends StatelessWidget {
const MyPlansScreen({super.key});
static const name = 'myPlansScreen';
static const path = '/my-plans-screen';
@override
Widget build(BuildContext context) {
return BlocProvider(create: (context) => sl<MyPlansCubit>()..loadAllPlans(), child: MyPlansScreenContent());
}
}
class MyPlansScreenContent extends StatelessWidget {
MyPlansScreenContent({super.key});
final activePlansScrollController = ScrollController();
final draftPlansScrollController = ScrollController();
final activePlansSearchController = SearchController();
final draftPlansSearchController = SearchController();
@override
Widget build(BuildContext context) {
final s = S.of(context);
return Scaffold(
backgroundColor: appTheme.gray100,
appBar: AppBar(
centerTitle: true,
title: Text(
s.my_plans,
maxLines: 2,
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
softWrap: true,
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
),
),
body: BlocBuilder<MyPlansCubit, MyPlansState>(
buildWhen: (previous, current) => previous.selectedStateIndex != current.selectedStateIndex,
builder: (context, state) {
return NestedScrollView(
controller: switch (state.selectedStateIndex) {
1 => draftPlansScrollController,
_ => activePlansScrollController,
},
headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
return [
SliverAppBar(
shape: RoundedRectangleBorder(
borderRadius: BorderRadius.vertical(bottom: Radius.circular(12)),
),
backgroundColor: appTheme.gray100,
foregroundColor: appTheme.gray100,
automaticallyImplyLeading: false,
stretchTriggerOffset: 1,
floating: true,
primary: false,
snap: true,
scrolledUnderElevation: 0,
bottom: PreferredSize(
preferredSize: Size(
MediaQuery.sizeOf(context).width,
64,
),
child: Padding(
padding: const EdgeInsets.only(bottom: 0),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
SizedBox(height: 8),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 4),
child: MyPlansTab(),
),
SizedBox(height: 8),
Row(
children: [
SizedBox(width: 4),
Expanded(
child: CustomSearchBar(
enableIcon: false,
backgroundColor: appTheme.whiteA700,
borderRadius: 100,
searchController: switch (state.selectedStateIndex) {
1 => draftPlansSearchController,
_ => activePlansSearchController,
},
onChanged: (query) {
EasyDebounce.debounce(
'searchPlans',
Duration(milliseconds: 500),
() {
context.read<MyPlansCubit>().loadPlans(query: query == '' ? null : query);
},
);
},
),
),
SizedBox(width: 12),
AddItemButton(
onTap: () => GoRouter.of(context).pushNamed(CreatePlanScreen.name),
),
SizedBox(width: 4),
],
),
SizedBox(height: 16),
],
),
),
),
),
];
},
body: RefreshIndicator(
onRefresh: () => context.read<MyPlansCubit>().loadPlans(),
child: BlocBuilder<MyPlansCubit, MyPlansState>(
builder: (BuildContext context, MyPlansState state) {
if (state.isLoading) {
return Scaffold(
backgroundColor: Colors.grey.shade200,
body: const Loader(),
);
} else if (state.error != null) {
return Scaffold(
backgroundColor: Colors.grey.shade200,
body: Padding(
padding: const EdgeInsets.all(16),
child: Center(
child: Text(state.error ?? ''),
),
),
);
} else {
final plans = switch (state.selectedStateIndex) {
1 => state.draftPlans,
_ => state.activePlans,
};
return Stack(
children: [
SizedBox.expand(),
ListView.separated(
shrinkWrap: true,
physics: BouncingScrollPhysics(),
itemBuilder: (context, index) {
return MyPlanWidget(plan: plans[index]);
},
separatorBuilder: (context, index) {
return SizedBox(height: 20);
},
itemCount: plans.length,
),
Positioned(
right: 0,
bottom: 74,
child: FilterBadge(
filterBottomSheet: PlansFilterBottomSheet(
myPlansCubit: context.read<MyPlansCubit>(),
),
),
),
],
);
}
},
),
),
);
},
),
);
}
}

View File

@@ -0,0 +1,259 @@
import 'package:cached_network_image/cached_network_image.dart';
import 'package:eatvio_app/core/const.dart';
import 'package:eatvio_app/core/theme/custom_text_style.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/core/widgets/bottom_sheet_handler_bar.dart';
import 'package:eatvio_app/core/widgets/bottom_sheet_with_blur.dart';
import 'package:eatvio_app/core/widgets/custom_outlined_button.dart';
import 'package:eatvio_app/core/widgets/info_row.dart';
import 'package:eatvio_app/features/feed/models/plan_pagination_model.dart';
import 'package:eatvio_app/features/my_plans/presentation/cubit/my_plans_cubit.dart';
import 'package:eatvio_app/features/my_plans/presentation/cubit/my_plans_state.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:flutter_svg/svg.dart';
import 'package:go_router/go_router.dart';
import 'package:share_plus/share_plus.dart';
class MyPlanWidget extends StatefulWidget {
final PlanModel plan;
const MyPlanWidget({
super.key,
required this.plan,
});
@override
State<MyPlanWidget> createState() => _MyPlanWidgetState();
}
class _MyPlanWidgetState extends State<MyPlanWidget> {
@override
Widget build(BuildContext context) {
final s = S.of(context);
return DecoratedBox(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(12),
color: Colors.white,
),
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Stack(
children: [
InkWell(
onTap: () => GoRouter.of(context).pushNamed('aboutPlanScreen', extra: {'plan': widget.plan, 'navigateToComments': false}),
child: ClipRRect(
borderRadius: BorderRadius.vertical(top: Radius.circular(12)),
child: CachedNetworkImage(
imageUrl: baseUrl + '/storage/' + widget.plan.image,
fit: BoxFit.fitWidth,
width: MediaQuery.of(context).size.width,
),
),
),
Positioned(
bottom: 16,
child: SizedBox(
width: MediaQuery.sizeOf(context).width,
child: InfoRow(
plan: widget.plan,
itemsBackgroundColor: appTheme.whiteA700,
disableDescriptionOfTypes: true,
),
),
),
],
),
SizedBox(height: 12),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
widget.plan.name,
style: TextStyles.textMSemibold.copyWith(color: appTheme.black),
),
),
if (widget.plan.details.isNotEmpty) ...[
SizedBox(
height: 12,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Html(
data: widget.plan.details.length > 200 ? widget.plan.details.substring(0, 200) + '...' : widget.plan.details,
style: {
"*": Style(
margin: Margins.zero,
color: appTheme.black,
fontSize: FontSize(TextStyles.textSMedium.fontSize ?? 14),
fontWeight: TextStyles.textSMedium.fontWeight ?? FontWeight.w400,
),
},
),
),
],
],
),
SizedBox(height: 16),
Padding(
padding: EdgeInsets.only(left: 16),
child: Text(
'${widget.plan.packetsCount == 1 ? widget.plan.packet1Options?.price : '${s.from} ${widget.plan.minPriceOfOptions.toStringAsFixed(0)}'}₽',
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.greenA700),
),
),
SizedBox(height: 20),
BlocBuilder<MyPlansCubit, MyPlansState>(
builder: (context, state) {
return Padding(
padding: const EdgeInsets.symmetric(horizontal: 16.0),
child: Column(
children: [
Row(
children: [
Expanded(
child: CustomOutlinedButton(
text: switch (state.selectedStateIndex) {
1 => s.publish,
_ => s.edit,
},
height: 52,
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.whiteA700),
buttonStyle: ButtonStyle(
shape: WidgetStatePropertyAll(RoundedRectangleBorder(borderRadius: BorderRadius.circular(20))),
backgroundColor: WidgetStatePropertyAll(appTheme.blueA400),
side: WidgetStatePropertyAll(BorderSide.none),
),
),
),
if (state.selectedStateIndex == 0) ...[
SizedBox(width: 6),
CustomOutlinedButton(
onPressed: () async {
await Share.shareUri(
Uri.parse(
baseUrl + '/ru/plan/' + widget.plan.id.toString(),
),
);
},
height: 52,
width: 52,
leftIcon: SvgPicture.asset(
'assets/icons/share2.svg',
width: 20,
height: 20,
colorFilter: ColorFilter.mode(appTheme.whiteA700, BlendMode.srcIn),
),
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.red),
buttonStyle: ButtonStyle(
shape: WidgetStatePropertyAll(RoundedRectangleBorder(borderRadius: BorderRadius.circular(20))),
backgroundColor: WidgetStatePropertyAll(appTheme.blueA400),
side: WidgetStatePropertyAll(BorderSide.none),
),
text: '',
),
],
],
),
SizedBox(height: 8),
Row(
children: [
Expanded(
child: CustomOutlinedButton(
text: switch (state.selectedStateIndex) {
0 => s.removeFromActive,
_ => s.edit,
},
height: 52,
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.black),
buttonStyle: ButtonStyle(
shape: WidgetStatePropertyAll(RoundedRectangleBorder(borderRadius: BorderRadius.circular(20))),
backgroundColor: WidgetStatePropertyAll(appTheme.lightGray0),
side: WidgetStatePropertyAll(BorderSide.none),
),
),
),
SizedBox(width: 6),
CustomOutlinedButton(
onPressed: () async {
final result = await context.read<MyPlansCubit>().deletePlan(widget.plan.slug);
if (result)
Future.delayed(Duration(seconds: 3), () {
showBottomSheetWithBlur(
context: context,
child: Column(
children: [
SizedBox(
height: 20,
),
BottomSheetHandlerBar(),
SizedBox(
height: 20,
),
Text(
'${widget.plan.name}',
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
),
Text(
s.deleted,
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
),
SizedBox(
height: 20,
),
Padding(
padding: const EdgeInsets.symmetric(horizontal: 20),
child: CustomOutlinedButton(
onPressed: () {
context.pop();
},
text: 'Хорошо',
height: 52,
buttonTextStyle: TextStyles.textSSemibold.copyWith(color: appTheme.whiteA700),
buttonStyle: ButtonStyle(
side: WidgetStatePropertyAll(BorderSide.none),
backgroundColor: WidgetStatePropertyAll(appTheme.blueA400),
),
),
),
SizedBox(
height: 20,
),
],
),
);
});
},
height: 52,
width: 52,
leftIcon: SvgPicture.asset(
'assets/icons/trash_can.svg',
width: 20,
height: 20,
),
buttonTextStyle: TextStyles.textMSemibold.copyWith(color: appTheme.red),
buttonStyle: ButtonStyle(
shape: WidgetStatePropertyAll(RoundedRectangleBorder(borderRadius: BorderRadius.circular(20))),
backgroundColor: WidgetStatePropertyAll(appTheme.lightGray0),
side: WidgetStatePropertyAll(BorderSide.none),
),
text: '',
),
],
),
SizedBox(height: 8),
],
),
);
},
),
],
),
);
}
}

View File

@@ -0,0 +1,71 @@
import 'package:eatvio_app/core/theme/custom_text_style.dart';
import 'package:eatvio_app/core/theme/theme_helper.dart';
import 'package:eatvio_app/core/widgets/animated_option_button.dart';
import 'package:eatvio_app/features/my_plans/presentation/cubit/my_plans_cubit.dart';
import 'package:eatvio_app/features/my_plans/presentation/cubit/my_plans_state.dart';
import 'package:eatvio_app/generated/l10n.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class MyPlansTab extends StatefulWidget {
const MyPlansTab({super.key, this.additionalOnTap});
final void Function()? additionalOnTap;
@override
State<MyPlansTab> createState() => _MyPlansTabState();
}
class _MyPlansTabState extends State<MyPlansTab> {
final List<String> tabTitles = [];
@override
void didChangeDependencies() {
final s = S.of(context);
if (tabTitles.isEmpty) {
tabTitles.add(s.published);
tabTitles.add(s.drafted);
}
super.didChangeDependencies();
}
@override
Widget build(BuildContext context) {
return BlocBuilder<MyPlansCubit, MyPlansState>(
builder: (context, state) {
return Align(
alignment: Alignment.centerLeft,
child: Row(
children: [
Expanded(
child: Container(
height: 48,
decoration: BoxDecoration(
color: appTheme.whiteA700,
borderRadius: BorderRadius.circular(100),
),
padding: const EdgeInsets.all(4),
child: Row(
children: [
...List.generate(
2,
(index) => Expanded(
child: AnimatedOptionButton(
textStyle: TextStyles.textSMedium,
isSelected: state.selectedStateIndex == index,
text: tabTitles[index],
onTap: () {
widget.additionalOnTap?.call();
context.read<MyPlansCubit>().changeSelectedStateIndex(index);
},
),
),
),
],
),
),
),
],
),
);
},
);
}
}