Commit a6797435 authored by DatHV's avatar DatHV
Browse files

refactor print, log, request

parent f0334970
import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
import '../../resources/base_color.dart';
class Campaign7DayGuideDialog extends StatelessWidget {
......
import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
import '../../resources/base_color.dart';
import 'models/campaign_7day_mission_model.dart';
......
import 'package:flutter/material.dart';
import 'package:flutter_widget_from_html/flutter_widget_from_html.dart';
import 'package:flutter_widget_from_html_core/flutter_widget_from_html_core.dart';
import 'package:get/get.dart';
import '../../../resources/base_color.dart';
import '../models/campaign_7day_reward_model.dart';
......
import 'package:flutter/foundation.dart';
import 'package:json_annotation/json_annotation.dart';
import 'campaign_7day_config_model.dart';
import 'campaign_7day_mission_model.dart';
......@@ -29,14 +30,14 @@ class Campaign7DayInfoModel {
});
double? get countDownTime {
print("End time: $endTime");
debugPrint("End time: $endTime");
if (endTime == null) return null;
try {
final date = intl.DateFormat("yyyy-MM-dd HH:mm:ss").parseUtc(endTime!);
print("Parsed date: $date");
debugPrint("Parsed date: $date");
final now = DateTime.now().toUtc();
final diff = date.difference(now).inSeconds;
print("Difference in seconds: $diff");
debugPrint("Difference in seconds: $diff");
return (diff > 0 ? diff : 0).toDouble();
} catch (_) {
return null;
......
import 'package:flutter/foundation.dart';
import 'package:flutter_contacts/flutter_contacts.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
......@@ -78,7 +79,7 @@ class _ContactsListScreenState extends State<ContactsListScreen> {
final contact = displayContacts[index];
return GestureDetector(
onTap: () {
print('contact selected ${contact.phones.firstOrNull}');
debugPrint('contact selected ${contact.phones.firstOrNull}');
},
child: Column(
children: [
......
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:mypoint_flutter_app/networking/restful_api_client_all_request.dart';
......@@ -29,7 +30,7 @@ class SignUpCreatePasswordRepository extends RestfulApiViewModel implements ICre
return client.signup(phoneNumber, password).then((value) {
hideLoading();
if (value.status == "success" || value.code == 200) {
print("signup success");
debugPrint("signup success");
_autoLogin(password);
}
return value;
......
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:mypoint_flutter_app/extensions/num_extension.dart';
......@@ -94,7 +95,7 @@ class _DataNetworkServiceScreenState extends BaseState<DataNetworkServiceScreen>
}
void _redeemProductMobileCard() {
print("redeem ${UserPointManager().point} >= ${_viewModel.payPoint}");
debugPrint("redeem ${UserPointManager().point} >= ${_viewModel.payPoint}");
final isValidInput =
(_viewModel.phoneNumber.value.trim().length >= 10) && (_viewModel.selectedProduct.value != null);
if (!isValidInput) {
......
import 'package:get/get.dart';
import 'package:get/get_rx/src/rx_types/rx_types.dart';
import 'package:mypoint_flutter_app/networking/restful_api_client_all_request.dart';
import 'package:mypoint_flutter_app/networking/api/product_api.dart' deferred as product_api;
import 'package:mypoint_flutter_app/preference/data_preference.dart';
import 'package:mypoint_flutter_app/screen/data_network_service/product_network_data_model.dart';
import 'package:mypoint_flutter_app/widgets/custom_toast_message.dart';
......@@ -23,6 +23,19 @@ class DataNetworkServiceViewModel extends RestfulApiViewModel {
final RxString phoneNumber = ''.obs;
void Function(String message)? onShowAlertError;
void Function(String message)? onShowAlertRedeemSuccess;
bool _productApiLoaded = false;
Future<void> _ensureProductApiLoaded() async {
if (_productApiLoaded) return;
await product_api.loadLibrary();
_productApiLoaded = true;
}
Future<BaseResponseModel<T>> _callProductApi<T>(Future<BaseResponseModel<T>> Function(dynamic api) fn) async {
await _ensureProductApiLoaded();
final api = product_api.ProductApi(client);
return fn(api);
}
int get payPoint {
return (int.tryParse(selectedProduct.value?.prices?.firstOrNull?.payPoint ?? "0") ?? 0);
......@@ -55,7 +68,7 @@ class DataNetworkServiceViewModel extends RestfulApiViewModel {
Future<void> _getNetworkBrands() async {
await callApi<List<ProductBrandModel>>(
request: () => client.productTopUpBrands(),
request: () => _callProductApi((api) => api.productTopUpBrands()),
onSuccess: (data, _) {
topUpBrands.assignAll(data);
checkMobileNetwork();
......@@ -69,7 +82,7 @@ class DataNetworkServiceViewModel extends RestfulApiViewModel {
Future<void> checkMobileNetwork() async {
await callApi<BrandNameCheckResponse>(
request: () => client.checkMobileNetwork(phoneNumber.value),
request: () => _callProductApi((api) => api.checkMobileNetwork(phoneNumber.value)),
onSuccess: (data, _) {
final brandCode = data.brand ?? '';
var brand = topUpBrands.isNotEmpty
......@@ -118,7 +131,7 @@ class DataNetworkServiceViewModel extends RestfulApiViewModel {
return;
}
await callApi<List<TopUpNetworkDataModel>>(
request: () => client.getNetworkProducts((id ?? 0).toString()),
request: () => _callProductApi((api) => api.getNetworkProducts((id ?? 0).toString())),
onSuccess: (data, _) {
final filtered = (data)
.where((e) => e.products?.isNotEmpty == true)
......@@ -138,7 +151,7 @@ class DataNetworkServiceViewModel extends RestfulApiViewModel {
return;
}
await callApi<EmptyCodable>(
request: () => client.redeemProductTopUps(id, phoneNumber.value),
request: () => _callProductApi((api) => api.redeemProductTopUps(id, phoneNumber.value)),
onSuccess: (data, _) {
onShowAlertRedeemSuccess?.call("Chúc mừng bạn đã đổi Ưu đãi data thành công");
},
......@@ -147,4 +160,4 @@ class DataNetworkServiceViewModel extends RestfulApiViewModel {
},
);
}
}
\ No newline at end of file
}
import 'package:get/get_rx/src/rx_types/rx_types.dart';
import 'package:mypoint_flutter_app/extensions/collection_extension.dart';
import 'package:mypoint_flutter_app/networking/api/product_api.dart' deferred as product_api;
import 'package:mypoint_flutter_app/networking/restful_api_client_all_request.dart';
import '../../networking/restful_api_viewmodel.dart';
import '../transaction/model/payment_method_model.dart';
import 'models/customer_contract_object_model.dart';
import 'models/electric_payment_response_model.dart';
import '../../base/base_response_model.dart';
class ElectricPaymentBillViewModel extends RestfulApiViewModel {
final RxList<PaymentMethodModel> paymentMethods = <PaymentMethodModel>[].obs;
final RxInt selectedPaymentMethodIndex = 0.obs;
void Function(ElectricPaymentResponseModel data)? customerEvnPaymentGatewayResponse;
void Function(String message)? onShowAlertError;
bool _productApiLoaded = false;
Future<void> _ensureProductApiLoaded() async {
if (_productApiLoaded) return;
await product_api.loadLibrary();
_productApiLoaded = true;
}
Future<BaseResponseModel<T>> _callProductApi<T>(Future<BaseResponseModel<T>> Function(dynamic api) fn) async {
await _ensureProductApiLoaded();
final api = product_api.ProductApi(client);
return fn(api);
}
Future<void> getPaymentMethods() async {
await callApi<List<PaymentMethodModel>>(
request: () => client.getPreviewPaymentMethods(),
request: () => _callProductApi((api) => api.getPreviewPaymentMethods()),
onSuccess: (data, _) {
selectedPaymentMethodIndex.value = 0;
paymentMethods.assignAll(data);
......
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:mypoint_flutter_app/extensions/num_extension.dart';
......@@ -189,7 +190,7 @@ class _ElectricPaymentHistoryScreenState extends State<ElectricPaymentHistoryScr
GestureDetector(
onTap: () {
Get.to(ElectricPaymentBillScreen(bill: bill,));
print('Thanh toán hoá đơn: ${bill.maKH ?? ''}');
debugPrint('Thanh toán hoá đơn: ${bill.maKH ?? ''}');
},
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 8),
......
import 'package:get/get.dart';
import 'package:mypoint_flutter_app/networking/restful_api_client_all_request.dart';
import 'package:mypoint_flutter_app/networking/api/website_api.dart' deferred as website_api;
import '../../networking/restful_api_viewmodel.dart';
import 'faqs_model.dart';
class FAQViewModel extends RestfulApiViewModel {
final RxList<PageItemModel> faqItems = <PageItemModel>[].obs;
bool _websiteApiLoaded = false;
Future<void> _ensureWebsiteApiLoaded() async {
if (_websiteApiLoaded) return;
await website_api.loadLibrary();
_websiteApiLoaded = true;
}
@override
void onInit() {
super.onInit();
......@@ -14,7 +22,11 @@ class FAQViewModel extends RestfulApiViewModel {
Future<void> fetchFAQItems() async {
await callApi<FAQItemModelResponse>(
request: () => client.websiteFolderGetPageList({"folder_uri": "FAQ"}),
request: () async {
await _ensureWebsiteApiLoaded();
final api = website_api.WebsiteApi(client);
return api.websiteFolderGetPageList({"folder_uri": "FAQ"});
},
onSuccess: (data, _) {
faqItems.assignAll(data.items ?? []);
},
......
import 'package:get/get.dart';
import 'package:mypoint_flutter_app/networking/restful_api_client_all_request.dart';
import 'package:mypoint_flutter_app/networking/api/game_api.dart' deferred as game_api;
import '../../../configs/constants.dart';
import '../../../networking/restful_api_viewmodel.dart';
import '../../../widgets/alert/popup_data_model.dart';
......@@ -11,9 +11,21 @@ class GameCardViewModel extends RestfulApiViewModel {
void Function(PopupDataModel popup)? submitGameCardSuccess;
void Function()? getGameDetailSuccess;
bool _gameApiLoaded = false;
Future<void> _ensureGameApiLoaded() async {
if (_gameApiLoaded) return;
await game_api.loadLibrary();
_gameApiLoaded = true;
}
Future<void> submitGameCard(String gameId, int itemId) async {
await callApi<GameBundleItemModel>(
request: () => client.submitGameCard(gameId, itemId.toString()),
request: () async {
await _ensureGameApiLoaded();
final api = game_api.GameApi(client);
return api.submitGameCard(gameId, itemId.toString());
},
onSuccess: (data, _) {
final popupData = data?.popup;
if (popupData != null) {
......@@ -22,7 +34,7 @@ class GameCardViewModel extends RestfulApiViewModel {
onShowAlertError?.call(Constants.commonError, false);
}
},
onFailure: (msg, _, __) async {
onFailure: (msg, _, _) async {
onShowAlertError?.call(msg, false);
},
);
......@@ -30,7 +42,11 @@ class GameCardViewModel extends RestfulApiViewModel {
Future<void> getGameDetail({String? id}) async {
await callApi<GameBundleItemModel>(
request: () => client.getGameDetail(id ?? data.value?.id ?? ''),
request: () async {
await _ensureGameApiLoaded();
final api = game_api.GameApi(client);
return api.getGameDetail(id ?? data.value?.id ?? '');
},
onSuccess: (data, _) {
this.data.value = data;
getGameDetailSuccess?.call();
......@@ -40,4 +56,4 @@ class GameCardViewModel extends RestfulApiViewModel {
},
);
}
}
\ No newline at end of file
}
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
import 'package:get/get.dart';
import 'package:mypoint_flutter_app/widgets/image_loader.dart';
import '../../base/base_screen.dart';
......@@ -58,7 +57,7 @@ class _GameTabScreenState extends BaseState<GameTabScreen> with BasicState, Popu
title: "Games",
leftButtons: _canBackButton ? [CustomBackButton()] : [],
rightButtons: [
if (Platform.isIOS)
if (!kIsWeb && defaultTargetPlatform == TargetPlatform.iOS)
CompositedTransformTarget(
link: _layerLink,
child: IconButton(
......
import 'package:get/get_rx/src/rx_types/rx_types.dart';
import 'package:mypoint_flutter_app/networking/restful_api_client_all_request.dart';
import 'package:mypoint_flutter_app/networking/api/game_api.dart' deferred as game_api;
import 'package:mypoint_flutter_app/screen/game/models/game_bundle_item_model.dart';
import '../../networking/restful_api_viewmodel.dart';
import 'models/game_bundle_response.dart';
......@@ -11,9 +10,21 @@ class GameTabViewModel extends RestfulApiViewModel {
void Function(String message)? onShowAlertError;
void Function(GameBundleItemModel data)? gotoGameDetail;
bool _gameApiLoaded = false;
Future<void> _ensureGameApiLoaded() async {
if (_gameApiLoaded) return;
await game_api.loadLibrary();
_gameApiLoaded = true;
}
Future<void> getGames() {
return callApi<GameBundleResponse>(
request: () => client.getGames(),
request: () async {
await _ensureGameApiLoaded();
final api = game_api.GameApi(client);
return api.getGames();
},
onSuccess: (data, _) {
games.assignAll(data.games ?? []);
turnsNumberText.value = data.turnsNumberText ?? "";
......@@ -26,7 +37,11 @@ class GameTabViewModel extends RestfulApiViewModel {
void getGameDetail(String gameId) {
callApi<GameBundleItemModel>(
request: () => client.getGameDetail(gameId),
request: () async {
await _ensureGameApiLoaded();
final api = game_api.GameApi(client);
return api.getGameDetail(gameId);
},
onSuccess: (data, _) {
gotoGameDetail?.call(data);
},
......
......@@ -124,3 +124,6 @@ class HealthBookItem extends StatelessWidget {
import 'dart:async';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';
import 'package:mypoint_flutter_app/widgets/image_loader.dart';
......@@ -65,7 +66,7 @@ class _HoverViewState extends State<HoverView> {
if (!mounted) return;
setState(() {
_remainingSeconds.value--;
print("Remaining seconds: ${_remainingSeconds.value}");
debugPrint("Remaining seconds: ${_remainingSeconds.value}");
if (_remainingSeconds.value <= 0) _timer?.cancel();
});
});
......
import 'package:get/get.dart';
import 'package:mypoint_flutter_app/networking/api/notification_api.dart'
deferred as notification_api;
import 'package:mypoint_flutter_app/networking/restful_api_client_all_request.dart';
import 'package:mypoint_flutter_app/preference/data_preference.dart';
import '../../networking/restful_api_viewmodel.dart';
......@@ -12,10 +14,12 @@ class HeaderHomeRepository extends RestfulApiViewModel {
factory HeaderHomeRepository() => _instance;
final Rx<HeaderHomeModel?> _headerHome = Rx<HeaderHomeModel?>(null);
final Rxn<NotificationUnreadData> _notificationUnread = Rxn<NotificationUnreadData>();
final Rxn<NotificationUnreadData> _notificationUnread =
Rxn<NotificationUnreadData>();
int get totalPoint => header.totalPointActive ?? 0;
HeaderHomeModel get header => _headerHome.value ??
HeaderHomeModel get header =>
_headerHome.value ??
HeaderHomeModel(
greeting: 'Xin chào!',
totalVoucher: 0,
......@@ -47,13 +51,25 @@ class HeaderHomeRepository extends RestfulApiViewModel {
Future<void> _fetchNotificationUnread() async {
if (!DataPreference.instance.logged) return;
await callApi<NotificationUnreadData>(
request: () => client.getNotificationUnread(),
request: () async {
await _ensureNotificationApiLoaded();
final api = notification_api.NotificationApi(client);
return api.getNotificationUnread();
},
onSuccess: (data, _) {
_notificationUnread.value = data;
},
withLoading: false,
);
}
bool _notificationApiLoaded = false;
Future<void> _ensureNotificationApiLoaded() async {
if (_notificationApiLoaded) return;
await notification_api.loadLibrary();
_notificationApiLoaded = true;
}
}
class HeaderThemeController extends GetxController {
......@@ -65,7 +81,8 @@ class HeaderHomeViewModel extends GetxController {
final HeaderHomeRepository _repository = HeaderHomeRepository();
HeaderHomeModel get headerData => _repository.header;
Rxn<NotificationUnreadData> get notificationUnreadData => _repository.notificationStream;
Rxn<NotificationUnreadData> get notificationUnreadData =>
_repository.notificationStream;
@override
void onInit() {
......
import 'package:flutter/foundation.dart';
import 'package:get/get.dart';
import 'package:json_annotation/json_annotation.dart';
import 'package:mypoint_flutter_app/directional/directional_screen.dart';
......@@ -40,7 +41,7 @@ class AchievementModel {
(image) => image.imageType == 'COVER',
);
final url = coverImage?.imageUrl ?? images?.firstOrNull?.imageUrl;
print("urlBackground: $url");
debugPrint("urlBackground: $url");
return url;
}
......
......@@ -37,9 +37,7 @@ class MyProductModel {
rawStatus: json['status'] as int?,
);
} catch (e) {
if (kDebugMode) {
print('Failed to parse MyProductModel: $e');
}
debugPrint('Failed to parse MyProductModel: $e');
rethrow;
}
}
......@@ -65,9 +63,7 @@ class MyProductModel {
try {
return DateTime.tryParse(expireTime!);
} catch (e) {
if (kDebugMode) {
print('Failed to parse expireTime: $expireTime - $e');
}
debugPrint('Failed to parse expireTime: $expireTime - $e');
return null;
}
}
......@@ -83,9 +79,7 @@ class MyProductModel {
final formatted = _formatDate(expireDate!);
return 'HSD: $formatted';
} catch (e) {
if (kDebugMode) {
print('Failed to format deadline: $e');
}
debugPrint('Failed to format deadline: $e');
return 'HSD: Không xác định';
}
}
......
import 'package:get/get.dart';
import 'package:mypoint_flutter_app/networking/restful_api_client_all_request.dart';
import 'package:mypoint_flutter_app/networking/api/location_api.dart' deferred as location_api;
import '../../base/base_response_model.dart';
import '../../networking/restful_api_viewmodel.dart';
import 'location_address_screen.dart';
import 'models/district_address_model.dart';
......@@ -18,6 +19,20 @@ class LocationAddressViewModel extends RestfulApiViewModel {
LocationAddressType type = LocationAddressType.province;
String provinceCode = '';
bool _locationApiLoaded = false;
Future<void> _ensureLocationApiLoaded() async {
if (_locationApiLoaded) return;
await location_api.loadLibrary();
_locationApiLoaded = true;
}
Future<BaseResponseModel<T>> _callLocationApi<T>(Future<BaseResponseModel<T>> Function(dynamic api) fn) async {
await _ensureLocationApiLoaded();
final api = location_api.LocationApi(client);
return fn(api);
}
LocationAddressViewModel({this.type = LocationAddressType.province, this.provinceCode = ''});
@override
......@@ -25,7 +40,7 @@ class LocationAddressViewModel extends RestfulApiViewModel {
super.onInit();
if (type == LocationAddressType.province) {
callApi<ProvinceAddressResponse>(
request: () => client.locationProvinceGetList(),
request: () => _callLocationApi((api) => api.locationProvinceGetList()),
onSuccess: (data, _) {
_loadFromProvince(data.items ?? []);
},
......@@ -33,7 +48,7 @@ class LocationAddressViewModel extends RestfulApiViewModel {
);
} else {
callApi<DistrictAddressResponse>(
request: () => client.locationDistrictGetList(provinceCode),
request: () => _callLocationApi((api) => api.locationDistrictGetList(provinceCode)),
onSuccess: (data, _) {
_loadFromDistrict(data.items ?? []);
},
......@@ -58,11 +73,12 @@ class LocationAddressViewModel extends RestfulApiViewModel {
return;
}
final lowerQuery = _removeDiacritics(query).toLowerCase();
final filteredItems = _allItems.where((item) {
final name = item.name ?? '';
final normalized = _removeDiacritics(name).toLowerCase();
return normalized.contains(lowerQuery);
}).toList();
final filteredItems =
_allItems.where((item) {
final name = item.name ?? '';
final normalized = _removeDiacritics(name).toLowerCase();
return normalized.contains(lowerQuery);
}).toList();
displayItems.assignAll(filteredItems);
}
......@@ -73,9 +89,11 @@ class LocationAddressViewModel extends RestfulApiViewModel {
}
String _removeDiacritics(String str) {
const withDiacritics = 'àáảãạâầấẩẫậăằắẳẵặèéẻẽẹêềếểễệìíỉĩịòóỏõọôồốổỗộơờớởỡợùúủũụưừứửữựỳýỷỹỵđ'
const withDiacritics =
'àáảãạâầấẩẫậăằắẳẵặèéẻẽẹêềếểễệìíỉĩịòóỏõọôồốổỗộơờớởỡợùúủũụưừứửữựỳýỷỹỵđ'
'ÀÁẢÃẠÂẦẤẨẪẬĂẰẮẲẴẶÈÉẺẼẸÊỀẾỂỄỆÌÍỈĨỊÒÓỎÕỌÔỒỐỔỖỘƠỜỚỞỠỢÙÚỦŨỤƯỪỨỬỮỰỲÝỶỸỴĐ';
const withoutDiacritics = 'aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiooooooooooooooooouuuuuuuuuuuyyyyyd'
const withoutDiacritics =
'aaaaaaaaaaaaaaaaaeeeeeeeeeeeiiiiiooooooooooooooooouuuuuuuuuuuyyyyyd'
'AAAAAAAAAAAAAAAAAEEEEEEEEEEEIIIIIOOOOOOOOOOOOOOOOOUUUUUUUUUUUYYYYYD';
for (int i = 0; i < withDiacritics.length; i++) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment