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

106 lines
4.4 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_recipes_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';
import 'package:eatvio_app/features/create_recipe/presentation/pages/recipe_create_screen.dart';
import 'package:go_router/go_router.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 Stack(
children: [
Positioned.fill(
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.only(top: 80, bottom: 16),
itemBuilder: (context, index) => MyRecipeWidget(recipe: state.recipes[index]),
separatorBuilder: (context, index) => const SizedBox(height: 12),
itemCount: state.recipes.length,
)
: const Center(child: CircularProgressIndicator()),
),
Positioned(
top: 16,
left: 16,
right: 16,
child: Row(
children: [
Expanded(
child: 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();
}
},
),
),
const SizedBox(width: 8),
InkWell(
onTap: () {
context.push(RecipeCreateScreen.path);
},
borderRadius: BorderRadius.circular(100),
child: Container(
width: 48,
height: 48,
decoration: BoxDecoration(
color: appTheme.blueA400,
shape: BoxShape.circle,
),
child: Icon(
Icons.add,
color: appTheme.whiteA700,
size: 24,
),
),
),
],
),
),
],
);
},
),
),
);
}
}