Files
eatvio_app/lib/features/recipe/presentation/pages/my_recipes_screen.dart

77 lines
3.2 KiB
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/features/recipe/presentation/cubit/my_recipes_cubit/my_recieps_cubit.dart';
import 'package:eatvio_app/features/recipe/presentation/cubit/my_recipes_cubit/my_recipes_state.dart';
import 'package:eatvio_app/features/recipe/presentation/widgets/my_recipe_widget.dart';
import 'package:eatvio_app/features/recipe/presentation/widgets/my_recipes_tab.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bloc/flutter_bloc.dart';
class MyRecipesScreen extends StatelessWidget {
const MyRecipesScreen({super.key});
static const name = 'myRecipesScreen';
static const path = '/my-recipes-screen';
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: appTheme.gray100,
appBar: AppBar(
centerTitle: true,
title: Text(
'Мои рецепты',
maxLines: 2,
textAlign: TextAlign.center,
overflow: TextOverflow.ellipsis,
softWrap: true,
style: TextStyles.headingXLSemibold.copyWith(color: appTheme.black),
),
),
body: BlocProvider<MyRecipesCubit>(
create: (BuildContext context) => sl<MyRecipesCubit>()..getMyRecipes(),
child: BlocBuilder<MyRecipesCubit, MyRecipesState>(
builder: (BuildContext context, MyRecipesState state) {
return Column(
children: [
MyRecipesTab(
selectedIndex: state is MyRecipesStateLoaded
? (state.selectedState == MyRecipesCubit.drafted ? 1 : 0)
: 0,
onTabChanged: (index) {
if (index == 0) {
context.read<MyRecipesCubit>().setActiveState();
} else {
context.read<MyRecipesCubit>().setDraftedState();
}
},
),
Expanded(
child: state is MyRecipesStateLoaded
? state.recipes.isEmpty
? Center(
child: Text(
state.selectedState == MyRecipesCubit.drafted
? 'Нет черновиков'
: 'Нет опубликованных рецептов',
style: TextStyles.textLMedium.copyWith(color: appTheme.gray500),
),
)
: ListView.separated(
padding: const EdgeInsets.symmetric(vertical: 16),
itemBuilder: (context, index) => MyRecipeWidget(recipe: state.recipes[index]),
separatorBuilder: (context, index) => const SizedBox(height: 12),
itemCount: state.recipes.length,
)
: const Center(child: CircularProgressIndicator()),
),
],
);
},
),
),
);
}
}