chore: fix for null check error in getFeedback (#2174)

This commit is contained in:
ggurdin 2025-03-19 10:45:48 -04:00 committed by GitHub
parent af295b2817
commit e3012f479f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 36 additions and 23 deletions

View file

@ -60,7 +60,11 @@ class FullTextTranslationRepo {
// check cache first
if (_cache.containsKey(cacheKey)) {
return _cache[cacheKey]!;
if (_cache[cacheKey] == null) {
_cache.remove(cacheKey);
} else {
return _cache[cacheKey]!;
}
}
final Requests req = Requests(

View file

@ -6,6 +6,7 @@ import 'package:http/http.dart';
import 'package:fluffychat/pangea/analytics_misc/text_loading_shimmer.dart';
import 'package:fluffychat/pangea/choreographer/repo/full_text_translation_repo.dart';
import 'package:fluffychat/pangea/common/utils/error_handler.dart';
import '../../../widgets/matrix.dart';
import '../../bot/utils/bot_style.dart';
import '../../common/controllers/pangea_controller.dart';
@ -50,29 +51,37 @@ class ITFeedbackCardController extends State<ITFeedbackCard> {
isLoadingFeedback = true;
});
FullTextTranslationRepo.translate(
accessToken: controller.userController.accessToken,
request: FullTextTranslationRequestModel(
text: widget.req.chosenContinuance,
tgtLang: controller.languageController.userL1?.langCode ??
widget.req.sourceTextLang,
userL1: controller.languageController.userL1?.langCode ??
widget.req.sourceTextLang,
userL2: controller.languageController.userL2?.langCode ??
widget.req.targetLang,
),
)
.then((translationResponse) {
res = ITFeedbackResponseModel(
text: translationResponse.bestTranslation,
);
})
.catchError((e) => error = e)
.whenComplete(() {
if (mounted) {
setState(() => isLoadingFeedback = false);
}
try {
final resp = await FullTextTranslationRepo.translate(
accessToken: controller.userController.accessToken,
request: FullTextTranslationRequestModel(
text: widget.req.chosenContinuance,
tgtLang: controller.languageController.userL1?.langCode ??
widget.req.sourceTextLang,
userL1: controller.languageController.userL1?.langCode ??
widget.req.sourceTextLang,
userL2: controller.languageController.userL2?.langCode ??
widget.req.targetLang,
),
);
res = ITFeedbackResponseModel(text: resp.bestTranslation);
} catch (e, s) {
error = e;
ErrorHandler.logError(
e: e,
s: s,
data: {
"req": widget.req.toJson(),
"choiceFeedback": widget.choiceFeedback,
},
);
} finally {
if (mounted) {
setState(() {
isLoadingFeedback = false;
});
}
}
}
@override