Skip to content

Commit

Permalink
Feat: Replace print by debugPrint for better performance
Browse files Browse the repository at this point in the history
  • Loading branch information
spicy-tomato committed Aug 5, 2021
1 parent 4ed0ee9 commit f42cfaa
Show file tree
Hide file tree
Showing 40 changed files with 134 additions and 103 deletions.
12 changes: 6 additions & 6 deletions lib/_crawler/bloc/crawler_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ class CrawlerBloc extends Bloc<CrawlerEvent, CrawlerState> {
),
);

print('crawler_bloc.dart --- Update password: $passwordStatus');
debugPrint('crawler_bloc.dart --- Update password: $passwordStatus');

if (passwordStatus.isOk) {
bool hasError = false;
Expand All @@ -94,7 +94,7 @@ class CrawlerBloc extends Bloc<CrawlerEvent, CrawlerState> {
all: true,
),
);
print('crawler_bloc.dart --- Crawl score: $scoreCrawlerStatus');
debugPrint('crawler_bloc.dart --- Crawl score: $scoreCrawlerStatus');

if (scoreCrawlerStatus.isOk) {
await userDataModel.scoreServiceController.refresh();
Expand All @@ -112,7 +112,7 @@ class CrawlerBloc extends Bloc<CrawlerEvent, CrawlerState> {
all: true,
),
);
print('crawler_bloc.dart --- Crawl exam Schedule: $examScheduleCrawlerStatus');
debugPrint('crawler_bloc.dart --- Crawl exam Schedule: $examScheduleCrawlerStatus');

if (examScheduleCrawlerStatus.isOk) {
await userDataModel.examScheduleServiceController.refresh();
Expand Down Expand Up @@ -158,9 +158,9 @@ class CrawlerBloc extends Bloc<CrawlerEvent, CrawlerState> {
),
);

print(state.formStatus);
debugPrint(state.formStatus.toString());

print('crawler_bloc.dart --- Crawl score: $scoreCrawlerStatus');
debugPrint('crawler_bloc.dart --- Crawl score: $scoreCrawlerStatus');

if (scoreCrawlerStatus.isOk) {
await userDataModel.scoreServiceController.refresh();
Expand All @@ -178,7 +178,7 @@ class CrawlerBloc extends Bloc<CrawlerEvent, CrawlerState> {
all: true,
),
);
print('crawler_bloc.dart --- Crawl exam Schedule: $examScheduleCrawlerStatus');
debugPrint('crawler_bloc.dart --- Crawl exam Schedule: $examScheduleCrawlerStatus');

