forked from eatvio/eatvio_app
feat(app): refactoring of sentry using, feat(become_consultant): fixed possible infinite loading, feat(push_notifications): fixed push navigation from paid plan push
This commit is contained in:
@@ -13,9 +13,9 @@ import 'package:eatvio_app/features/glossary/models/glossary_model.dart';
|
||||
import 'package:eatvio_app/features/glossary/repositories/glossary_repository.dart';
|
||||
import 'package:eatvio_app/features/profile/repositories/profile_repository.dart';
|
||||
import 'package:flutter_bloc/flutter_bloc.dart';
|
||||
import 'package:eatvio_app/core/error_reporting/report_from.dart';
|
||||
import 'package:flutter_image_compress/flutter_image_compress.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'package:sentry_flutter/sentry_flutter.dart';
|
||||
import 'package:path_provider/path_provider.dart';
|
||||
|
||||
class CreateDietCubit extends Cubit<CreateDietState> {
|
||||
@@ -29,9 +29,10 @@ class CreateDietCubit extends Cubit<CreateDietState> {
|
||||
|
||||
Future<void> setInitialData(Diet? diet) async {
|
||||
if (diet == null) return;
|
||||
emit(state.copyWith(isLoading: true, isDietBeingEdited: true));
|
||||
dietId = diet.id;
|
||||
final dailyScheduleWithNutrition = await createDietRepository.getDietPortionsNutrition(diet.id);
|
||||
try {
|
||||
emit(state.copyWith(isLoading: true, isDietBeingEdited: true));
|
||||
dietId = diet.id;
|
||||
final dailyScheduleWithNutrition = await createDietRepository.getDietPortionsNutrition(diet.id);
|
||||
final countOfDays = diet.duration;
|
||||
final List<List<List<DailySchedule>>> dailySchedule = List.generate(countOfDays, (index) => [[], [], [], [], []]);
|
||||
|
||||
@@ -66,7 +67,11 @@ class CreateDietCubit extends Cubit<CreateDietState> {
|
||||
imageUrl: appConfig.buildType == AppBuildType.tests ? null : imageUrl,
|
||||
),
|
||||
);
|
||||
emit(state.copyWith(isLoading: false, isDietBeingEdited: false, dietState: diet.state, durationIndex: durationValues.indexOf(diet.duration)));
|
||||
emit(state.copyWith(isLoading: false, isDietBeingEdited: false, dietState: diet.state, durationIndex: durationValues.indexOf(diet.duration)));
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
emit(state.copyWith(isLoading: false, isDietBeingEdited: false));
|
||||
}
|
||||
}
|
||||
|
||||
void setDetails(String text) {
|
||||
@@ -112,7 +117,12 @@ class CreateDietCubit extends Cubit<CreateDietState> {
|
||||
}
|
||||
|
||||
Future<List<GlossaryModel>> getGlossaryListByQuery(String query) async {
|
||||
return await glossaryRepository.getGlossaryListByQuery(query);
|
||||
try {
|
||||
return await glossaryRepository.getGlossaryListByQuery(query);
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
return [];
|
||||
}
|
||||
}
|
||||
|
||||
void setImage(XFile? image, {String? imageUrl}) {
|
||||
@@ -204,7 +214,8 @@ class CreateDietCubit extends Cubit<CreateDietState> {
|
||||
|
||||
Future<Diet?> getDietForPreview() async {
|
||||
if (!_isFormValidForDraft()) return null;
|
||||
final authorProfile = await profileRepository.getMyProfile();
|
||||
try {
|
||||
final authorProfile = await profileRepository.getMyProfile();
|
||||
final imageBytes = (await state.dietData.image?.readAsBytes()) ?? <int>[];
|
||||
String image = '';
|
||||
if (imageBytes.isNotEmpty && imageBytes.length <= _maxImageBytesForBase64) {
|
||||
@@ -297,19 +308,26 @@ class CreateDietCubit extends Cubit<CreateDietState> {
|
||||
isFavorite: false,
|
||||
dailyNutrition: dailyNutrition,
|
||||
);
|
||||
return diet;
|
||||
return diet;
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
Future<File> downloadImageAsFile(String imageUrl) async {
|
||||
final response = await http.get(Uri.parse(imageUrl));
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
Future<File?> downloadImageAsFile(String imageUrl) async {
|
||||
try {
|
||||
final response = await http.get(Uri.parse(imageUrl));
|
||||
if (response.statusCode != 200) {
|
||||
throw Exception('Не удалось загрузить изображение');
|
||||
}
|
||||
final tempDir = await getTemporaryDirectory();
|
||||
final filePath = '${tempDir.path}/${imageUrl.split('/').last}';
|
||||
final file = File(filePath);
|
||||
return await file.writeAsBytes(response.bodyBytes);
|
||||
} else {
|
||||
throw Exception('Не удалось загрузить изображение');
|
||||
return file.writeAsBytes(response.bodyBytes);
|
||||
} catch (e, st) {
|
||||
await reportFrom(e, st, this);
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -353,7 +371,7 @@ class CreateDietCubit extends Cubit<CreateDietState> {
|
||||
emit(state.copyWith(published: dietState != DietState.draft, drafted: dietState == DietState.draft));
|
||||
return null;
|
||||
} catch (e, st) {
|
||||
await Sentry.captureException(e, stackTrace: st);
|
||||
await reportFrom(e, st, this);
|
||||
log(e.toString(), stackTrace: st);
|
||||
emit(state.copyWith(isDietPublishing: false));
|
||||
}
|
||||
@@ -391,7 +409,7 @@ class CreateDietCubit extends Cubit<CreateDietState> {
|
||||
emit(state.copyWith(isDietBeingEdited: false));
|
||||
return null;
|
||||
} catch (e, st) {
|
||||
await Sentry.captureException(e, stackTrace: st);
|
||||
await reportFrom(e, st, this);
|
||||
log(e.toString(), stackTrace: st);
|
||||
emit(state.copyWith(isDietBeingEdited: false));
|
||||
return 'error';
|
||||
|
||||
Reference in New Issue
Block a user