go router 2

This commit is contained in:
mso7nueh
2024-06-06 13:42:46 +03:00
parent 8de91e6f7e
commit d49030c3dd
28 changed files with 219 additions and 271 deletions

View File

@@ -28,9 +28,7 @@ class RecipeCreateBloc extends Bloc<RecipeCreateEvent, RecipeCreateState> {
final box = await Hive.openBox('token');
final token = box.get('token');
if (token == null) {
NavigatorService.popAndPushNamed(
AppRoutes.authScreen,
);
// go to auth screen
}
if (state is RecipeCreateLoadedState) {
var currentState = state as RecipeCreateLoadedState;

View File

@@ -29,9 +29,7 @@ class RecipeEditBloc extends Bloc<RecipeEditEvent, RecipeEditState> {
final box = await Hive.openBox('token');
final token = box.get('token');
if (token == null) {
NavigatorService.popAndPushNamed(
AppRoutes.authScreen,
);
// go to auth screen
}
final String? recipeID = state.recipeModelObj?.recipeID;
final response = await http.get(

View File

@@ -28,9 +28,7 @@ class RecipeSelectBloc extends Bloc<RecipeSelectEvent, RecipeSelectState> {
final box = await Hive.openBox('token');
final token = box.get('token');
if (token == null) {
NavigatorService.popAndPushNamed(
AppRoutes.authScreen,
); // Если токен есть, запускаем приложение
// go to auth screen
}
final response = await http.get(
Uri.parse(dotenv.env['SERVER_ROOT']! + '/recipe/index'),

View File

@@ -13,9 +13,7 @@ import 'package:flutter/material.dart';
class RecipeSelectScreen extends StatelessWidget {
static Widget builder(BuildContext context) {
return BlocProvider<RecipeSelectBloc>(
create: (context) => RecipeSelectBloc(
RecipeSelectState(myProfileModelObj: RecipeSelectModel()))
..add(RecipeSelectInitialEvent()),
create: (context) => RecipeSelectBloc(RecipeSelectState(myProfileModelObj: RecipeSelectModel()))..add(RecipeSelectInitialEvent()),
child: RecipeSelectScreen());
}
@@ -23,17 +21,20 @@ class RecipeSelectScreen extends StatelessWidget {
return BlocBuilder<RecipeSelectBloc, RecipeSelectState>(
builder: (context, state) {
if (state is RecipeSelectInitialState) {
// Это начальное состояние, данные ещё не загружены.
return CircularProgressIndicator(
color: Colors.white,
backgroundColor: Colors.white,
return Scaffold(
body: Center(
child: CircularProgressIndicator(),
),
);
} else if (state is RecipeSelectLoadedState) {
// Данные загружены, можно строить экран.
return _buildRecipeScreen(context, state);
} else {
// Другие состояния, если они есть.
return Container(); // Пустой контейнер для необработанных состояний.
return Scaffold(
body: Center(
child: CircularProgressIndicator(),
),
);
}
},
);
@@ -75,8 +76,7 @@ class RecipeSelectScreen extends StatelessWidget {
leadingWidth: 28.h,
leading: AppbarLeadingImage(
imagePath: ImageConstant.imgArrowLeft,
margin: EdgeInsets.only(
left: 16.h, top: 15.v, bottom: 15.v),
margin: EdgeInsets.only(left: 16.h, top: 15.v, bottom: 15.v),
onTap: () => GoRouter.of(context).pop(),
),
title: Padding(
@@ -85,8 +85,7 @@ class RecipeSelectScreen extends StatelessWidget {
children: [
AppbarSubtitle(
text: "Рецепты",
margin: EdgeInsets.only(
left: 80.h, top: 12.v, bottom: 9.v),
margin: EdgeInsets.only(left: 80.h, top: 12.v, bottom: 9.v),
),
Spacer(),
Padding(

View File

@@ -29,9 +29,7 @@ class RecipeBloc extends Bloc<RecipeEvent, RecipeState> {
final box = await Hive.openBox('token');
final token = box.get('token');
if (token == null) {
NavigatorService.popAndPushNamed(
AppRoutes.authScreen,
);
// go to auth screen
}
final String? recipeID = state.recipeModelObj?.recipeID;
final response = await http.get(