if (examScheduleCrawlerStatus.isOk) {
await userDataModel.examScheduleServiceController.refresh();
Expand Down
11 changes: 6 additions & 5 deletions lib/_models/calendar_client_model.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:developer';

import 'package:flutter/widgets.dart';
import 'package:googleapis_auth/auth_io.dart';
import 'package:googleapis/calendar/v3.dart';
import 'package:url_launcher/url_launcher.dart';
Expand All @@ -13,7 +14,7 @@ class CalendarClientModel {
var _clientID = ClientId(clientId, "");
clientViaUserConsent(_clientID, _scopes, prompt).then((AuthClient client) {
var calendar = CalendarApi(client);
calendar.calendarList.list().then((value) => print("VAL________$value"));
calendar.calendarList.list().then((value) => debugPrint("VAL________$value"));

String calendarId = "primary";
Event event = Event();
Expand All @@ -32,7 +33,7 @@ class CalendarClientModel {

try {
calendar.events.insert(event, calendarId).then((value) {
print("ADDED_________________${value.status}");
debugPrint("ADDED_________________${value.status}");
if (value.status == "confirmed") {
log('Event added in google calendar');
} else {
Expand All @@ -46,9 +47,9 @@ class CalendarClientModel {
}

void prompt(String url) async {
print("Please go to the following URL and grant access:");
print(" => $url");
print("");
debugPrint("Please go to the following URL and grant access:");
debugPrint(" => $url");
debugPrint("");

if (await canLaunch(url)) {
await launch(url);
Expand Down
6 changes: 3 additions & 3 deletions lib/_preload/bloc/preload_bloc.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class PreloadBloc extends Bloc<PreloadEvent, PreloadState> {
final timeEnded = stopwatch.elapsed;
stopwatch.stop();

print(timeEnded);
debugPrint(timeEnded.toString());

final userDataModel = UserDataModel(
eventServiceController: serviceControllers.event,
Expand Down Expand Up @@ -127,7 +127,7 @@ class PreloadBloc extends Bloc<PreloadEvent, PreloadState> {
final timeEnded = stopwatch.elapsed;
stopwatch.stop();

print(timeEnded);
debugPrint(timeEnded.toString());

final userDataModel = UserDataModel(
eventServiceController: serviceControllers.event,
Expand Down Expand Up @@ -169,7 +169,7 @@ class PreloadBloc extends Bloc<PreloadEvent, PreloadState> {
).getServerDataVersion();

if (versionMap.isNotEmpty) {
print(versionMap);
debugPrint(versionMap.toString());
if (force) {
await serviceControllers.forceRefresh(versionMap);
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:async';
import 'package:app_qldt/_models/account_permission_enum.dart';
import 'package:app_qldt/_utils/database/provider.dart';
import 'package:app_qldt/_utils/secret/url/url.dart';
import 'package:flutter/widgets.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'services/services.dart';
Expand Down Expand Up @@ -35,7 +36,7 @@ class AuthenticationRepository {

final LoginResponse loginResponse = await _loginService!.login(loginUser);

print('Login status: ${loginResponse.status}, permission: ${apiUrl.accountPermission}');
debugPrint('Login status: ${loginResponse.status}, permission: ${apiUrl.accountPermission}');

if (loginResponse.status.isSuccessfully) {
await _saveUserInfo(loginResponse.data!, apiUrl.accountPermission);
Expand All @@ -54,7 +55,7 @@ class AuthenticationRepository {
}

Future<void> logOut() async {
print('${DateTime.now()}: Request to logout');
debugPrint('${DateTime.now()}: Request to logout');

await DatabaseProvider.deleteDb();
await _removeUserInfo();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'dart:convert';
import 'package:app_qldt/_utils/helper/const.dart';
import 'package:app_qldt/_utils/secret/url/url.dart';
import 'package:connectivity/connectivity.dart';
import 'package:flutter/widgets.dart';
import 'package:http/http.dart' as http;

import 'models/models.dart';
Expand Down Expand Up @@ -40,7 +41,7 @@ class LoginService {
data: status.isSuccessfully ? response.body : null,
);
} on Exception catch (e) {
print('Error: $e in Login service');
debugPrint('Error: $e in Login service');
return LoginResponse(status: LoginStatus.serverError);
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:firebase_messaging/firebase_messaging.dart';
import 'package:flutter/widgets.dart';
import 'package:flutter_local_notifications/flutter_local_notifications.dart';

class FirebaseRepository {
Expand All @@ -25,8 +26,7 @@ class FirebaseRepository {
importance: Importance.max,
);

final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin =
FlutterLocalNotificationsPlugin();
final FlutterLocalNotificationsPlugin flutterLocalNotificationsPlugin = FlutterLocalNotificationsPlugin();

const AndroidInitializationSettings initializationSettingsAndroid =
AndroidInitializationSettings('mipmap/ic_launcher');
Expand All @@ -45,8 +45,8 @@ class FirebaseRepository {
RemoteNotification? notification = message.notification;
AndroidNotification? android = message.notification?.android;

print(message.data);
print(message.notification);
debugPrint(message.data.toString());
debugPrint(message.notification.toString());

if (notification != null && android != null) {
flutterLocalNotificationsPlugin.show(
Expand All @@ -72,11 +72,11 @@ class FirebaseRepository {
}

Future<String?> getToken() async {
print('Getting token');
debugPrint('Getting token');
try {
return await FirebaseMessaging.instance.getToken();
} on Exception catch (e) {
print('Get token error: $e');
debugPrint('Get token error: $e');
}
}
}
5 changes: 3 additions & 2 deletions lib/_repositories/user_repository/src/user_repository.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';

import 'package:app_qldt/_models/account_permission_enum.dart';
import 'package:app_qldt/_models/user_data_model.dart';
import 'package:flutter/widgets.dart';
import 'package:shared_preferences/shared_preferences.dart';

import 'models/models.dart';
Expand All @@ -16,13 +17,13 @@ class UserRepository {

if (loginInfo.isEmpty) return null;

print(loginInfo);
debugPrint(loginInfo.toString());

try {
final permission = await _getPermission();
_user = User.fromJsonWithPermission(loginInfo, permission);
} on Exception catch (e){
print(e.toString());
debugPrint(e.toString());
}

return _user;
Expand Down
7 changes: 4 additions & 3 deletions lib/_services/api/api_event_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:app_qldt/_services/model/service_response.dart';
import 'package:app_qldt/_utils/helper/const.dart';
import 'package:app_qldt/_utils/secret/url/url.dart';
import 'package:connectivity/connectivity.dart';
import 'package:flutter/widgets.dart';
import 'package:http/http.dart' as http;

class ApiEventService extends ApiService {
Expand Down Expand Up @@ -46,11 +47,11 @@ class ApiEventService extends ApiService {
http.Response response = await http.get(Uri.parse(url)).timeout(Const.requestTimeout);
return ServiceResponse.withVersion(response);
} on TimeoutException catch (e) {
print('Timeout error: $e at Event service');
debugPrint('Timeout error: $e at Event service');
} on SocketException catch (e) {
print('Socket error: $e at Event service');
debugPrint('Socket error: $e at Event service');
} on Error catch (e) {
print('General Error: $e at Event service');
debugPrint('General Error: $e at Event service');
}

return ServiceResponse.error();
Expand Down
7 changes: 4 additions & 3 deletions lib/_services/api/api_exam_schedule_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:app_qldt/_services/model/service_response.dart';
import 'package:app_qldt/_utils/helper/const.dart';
import 'package:app_qldt/_utils/secret/url/url.dart';
import 'package:connectivity/connectivity.dart';
import 'package:flutter/widgets.dart';

import 'package:http/http.dart' as http;

Expand Down Expand Up @@ -50,11 +51,11 @@ class ApiExamScheduleService extends ApiService {
final response = await http.get(Uri.parse(url)).timeout(Const.requestTimeout);
return ServiceResponse(response);
} on TimeoutException catch (e) {
print('Timeout error: $e at ExamSchedule service');
debugPrint('Timeout error: $e at ExamSchedule service');
} on SocketException catch (e) {
print('Socket error: $e at ExamSchedule service');
debugPrint('Socket error: $e at ExamSchedule service');
} on Error catch (e) {
print('General Error: $e at ExamSchedule service');
debugPrint('General Error: $e at ExamSchedule service');
}

return ServiceResponse.error();
Expand Down
7 changes: 4 additions & 3 deletions lib/_services/api/api_notification_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:app_qldt/_services/model/service_response.dart';
import 'package:app_qldt/_utils/helper/const.dart';
import 'package:app_qldt/_utils/secret/url/url.dart';
import 'package:connectivity/connectivity.dart';
import 'package:flutter/widgets.dart';
import 'package:http/http.dart' as http;

class ApiNotificationService extends ApiService {
Expand Down Expand Up @@ -50,11 +51,11 @@ class ApiNotificationService extends ApiService {
final response = await http.get(Uri.parse(url)).timeout(Const.requestTimeout);
return ServiceResponse.withVersion(response);
} on TimeoutException catch (e) {
print('Timeout error: $e at API Notification service');
debugPrint('Timeout error: $e at API Notification service');
} on SocketException catch (e) {
print('Socket error: $e at API Notification service');
debugPrint('Socket error: $e at API Notification service');
} on Error catch (e) {
print('General Error: $e at API Notification service');
debugPrint('General Error: $e at API Notification service');
}

return ServiceResponse.error();
Expand Down
7 changes: 4 additions & 3 deletions lib/_services/api/api_score_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:app_qldt/_services/model/service_response.dart';
import 'package:app_qldt/_utils/helper/const.dart';
import 'package:app_qldt/_utils/secret/url/url.dart';
import 'package:connectivity/connectivity.dart';
import 'package:flutter/widgets.dart';
import 'package:http/http.dart' as http;

class ApiScoreService extends ApiService {
Expand Down Expand Up @@ -48,11 +49,11 @@ class ApiScoreService extends ApiService {
final response = await http.get(Uri.parse(url)).timeout(Const.requestTimeout);
return ServiceResponse(response);
} on TimeoutException catch (e) {
print('Timeout error: $e at Score service');
debugPrint('Timeout error: $e at Score service');
} on SocketException catch (e) {
print('Socket error: $e at Score service');
debugPrint('Socket error: $e at Score service');
} on Error catch (e) {
print('General Error: $e at Score service');
debugPrint('General Error: $e at Score service');
}

return ServiceResponse.error();
Expand Down
8 changes: 5 additions & 3 deletions lib/_services/api/crawler_service.dart
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import 'package:app_qldt/_models/crawler/score_crawler_model.dart';
import 'package:app_qldt/_models/crawler/update_password_crawler_model.dart';
import 'package:app_qldt/_utils/helper/const.dart';
import 'package:app_qldt/_utils/secret/url/url.dart';
import 'package:flutter/widgets.dart';
import 'package:http/http.dart' as http;

class CrawlerService {
Expand All @@ -22,10 +23,11 @@ class CrawlerService {
response = await http.post(Uri.parse(url), body: body).timeout(Const.crawlerTimeout);
return CrawlerStatusExtension.fromStatusCode(response.statusCode);
} on Exception catch (e) {
print('Error: $e in Crawler service - Update password');
debugPrint('Error: $e in Crawler service - Update password');
return CrawlerStatus.serverError;
}
}

Future<CrawlerStatus> crawlScore(ScoreCrawlerModel crawler) async {
String url = apiUrl.post.scoreCrawler;
String body = jsonEncode(crawler);
Expand All @@ -35,7 +37,7 @@ class CrawlerService {
response = await http.post(Uri.parse(url), body: body).timeout(Const.crawlerTimeout);
return CrawlerStatusExtension.fromStatusCode(response.statusCode);
} on Exception catch (e) {
print('Error: $e in Crawler service - Crawl score');
debugPrint('Error: $e in Crawler service - Crawl score');
return CrawlerStatus.serverError;
}
}
Expand All @@ -49,7 +51,7 @@ class CrawlerService {
response = await http.post(Uri.parse(url), body: body).timeout(Const.crawlerTimeout);
return CrawlerStatusExtension.fromStatusCode(response.statusCode);
} on Exception catch (e) {
print('Error: $e in Crawler service - Crawl exam schedule');
debugPrint('Error: $e in Crawler service - Crawl exam schedule');
return CrawlerStatus.serverError;
}
}
Expand Down
9 changes: 5 additions & 4 deletions lib/_services/api/token_service.dart
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import 'dart:convert';
import 'package:connectivity/connectivity.dart';
import 'package:flutter/widgets.dart';
import 'package:http/http.dart' as http;

import 'package:app_qldt/_utils/helper/const.dart';
Expand All @@ -19,7 +20,7 @@ class TokenService {
Future<void> upsert(String studentId) async {
if (await Connectivity().checkConnectivity() != ConnectivityResult.none) {
String? token = await _firebaseRepository.getToken();
print('Token: $token');
debugPrint('Token: $token');

final json = <String, String?>{
'id_student': studentId,
Expand All @@ -36,13 +37,13 @@ class TokenService {
)
.timeout(Const.requestTimeout);
} on Exception catch (e) {
print('Error: $e in Token service');
debugPrint('Error: $e in Token service');
return;
}

print('Upsert token status: ${response.body}');
debugPrint('Upsert token status: ${response.body}');
} else {
print('Token Service: Do not upsert since no internet connection');
debugPrint('Token Service: Do not upsert since no internet connection');
}
}
}
Loading

0 comments on commit f42cfaa

Please sign in to comment.