From 0b52d5d98b12b0d1b257c5d6f6f1ccc08f825dfe Mon Sep 17 00:00:00 2001 From: YiHungWONG <40423264+yihong1120@users.noreply.github.com> Date: Sat, 30 Dec 2023 18:36:40 +0000 Subject: [PATCH 1/2] Use logger instead of orint --- lib/services/report_service.dart | 7 +++++-- pubspec.yaml | 1 + 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/services/report_service.dart b/lib/services/report_service.dart index 93e7dfb..6cfb37f 100644 --- a/lib/services/report_service.dart +++ b/lib/services/report_service.dart @@ -1,7 +1,10 @@ import 'dart:convert'; import 'package:http/http.dart' as http; +import 'package:logger/logger.dart'; import '../models/traffic_violation.dart'; +var logger = Logger(); + class ReportService { final String apiUrl = 'https://your-api-url.com/reports'; @@ -30,11 +33,11 @@ class ReportService { if (response.statusCode == 200) { return true; } else { - print('Failed to create report: ${response.statusCode}'); + logger.d('Failed to create report: ${response.statusCode}'); return false; } } catch (e) { - print('Caught error: $e'); + logger.d('Caught error: $e'); return false; } } diff --git a/pubspec.yaml b/pubspec.yaml index aeacda1..9cfa05c 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -42,6 +42,7 @@ dependencies: intl: ^0.17.0 provider: ^6.0.1 http: ^0.13.3 + logger: ^1.1.0 dev_dependencies: flutter_test: From 2aaae95a9060f030786f24a730f0c7981f296c87 Mon Sep 17 00:00:00 2001 From: YiHungWONG <40423264+yihong1120@users.noreply.github.com> Date: Sat, 30 Dec 2023 18:40:56 +0000 Subject: [PATCH 2/2] use canLaunchUrl --- lib/services/social_service.dart | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/services/social_service.dart b/lib/services/social_service.dart index 7d32e22..64087d9 100644 --- a/lib/services/social_service.dart +++ b/lib/services/social_service.dart @@ -51,7 +51,7 @@ class SocialService { final String loginUrl = '$baseUrl/social/login/${provider.id}'; // 使用 url_launcher 打开浏览器窗口 - if (await canLaunch(loginUrl)) { + if (await canLaunchUrl(loginUrl)) { await launch(loginUrl); } else { throw 'Could not launch $loginUrl';