chore(notifications): fix conflig when show notification in android
This commit is contained in:
@@ -2,6 +2,8 @@
|
||||
|
||||
import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
import 'package:connectivity_plus/connectivity_plus.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:go_router/go_router.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
@@ -27,8 +29,6 @@ import '../constant/enums/local_keys_enums.dart';
|
||||
import '../network/network_manager.dart';
|
||||
|
||||
class APIServices {
|
||||
|
||||
|
||||
Map<String, String> headers = {
|
||||
'Accept': 'application/json',
|
||||
'Content-Type': 'application/json',
|
||||
@@ -92,7 +92,7 @@ class APIServices {
|
||||
// try {
|
||||
// return await apiCall();
|
||||
// } catch (e) {
|
||||
|
||||
|
||||
// AppLoggerUtils.error(e.toString());
|
||||
// return Future.error(e);
|
||||
// }
|
||||
@@ -104,12 +104,33 @@ class APIServices {
|
||||
bool checkMounted = true,
|
||||
}) async {
|
||||
try {
|
||||
// Quick connectivity check before attempting network calls.
|
||||
final conn = await Connectivity().checkConnectivity();
|
||||
if (conn == ConnectivityResult.none) {
|
||||
AppLoggerUtils.warning('No network connectivity');
|
||||
if (checkMounted && context.mounted) {
|
||||
showErrorTopSnackBarCustom(context, "Không có kết nối mạng");
|
||||
}
|
||||
return Future.error(const SocketException('No network connectivity'));
|
||||
}
|
||||
|
||||
return await apiCall();
|
||||
} catch (e) {
|
||||
} on SocketException catch (e, stackTrace) {
|
||||
// Network-related errors (DNS, timeout, host lookup...)
|
||||
AppLoggerUtils.warning('Network error when calling API: $e');
|
||||
if (checkMounted && context.mounted) {
|
||||
AppLoggerUtils.error("Không có kết nối mạng");
|
||||
}
|
||||
return Future.error(e);
|
||||
} catch (e, stackTrace) {
|
||||
// If widget was unmounted (e.g. background isolate), preserve previous behavior
|
||||
if (checkMounted && !context.mounted) {
|
||||
return Future.error('Widget not mounted');
|
||||
}
|
||||
showErrorTopSnackBarCustom(context, "Lỗi hệ thống");
|
||||
AppLoggerUtils.error("Lỗi hệ thống khi gọi API", e, stackTrace);
|
||||
if (checkMounted && context.mounted) {
|
||||
showErrorTopSnackBarCustom(context, "Lỗi hệ thống");
|
||||
}
|
||||
return Future.error(e);
|
||||
}
|
||||
}
|
||||
@@ -308,7 +329,6 @@ class APIServices {
|
||||
.getDataFromServer(APIPathConstants.PROVINCES_PATH),
|
||||
parser: (json) => Province.fromJsonDynamicList(json['items']),
|
||||
errorMessage: 'Lỗi khi GET /${APIPathConstants.PROVINCES_PATH}');
|
||||
|
||||
}
|
||||
|
||||
Future<List<Province>> getProvincesByName(String name) async {
|
||||
@@ -319,7 +339,6 @@ class APIServices {
|
||||
parser: (json) => Province.fromJsonDynamicList(json['items']),
|
||||
errorMessage: 'Lỗi khi GET /${APIPathConstants.PROVINCES_PATH}/$name',
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
Future<Province> getProvinceByID(String provinceID) async {
|
||||
|
||||
Reference in New Issue
Block a user