forked from eatvio/eatvio_app
feature(registration): remove .env
This commit is contained in:
@@ -1,18 +1,17 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:eatvio_app/app_router.dart';
|
||||
import 'package:eatvio_app/presentation/plans/plan_edit_screen/models/plan_edit_model.dart';
|
||||
import 'package:equatable/equatable.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:hive/hive.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert';
|
||||
|
||||
import '/core/app_export.dart';
|
||||
import 'package:eatvio_app/presentation/plans/plan_edit_screen/models/plan_edit_model.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
part 'plan_edit_event.dart';
|
||||
|
||||
part 'plan_edit_state.dart';
|
||||
|
||||
/// A bloc that manages the state of a PlanEdit according to the event that is dispatched to it.
|
||||
@@ -34,7 +33,7 @@ class PlanEditBloc extends Bloc<PlanEditEvent, PlanEditState> {
|
||||
}
|
||||
final String? planID = state.planModelObj?.planID;
|
||||
final response = await http.get(
|
||||
Uri.parse(dotenv.env['SERVER_ROOT']! + '/plans/show/$planID'),
|
||||
Uri.parse(baseUrl + '/api/plans/show/$planID'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
@@ -44,18 +43,24 @@ class PlanEditBloc extends Bloc<PlanEditEvent, PlanEditState> {
|
||||
if (data is Map<String, dynamic>) {
|
||||
if (state is PlanEditLoadedState) {
|
||||
var currentState = state as PlanEditLoadedState;
|
||||
emit(currentState.copyWith(
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
planModelObj: currentState.planModelObj,
|
||||
plan: currentState.plan,
|
||||
name: currentState.name,
|
||||
duration: currentState.duration,
|
||||
details: currentState.details,),);
|
||||
details: currentState.details,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
emit(PlanEditLoadedState(
|
||||
emit(
|
||||
PlanEditLoadedState(
|
||||
plan: data,
|
||||
name: TextEditingController(text: data['name']),
|
||||
details: TextEditingController(text: data['details']),
|
||||
duration: TextEditingController(text: data['duration'].toString()),),);
|
||||
duration: TextEditingController(text: data['duration'].toString()),
|
||||
),
|
||||
);
|
||||
}
|
||||
} else {
|
||||
// Один или несколько ключевых полей отсутствуют, обрабатываем ошибку
|
||||
@@ -96,7 +101,7 @@ class PlanEditBloc extends Bloc<PlanEditEvent, PlanEditState> {
|
||||
String? duration,
|
||||
) async {
|
||||
int id = plan?['id'];
|
||||
String url = '${dotenv.env['SERVER_ROOT']!}/plans/update/$id';
|
||||
String url = '${baseUrl}/api/plans/update/$id';
|
||||
|
||||
final Map<String, dynamic> credentials = {
|
||||
'id': id,
|
||||
|
||||
@@ -22,8 +22,13 @@ class PlanEditState extends Equatable {
|
||||
}
|
||||
|
||||
class PlanEditLoadedState extends PlanEditState {
|
||||
PlanEditLoadedState(
|
||||
{this.planModelObj, this.plan, this.name, this.details, this.duration,});
|
||||
PlanEditLoadedState({
|
||||
this.planModelObj,
|
||||
this.plan,
|
||||
this.name,
|
||||
this.details,
|
||||
this.duration,
|
||||
});
|
||||
|
||||
PlanEditModel? planModelObj;
|
||||
Map<String, dynamic>? plan;
|
||||
@@ -59,6 +64,5 @@ class PlanEditErrorState extends PlanEditState {
|
||||
}
|
||||
|
||||
class PlanEditInitialState extends PlanEditState {
|
||||
PlanEditInitialState({required PlanEditModel planModelObj})
|
||||
: super(planModelObj: planModelObj);
|
||||
PlanEditInitialState({required PlanEditModel planModelObj}) : super(planModelObj: planModelObj);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,9 @@
|
||||
import 'bloc/plan_edit_bloc.dart';
|
||||
import 'models/plan_edit_model.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:eatvio_app/core/app_export.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
|
||||
import 'bloc/plan_edit_bloc.dart';
|
||||
import 'models/plan_edit_model.dart';
|
||||
|
||||
class PlanEditScreen extends StatelessWidget {
|
||||
const PlanEditScreen({Key? key}) : super(key: key);
|
||||
@@ -11,8 +11,9 @@ class PlanEditScreen extends StatelessWidget {
|
||||
static Widget builder(BuildContext context) {
|
||||
final planID = ModalRoute.of(context)!.settings.arguments;
|
||||
return BlocProvider<PlanEditBloc>(
|
||||
create: (context) => PlanEditBloc(PlanEditState(planModelObj: PlanEditModel(planID: planID.toString())))..add(PlanEditInitialEvent()),
|
||||
child: PlanEditScreen(),);
|
||||
create: (context) => PlanEditBloc(PlanEditState(planModelObj: PlanEditModel(planID: planID.toString())))..add(PlanEditInitialEvent()),
|
||||
child: PlanEditScreen(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
@@ -71,7 +72,7 @@ class PlanEditScreen extends StatelessWidget {
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: [
|
||||
CachedNetworkImage(
|
||||
imageUrl: dotenv.env['STORAGE_URL']! + (state.plan?['image'] ?? ''),
|
||||
imageUrl: baseUrl + '/storage/' + (state.plan?['image'] ?? ''),
|
||||
imageBuilder: (context, imageProvider) => CircleAvatar(
|
||||
backgroundImage: imageProvider,
|
||||
radius: 25,
|
||||
|
||||
Reference in New Issue
Block a user