forked from eatvio/eatvio_app
feature(registration): remove .env
This commit is contained in:
@@ -1,15 +1,16 @@
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:eatvio_app/app_router.dart';
|
||||
import 'package:eatvio_app/presentation/glossary/glossary_screen/models/glossary_screen_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/glossary/glossary_screen/models/glossary_screen_model.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
|
||||
part 'glossary_screen_event.dart';
|
||||
part 'glossary_screen_state.dart';
|
||||
|
||||
@@ -31,7 +32,7 @@ class GlossaryBloc extends Bloc<GlossaryEvent, GlossaryState> {
|
||||
AppRouter.navigatorKey.currentContext?.goNamed('authScreen');
|
||||
}
|
||||
final responseProductGroups = await http.get(
|
||||
Uri.parse(dotenv.env['SERVER_ROOT']! + '/glossary/getProductGroups'),
|
||||
Uri.parse(baseUrl + '/api/glossary/getProductGroups'),
|
||||
headers: {
|
||||
'Authorization': 'Bearer $token',
|
||||
},
|
||||
@@ -41,18 +42,23 @@ class GlossaryBloc extends Bloc<GlossaryEvent, GlossaryState> {
|
||||
if (dataProductGroups is List<dynamic>) {
|
||||
if (state is GlossaryLoadedState) {
|
||||
var currentState = state as GlossaryLoadedState;
|
||||
emit(currentState.copyWith(
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
glossaryModelObj: currentState.glossaryModelObj,
|
||||
token: currentState.token,
|
||||
productGroups: currentState.productGroups,
|
||||
productList: currentState.productList,),);
|
||||
productList: currentState.productList,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
List<SelectionPopupModel> productGroupsModel =
|
||||
_fillProductGroups(dataProductGroups);
|
||||
emit(GlossaryLoadedState(
|
||||
List<SelectionPopupModel> productGroupsModel = _fillProductGroups(dataProductGroups);
|
||||
emit(
|
||||
GlossaryLoadedState(
|
||||
token: token,
|
||||
productGroups: productGroupsModel,
|
||||
productList: [],),);
|
||||
productList: [],
|
||||
),
|
||||
);
|
||||
await _getProductListById(token, emit, productGroupsModel[0].id);
|
||||
}
|
||||
} else {
|
||||
@@ -61,8 +67,11 @@ class GlossaryBloc extends Bloc<GlossaryEvent, GlossaryState> {
|
||||
}
|
||||
} else {
|
||||
// Статус ответа не равен 200, обрабатываем ошибку
|
||||
emit(GlossaryErrorState(
|
||||
'Ошибка сервера: ${responseProductGroups.statusCode}',),);
|
||||
emit(
|
||||
GlossaryErrorState(
|
||||
'Ошибка сервера: ${responseProductGroups.statusCode}',
|
||||
),
|
||||
);
|
||||
}
|
||||
} catch (e) {
|
||||
// Ошибка при декодировании JSON или другая ошибка выполнения
|
||||
@@ -71,7 +80,9 @@ class GlossaryBloc extends Bloc<GlossaryEvent, GlossaryState> {
|
||||
}
|
||||
|
||||
void _changeProductGroup(
|
||||
ChangeProductGroup event, Emitter<GlossaryState> emit,) async {
|
||||
ChangeProductGroup event,
|
||||
Emitter<GlossaryState> emit,
|
||||
) async {
|
||||
if (state is GlossaryLoadedState) {
|
||||
var currentState = state as GlossaryLoadedState;
|
||||
await _getProductListById(currentState.token, emit, event.id);
|
||||
@@ -79,9 +90,12 @@ class GlossaryBloc extends Bloc<GlossaryEvent, GlossaryState> {
|
||||
}
|
||||
|
||||
Future<void> _getProductListById(
|
||||
token, Emitter<GlossaryState> emit, int? productGroupID,) async {
|
||||
token,
|
||||
Emitter<GlossaryState> emit,
|
||||
int? productGroupID,
|
||||
) async {
|
||||
final responseProductList = await http.get(
|
||||
Uri.parse(dotenv.env['SERVER_ROOT']! + '/glossary/index/$productGroupID'),
|
||||
Uri.parse(baseUrl + '/api/glossary/index/$productGroupID'),
|
||||
headers: {
|
||||
'Content-Type': 'application/json',
|
||||
'Authorization': 'Bearer $token',
|
||||
@@ -90,10 +104,13 @@ class GlossaryBloc extends Bloc<GlossaryEvent, GlossaryState> {
|
||||
final dataProductList = jsonDecode(responseProductList.body);
|
||||
if (dataProductList is List<dynamic>) {
|
||||
var currentState = state as GlossaryLoadedState;
|
||||
emit(currentState.copyWith(
|
||||
emit(
|
||||
currentState.copyWith(
|
||||
glossaryModelObj: currentState.glossaryModelObj,
|
||||
productGroups: currentState.productGroups,
|
||||
productList: dataProductList,),);
|
||||
productList: dataProductList,
|
||||
),
|
||||
);
|
||||
} else {
|
||||
emit(GlossaryErrorState('Список продуктов некорректного формата'));
|
||||
}
|
||||
|
||||
@@ -22,24 +22,25 @@ class GlossaryState extends Equatable {
|
||||
}
|
||||
|
||||
class GlossaryLoadedState extends GlossaryState {
|
||||
GlossaryLoadedState(
|
||||
{this.glossaryModelObj,
|
||||
this.productGroups,
|
||||
this.productList,
|
||||
this.token,});
|
||||
GlossaryLoadedState({
|
||||
this.glossaryModelObj,
|
||||
this.productGroups,
|
||||
this.productList,
|
||||
this.token,
|
||||
});
|
||||
|
||||
GlossaryModel? glossaryModelObj;
|
||||
String? token;
|
||||
List<SelectionPopupModel>? productGroups;
|
||||
List<dynamic>? productList;
|
||||
@override
|
||||
List<Object?> get props =>
|
||||
[glossaryModelObj, productGroups, productList, token];
|
||||
GlossaryLoadedState copyWith(
|
||||
{GlossaryModel? glossaryModelObj,
|
||||
String? token,
|
||||
List<SelectionPopupModel>? productGroups,
|
||||
List<dynamic>? productList,}) {
|
||||
List<Object?> get props => [glossaryModelObj, productGroups, productList, token];
|
||||
GlossaryLoadedState copyWith({
|
||||
GlossaryModel? glossaryModelObj,
|
||||
String? token,
|
||||
List<SelectionPopupModel>? productGroups,
|
||||
List<dynamic>? productList,
|
||||
}) {
|
||||
return GlossaryLoadedState(
|
||||
glossaryModelObj: glossaryModelObj ?? this.glossaryModelObj,
|
||||
productGroups: productGroups ?? this.productGroups,
|
||||
@@ -59,6 +60,5 @@ class GlossaryErrorState extends GlossaryState {
|
||||
}
|
||||
|
||||
class GlossaryInitialState extends GlossaryState {
|
||||
GlossaryInitialState({required GlossaryModel glossaryModelObj})
|
||||
: super(glossaryModelObj: glossaryModelObj);
|
||||
GlossaryInitialState({required GlossaryModel glossaryModelObj}) : super(glossaryModelObj: glossaryModelObj);
|
||||
}
|
||||
|
||||
@@ -1,20 +1,22 @@
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:eatvio_app/core/app_export.dart';
|
||||
import 'package:eatvio_app/presentation/glossary/glossary_screen/widgets/glossary_scroll_item.dart';
|
||||
import 'package:eatvio_app/presentation/glossary/glossary_screen/widgets/glossary_search_widget.dart';
|
||||
import 'package:eatvio_app/widgets/custom_drop_down.dart';
|
||||
import 'package:eatvio_app/widgets/custom_outlined_button.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'bloc/glossary_screen_bloc.dart';
|
||||
import 'models/glossary_screen_model.dart';
|
||||
import 'package:eatvio_app/core/app_export.dart';
|
||||
import 'package:cached_network_image/cached_network_image.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_dotenv/flutter_dotenv.dart';
|
||||
import 'package:eatvio_app/widgets/custom_outlined_button.dart';
|
||||
import 'package:eatvio_app/widgets/custom_drop_down.dart';
|
||||
import 'package:eatvio_app/presentation/glossary/glossary_screen/widgets/glossary_search_widget.dart';
|
||||
import 'package:eatvio_app/presentation/glossary/glossary_screen/widgets/glossary_scroll_item.dart';
|
||||
|
||||
class GlossaryScreen extends StatelessWidget {
|
||||
const GlossaryScreen({Key? key}) : super(key: key);
|
||||
|
||||
static Widget builder(BuildContext context) {
|
||||
return BlocProvider<GlossaryBloc>(
|
||||
create: (context) => GlossaryBloc(GlossaryState(glossaryModelObj: GlossaryModel()))..add(GlossaryInitialEvent()), child: GlossaryScreen(),);
|
||||
create: (context) => GlossaryBloc(GlossaryState(glossaryModelObj: GlossaryModel()))..add(GlossaryInitialEvent()),
|
||||
child: GlossaryScreen(),
|
||||
);
|
||||
}
|
||||
|
||||
Widget build(BuildContext context) {
|
||||
@@ -125,24 +127,26 @@ class GlossaryScreen extends StatelessWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(children: [
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
"Поиск по алфавиту",
|
||||
style: CustomTextStyles.titleMediumSemiBold,
|
||||
child: Column(
|
||||
children: [
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
"Поиск по алфавиту",
|
||||
style: CustomTextStyles.titleMediumSemiBold,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: List.generate(33, _fillAlphabet),
|
||||
SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
),
|
||||
],),
|
||||
SingleChildScrollView(
|
||||
scrollDirection: Axis.horizontal,
|
||||
child: Row(
|
||||
children: List.generate(33, _fillAlphabet),
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -162,42 +166,44 @@ class GlossaryScreen extends StatelessWidget {
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(children: [
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
"Группа продуктов",
|
||||
style: CustomTextStyles.titleMediumSemiBold,
|
||||
child: Column(
|
||||
children: [
|
||||
Align(
|
||||
alignment: Alignment.centerLeft,
|
||||
child: Text(
|
||||
"Группа продуктов",
|
||||
style: CustomTextStyles.titleMediumSemiBold,
|
||||
),
|
||||
),
|
||||
),
|
||||
SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
CustomDropDown(
|
||||
items: state.productGroups,
|
||||
value: state.productGroups?[0],
|
||||
fillColor: Colors.grey[200]!,
|
||||
hintText: 'Выберите категорию',
|
||||
borderDecoration: OutlineInputBorder(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
||||
borderSide: BorderSide(color: Colors.grey[200]!, width: 1),
|
||||
SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 9,
|
||||
CustomDropDown(
|
||||
items: state.productGroups,
|
||||
value: state.productGroups?[0],
|
||||
fillColor: Colors.grey[200]!,
|
||||
hintText: 'Выберите категорию',
|
||||
borderDecoration: OutlineInputBorder(
|
||||
borderRadius: const BorderRadius.all(Radius.circular(8)),
|
||||
borderSide: BorderSide(color: Colors.grey[200]!, width: 1),
|
||||
),
|
||||
contentPadding: EdgeInsets.symmetric(
|
||||
horizontal: 10,
|
||||
vertical: 9,
|
||||
),
|
||||
onChanged: _changeProductGroup(context, state),
|
||||
width: MediaQuery.of(context).size.width, // Set a percentage value as per your layout
|
||||
),
|
||||
onChanged: _changeProductGroup(context, state),
|
||||
width: MediaQuery.of(context).size.width, // Set a percentage value as per your layout
|
||||
),
|
||||
SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
Align(alignment: Alignment.centerLeft, child: Text("*КБЖУ указано за 100гр")),
|
||||
SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
_buildProductList(context, state),
|
||||
],),
|
||||
SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
Align(alignment: Alignment.centerLeft, child: Text("*КБЖУ указано за 100гр")),
|
||||
SizedBox(
|
||||
height: 8,
|
||||
),
|
||||
_buildProductList(context, state),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
@@ -218,23 +224,24 @@ class GlossaryScreen extends StatelessWidget {
|
||||
|
||||
_buildProductEntry(product, BuildContext context) {
|
||||
return Container(
|
||||
margin: EdgeInsets.only(bottom: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withOpacity(0.5),
|
||||
spreadRadius: 1,
|
||||
blurRadius: 3,
|
||||
offset: Offset(0, 3),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(children: [
|
||||
margin: EdgeInsets.only(bottom: 10),
|
||||
decoration: BoxDecoration(
|
||||
color: Colors.white,
|
||||
borderRadius: const BorderRadius.all(Radius.circular(12)),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.grey.withOpacity(0.5),
|
||||
spreadRadius: 1,
|
||||
blurRadius: 3,
|
||||
offset: Offset(0, 3),
|
||||
),
|
||||
],
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
ListTile(
|
||||
trailing: CachedNetworkImage(
|
||||
imageUrl: dotenv.env['STORAGE_URL']! + (product['image'] ?? ''),
|
||||
imageUrl: baseUrl + '/storage/' + (product['image'] ?? ''),
|
||||
imageBuilder: (context, imageProvider) => CircleAvatar(
|
||||
backgroundImage: imageProvider,
|
||||
radius: 25,
|
||||
@@ -255,26 +262,34 @@ class GlossaryScreen extends StatelessWidget {
|
||||
padding: const EdgeInsets.all(16.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Row(children: [
|
||||
Column(children: [
|
||||
Text("Ккал - ${product['energy_on_100gr'].toString()}"),
|
||||
SizedBox(height: 8),
|
||||
Text("Белки - ${product['proteins_on_100gr'].toString()}"),
|
||||
],),
|
||||
Spacer(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 24.0),
|
||||
child: Column(children: [
|
||||
Text("Жиры - ${product['fats_on_100gr'].toString()}"),
|
||||
SizedBox(height: 8),
|
||||
Text("Углеводы - ${product['carbohydrates_on_100gr'].toString()}"),
|
||||
],),
|
||||
),
|
||||
],),
|
||||
Row(
|
||||
children: [
|
||||
Column(
|
||||
children: [
|
||||
Text("Ккал - ${product['energy_on_100gr'].toString()}"),
|
||||
SizedBox(height: 8),
|
||||
Text("Белки - ${product['proteins_on_100gr'].toString()}"),
|
||||
],
|
||||
),
|
||||
Spacer(),
|
||||
Padding(
|
||||
padding: const EdgeInsets.only(right: 24.0),
|
||||
child: Column(
|
||||
children: [
|
||||
Text("Жиры - ${product['fats_on_100gr'].toString()}"),
|
||||
SizedBox(height: 8),
|
||||
Text("Углеводы - ${product['carbohydrates_on_100gr'].toString()}"),
|
||||
],
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
],),);
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _fillAlphabet(int index) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:eatvio_app/core/app_export.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class ScrollItem extends StatelessWidget {
|
||||
final String title;
|
||||
|
||||
@@ -1,31 +1,31 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:eatvio_app/core/app_export.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
class CustomSearchView extends StatelessWidget {
|
||||
CustomSearchView(
|
||||
{Key? key,
|
||||
this.alignment,
|
||||
this.width,
|
||||
this.scrollPadding,
|
||||
this.controller,
|
||||
this.focusNode,
|
||||
this.autofocus = false,
|
||||
this.textStyle,
|
||||
this.textInputType = TextInputType.text,
|
||||
this.maxLines,
|
||||
this.hintText,
|
||||
this.hintStyle,
|
||||
this.prefix,
|
||||
this.prefixConstraints,
|
||||
this.suffix,
|
||||
this.suffixConstraints,
|
||||
this.contentPadding,
|
||||
this.borderDecoration,
|
||||
this.fillColor,
|
||||
this.filled = true,
|
||||
this.validator,
|
||||
this.onChanged,})
|
||||
: super(
|
||||
CustomSearchView({
|
||||
Key? key,
|
||||
this.alignment,
|
||||
this.width,
|
||||
this.scrollPadding,
|
||||
this.controller,
|
||||
this.focusNode,
|
||||
this.autofocus = false,
|
||||
this.textStyle,
|
||||
this.textInputType = TextInputType.text,
|
||||
this.maxLines,
|
||||
this.hintText,
|
||||
this.hintStyle,
|
||||
this.prefix,
|
||||
this.prefixConstraints,
|
||||
this.suffix,
|
||||
this.suffixConstraints,
|
||||
this.contentPadding,
|
||||
this.borderDecoration,
|
||||
this.fillColor,
|
||||
this.filled = true,
|
||||
this.validator,
|
||||
this.onChanged,
|
||||
}) : super(
|
||||
key: key,
|
||||
);
|
||||
|
||||
@@ -76,15 +76,15 @@ class CustomSearchView extends StatelessWidget {
|
||||
return alignment != null
|
||||
? Align(
|
||||
alignment: alignment ?? Alignment.center,
|
||||
child: searchViewWidget(context),)
|
||||
child: searchViewWidget(context),
|
||||
)
|
||||
: searchViewWidget(context);
|
||||
}
|
||||
|
||||
searchViewWidget(BuildContext context) => SizedBox(
|
||||
width: width ?? double.maxFinite,
|
||||
child: TextFormField(
|
||||
scrollPadding:
|
||||
EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
|
||||
scrollPadding: EdgeInsets.only(bottom: MediaQuery.of(context).viewInsets.bottom),
|
||||
controller: controller,
|
||||
focusNode: focusNode,
|
||||
onTapOutside: (event) => onTapOutside(),
|
||||
@@ -112,8 +112,9 @@ class CustomSearchView extends StatelessWidget {
|
||||
prefixIcon: prefix ??
|
||||
SizedBox(
|
||||
child: Padding(
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Icon(Icons.search),),
|
||||
padding: EdgeInsets.only(left: 10),
|
||||
child: Icon(Icons.search),
|
||||
),
|
||||
),
|
||||
prefixIconConstraints: prefixConstraints ??
|
||||
BoxConstraints(
|
||||
|
||||
Reference in New Issue
Block a user