Skip to content

Commit

Permalink
delete print
Browse files Browse the repository at this point in the history
  • Loading branch information
duong2417 committed Nov 14, 2024
1 parent b36a10f commit b990979
Show file tree
Hide file tree
Showing 9 changed files with 12 additions and 37 deletions.
18 changes: 6 additions & 12 deletions lib/_shared/button/button_with_popup.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,43 +2,37 @@ import 'package:flutter/material.dart';

class ButtonWithPopup<T> extends StatefulWidget {
const ButtonWithPopup(
{
// required this.onChanged,
required this.items,
this.onTap,
required this.child});
// final Function(T) onChanged;
{super.key, required this.items, this.onTap, required this.child});
final List<DropdownMenuItem<T>> items;
final Widget child;
final Function()? onTap;

@override
_ButtonWithPopupState<T> createState() => _ButtonWithPopupState<T>();
State<ButtonWithPopup<T>> createState() => _ButtonWithPopupState<T>();
}

class _ButtonWithPopupState<T> extends State<ButtonWithPopup<T>> {
String? selectedItem;

final LayerLink _layerLink = LayerLink();

void _onDropdownTap() async {
print('onDropdownTap');
// Khi đã có dữ liệu, hiển thị dropdown items
if (widget.items.isNotEmpty) {
print('items không rỗng');
_showOverlay(); //ko do day
} else {
print('items rỗng');
// MsgDialog.showError(msg: 'Không tải được dữ liệu!');
}
}

final GlobalKey _key = GlobalKey();

OverlayEntry? _overlayEntry;

void _showOverlay() {
print('show overlay');
//null check
final renderBox = _key.currentContext!.findRenderObject() as RenderBox;
final size = renderBox.size;
print('size (dropdownNoFetchItems): $size');
final position = renderBox.localToGlobal(Offset.zero);

// Tính chiều cao của popup dựa trên số lượng items
Expand Down
1 change: 0 additions & 1 deletion lib/_shared/widgets/chat_bubble_widget.dart
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,6 @@ class ChatBubble extends StatelessWidget {
padding: const EdgeInsets.all(8.0),
child: BlocBuilder<TransBloc, TransState>(builder: (context, state) {
if (!isMine && state is ChangeLangState) {
print('state: ${state.selectedLanguages}');
context.read<TransBloc>().getTranslations(
message: message,
selectedLanguages: state.selectedLanguages,
Expand Down
1 change: 0 additions & 1 deletion lib/features/app_settings/widgets/switch_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,6 @@ class _MySwitchButtonState extends State<MySwitchButton> {
onChanged: (value) {
setState(() {
_toggle = value;
print(_toggle);
});
widget.onChange?.call(value);
},
Expand Down
2 changes: 0 additions & 2 deletions lib/features/chat/ui/public_chat_screen.dart
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,6 @@ class PublicChatScreen extends StatelessWidget {
shrinkWrap: true,
itemBuilder: (BuildContext context,
QueryDocumentSnapshot<Message> doc) {
print(
'build FirestoreListView:${doc.data().toString()}');
if (!doc.exists) {
return const SizedBox.shrink();
}
Expand Down
12 changes: 3 additions & 9 deletions lib/features/translate_settings/trans_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@ class TransBloc extends Bloc<TransEvent, TransState> {
.get();
}
Map<String, dynamic> translations = data.data() ?? {};
print('translations: $translations');
List<String> listLangSendToGemini = [];
for (String lang in selectedLanguages) {
bool hasTranslated = false;
Expand Down Expand Up @@ -133,14 +132,12 @@ class TransBloc extends Bloc<TransEvent, TransState> {
You must return the translations in JSON format with language codes as keys, e.g: {"en": "English translation", "fr": "French translation"}''';
final chatSession = model.startChat(generationConfig: generationConfig);
final result = await chatSession.sendMessage(Content.text(prompt));
final jsonTranslated = result.text;
print(
'translated json: $jsonTranslated'); // {"translations": {"en": "Hello, this is a test. I am Dương"}}
final jsonTranslated = result
.text; // {"translations": {"en": "Hello, this is a test. I am Dương"}}
Map<String, String>? translated;
if (jsonTranslated != null) {
translated = jsonDecode(jsonTranslated)['translations'];
print(
'final result: $translated'); //{en: Hello, this is a test. I am Dương}
//{en: Hello, this is a test. I am Dương}
} else {
MessageDialog.showError('Gemini trả về phản hồi null');
}
Expand All @@ -149,7 +146,6 @@ class TransBloc extends Bloc<TransEvent, TransState> {

FutureOr<void> _onLoadHistoryLanguages(
LoadHistoryLanguagesEvent event, Emitter<TransState> emit) {
print('onLoadHistoryLanguages');
emitSafely(TransInit());
final listHistoryLanguages = _localSharedData.getListHistoryLanguages();
emitSafely(
Expand All @@ -160,14 +156,12 @@ class TransBloc extends Bloc<TransEvent, TransState> {
extension on List<String> {
//tính luôn cả trường hợp giống nhau nhưng ko đúng thứ tự
bool equal(List<String> selectedLanguages) {
// if (this == null) return false;
if (isEmpty || selectedLanguages.isEmpty) return false;
for (String e in this) {
if (!selectedLanguages.contains(e)) {
return false;
}
}
print('equal: $selectedLanguages');
return true;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ class TranslateSettingsButton extends StatelessWidget {
}

void showSelectLang() {
List<String> _getHistoryLanguages() {
List<String> getHistoryLanguages() {
return LocalSharedData().getListHistoryLanguages();
}

Expand All @@ -38,16 +38,12 @@ void showSelectLang() {
.map((e) => e.trim().toLowerCase())
.toList();
languages.removeWhere((e) => e.isEmpty);
print('languages: $languages');
// if (languages.length > maxLanguages) {
// languages.sublist(0, maxLanguages);
// }
context.read<TransBloc>().add(SelectLanguageEvent(
languages: languages,
));
LocalSharedData().setChatLanguagesAndHistoryLanguages(languages);
},
fetchListHistoryLanguages: () async => _getHistoryLanguages(),
fetchListHistoryLanguages: () async => getHistoryLanguages(),
);
},
),
Expand Down
1 change: 0 additions & 1 deletion lib/utils/local_shared_data.dart
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,6 @@ class LocalSharedData {
List<String> list =
sharedPreferences.getStringList(keyListHistoryLanguages) ??
[defaultLanguageCode, 'en'];
print('getListHistoryLanguages: $list');
return list;
}

Expand Down
3 changes: 0 additions & 3 deletions lib/utils/my_translator.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ Future<String> translate(String text,
from: from))
.text;
} catch (e) {
print('translate error: $e');
// MessageDialog.showError("Không tìm thấy ngôn ngữ '$to'\n${e}",
// titleText: 'Dịch thất bại (dịch từ ngôn ngữ "$from")');
return "Không tìm thấy ngôn ngữ '$to' (dịch từ ngôn ngữ '$from')";
}
}
3 changes: 1 addition & 2 deletions lib/utils/send_to_gemini.dart
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ Future<Map<String, dynamic>> sendToGenmini({
final chatSession = model.startChat(generationConfig: generationConfig);
final result = await chatSession.sendMessage(Content.text(prompt));
final jsonTranslated = result.text;
print(
'translated json: $jsonTranslated'); // {"translations": {"en": "Hello, this is a test. I am Dương"}}
// {"translations": {"en": "Hello, this is a test. I am Dương"}}
Map<String, String>? translated;
if (jsonTranslated != null) {
translated = jsonDecode(jsonTranslated)['translations'];
Expand Down

0 comments on commit b990979

Please sign in to comment.