forked from eatvio/eatvio_app
refactor(all): refactor
This commit is contained in:
@@ -1,6 +1,8 @@
|
||||
import 'dart:async';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:eatvio_app/app_router.dart';
|
||||
import 'package:eatvio_app/locator_service.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import '/core/app_export.dart';
|
||||
@@ -31,27 +33,29 @@ class RecipeSelectBloc extends Bloc<RecipeSelectEvent, RecipeSelectState> {
|
||||
if (token == null) {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
final response = await http.get(
|
||||
Uri.parse(dotenv.env['SERVER_ROOT']! + '/recipe/index'),
|
||||
);
|
||||
final response = await sl<Dio>().get(dotenv.env['SERVER_ROOT']! + '/recipes/index');
|
||||
print('Got response');
|
||||
if (response.statusCode == 200) {
|
||||
print('Got 200');
|
||||
final data = jsonDecode(response.body);
|
||||
final data = response.data['data'];
|
||||
if (data is List<dynamic>) {
|
||||
print('Got List');
|
||||
if (state is RecipeSelectLoadedState) {
|
||||
print('Got loaded');
|
||||
var currentState = state as RecipeSelectLoadedState;
|
||||
emit((currentState).copyWith(
|
||||
posts: data,
|
||||
myProfileModelObj: currentState.myProfileModelObj,
|
||||
),);
|
||||
emit(
|
||||
(currentState).copyWith(
|
||||
posts: data,
|
||||
myProfileModelObj: currentState.myProfileModelObj,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
print('Got unloaded');
|
||||
emit(RecipeSelectLoadedState(
|
||||
posts: data,
|
||||
),);
|
||||
emit(
|
||||
RecipeSelectLoadedState(
|
||||
posts: data,
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Один или несколько ключевых полей отсутствуют, обрабатываем ошибку
|
||||
|
||||
@@ -12,14 +12,12 @@ class RecipeSelectState extends Equatable {
|
||||
}
|
||||
|
||||
class RecipeSelectInitialState extends RecipeSelectState {
|
||||
RecipeSelectInitialState({required RecipeSelectModel myProfileModelObj})
|
||||
: super(myProfileModelObj: myProfileModelObj);
|
||||
RecipeSelectInitialState({required RecipeSelectModel myProfileModelObj}) : super(myProfileModelObj: myProfileModelObj);
|
||||
}
|
||||
|
||||
/// Represents the state of RecipeSelect in the application.
|
||||
class RecipeSelectLoadedState extends RecipeSelectState {
|
||||
RecipeSelectLoadedState({this.myProfileModelObj, this.posts})
|
||||
: super(myProfileModelObj: null);
|
||||
RecipeSelectLoadedState({this.myProfileModelObj, this.posts}) : super(myProfileModelObj: null);
|
||||
|
||||
RecipeSelectModel? myProfileModelObj;
|
||||
List<dynamic>? posts;
|
||||
|
||||
@@ -112,6 +112,7 @@ class RecipeSelectScreen extends StatelessWidget {
|
||||
|
||||
_buildRecipeList(BuildContext context, RecipeSelectLoadedState state) {
|
||||
return ListView.builder(
|
||||
physics: NeverScrollableScrollPhysics(),
|
||||
shrinkWrap: true, // Add this line
|
||||
itemCount: state.posts?.length ?? 0,
|
||||
itemBuilder: (context, index) {
|
||||
|
||||
Reference in New Issue
Block a user