translator removed

This commit is contained in:
2026-03-25 18:03:50 +05:30
parent c4e28decb9
commit b78c83cc4a
3 changed files with 5 additions and 93 deletions

View File

@@ -1,5 +1,4 @@
import 'package:flutter_bloc/flutter_bloc.dart';
import 'package:google_mlkit_translation/google_mlkit_translation.dart';
import '../../../localPreference/local_preference.dart';
import '../../repository/faq_n_privacy_n_terms_repository.dart';
@@ -10,12 +9,10 @@ class FAQnPrivacynTermsBloc
extends Bloc<FAQnPrivacynTermsEvent, FAQnPrivacynTermsState> {
final FAQnPrivacynTermsRepository repository;
OnDeviceTranslator? _translator;
FAQnPrivacynTermsBloc(this.repository) : super(FAQnPrivacynTermsInitial()) {
FAQnPrivacynTermsBloc(this.repository)
: super(FAQnPrivacynTermsInitial()) {
on<FetchFAQnPrivacynTermsEvent>(_onFetchFAQnPrivacynTerms);
on<ToggleFAQItemEvent>(_onToggleFAQItem);
on<TranslatePrivacyContentEvent>(_onTranslatePrivacyContent);
}
// ---------------------------------------------------------------------------
@@ -50,87 +47,18 @@ class FAQnPrivacynTermsBloc
current.expandedCategoryIndex == event.categoryIndex;
final isSameItem = current.expandedItemIndex == event.tappedIndex;
// Tapping the already-open tile → close it; otherwise open the new one
// If same tile tapped → close it
if (isSameCategory && isSameItem) {
emit(current.copyWith(
expandedCategoryIndex: -1,
expandedItemIndex: -1,
));
} else {
// Open new tile
emit(current.copyWith(
expandedCategoryIndex: event.categoryIndex,
expandedItemIndex: event.tappedIndex,
));
}
}
// ---------------------------------------------------------------------------
// Translate privacy-policy content (on-device, ML Kit)
// ---------------------------------------------------------------------------
Future<void> _onTranslatePrivacyContent(
TranslatePrivacyContentEvent event,
Emitter<FAQnPrivacynTermsState> emit,
) async {
final current = state;
if (current is! FAQnPrivacynTermsLoaded) return;
final rawContent = event.rawContent;
final languageCode = await LocalPreference.getLanguage(); // e.g. 'hi', 'fr'
// No translation needed for English — just store the raw content
if (languageCode == 'en' || languageCode == null || languageCode.isEmpty) {
emit(current.copyWith(translatedContent: rawContent, isTranslating: false));
return;
}
final targetLanguage = TranslateLanguage.values.firstWhere(
(l) => l.bcpCode == languageCode,
orElse: () => TranslateLanguage.english,
);
// Signal that translation is in progress
emit(current.copyWith(isTranslating: true));
try {
// Close previous translator if language changed
await _translator?.close();
_translator = OnDeviceTranslator(
sourceLanguage: TranslateLanguage.english,
targetLanguage: targetLanguage,
);
// Download the model if not already on-device
final modelManager = OnDeviceTranslatorModelManager();
final isDownloaded = await modelManager.isModelDownloaded(languageCode);
if (!isDownloaded) {
await modelManager.downloadModel(languageCode);
}
final translated = await _translator!.translateText(rawContent);
// Emit only if bloc is still active (emitter guards this automatically)
emit(current.copyWith(
translatedContent: translated,
isTranslating: false,
));
} catch (_) {
// Fallback to the original content on any error
emit(current.copyWith(
translatedContent: rawContent,
isTranslating: false,
));
}
}
// ---------------------------------------------------------------------------
// Cleanup
// ---------------------------------------------------------------------------
@override
Future<void> close() async {
await _translator?.close();
return super.close();
}
}

View File

@@ -605,22 +605,6 @@ packages:
url: "https://pub.dev"
source: hosted
version: "0.5.14+2"
google_mlkit_commons:
dependency: transitive
description:
name: google_mlkit_commons
sha256: "3e69fea4211727732cc385104e675ad1e40b29f12edd492ee52fa108423a6124"
url: "https://pub.dev"
source: hosted
version: "0.11.1"
google_mlkit_translation:
dependency: "direct main"
description:
name: google_mlkit_translation
sha256: "5cb1c156d926cb5f4795674835d9df480366e002a3a7e17729d2ee472aed11ae"
url: "https://pub.dev"
source: hosted
version: "0.13.1"
gsettings:
dependency: transitive
description:

View File

@@ -64,7 +64,7 @@ dependencies:
flutter_slidable: ^4.0.3
path_provider: ^2.1.5
share_plus: ^12.0.1
google_mlkit_translation: ^0.13.1
# google_mlkit_translation: ^0.13.1
url_launcher: ^6.3.2
open_filex: ^4.7.0
country_code_picker: ^3.4.1