Fix 2799
This commit is contained in:
@ -9,6 +9,13 @@ import 'package:rogapp/utils/string_values.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
// import 'package:is_lock_screen/is_lock_screen.dart';
|
||||
|
||||
import 'package:rogapp/services/device_info_service.dart';
|
||||
import 'package:rogapp/services/error_service.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'dart:async';
|
||||
|
||||
Map<String, dynamic> deviceInfo = {};
|
||||
|
||||
void saveGameState() async {
|
||||
DestinationController destinationController =
|
||||
Get.find<DestinationController>();
|
||||
@ -35,8 +42,8 @@ void restoreGame() async {
|
||||
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
await FlutterMapTileCaching.initialise();
|
||||
|
||||
final StoreDirectory instanceA = FMTC.instance('OpenStreetMap (A)');
|
||||
await instanceA.manage.createAsync();
|
||||
await instanceA.metadata.addAsync(
|
||||
@ -51,7 +58,21 @@ void main() async {
|
||||
key: 'behaviour',
|
||||
value: 'cacheFirst',
|
||||
);
|
||||
runApp(const MyApp());
|
||||
|
||||
deviceInfo = await DeviceInfoService.getDeviceInfo();
|
||||
|
||||
FlutterError.onError = (FlutterErrorDetails details) {
|
||||
FlutterError.presentError(details);
|
||||
ErrorService.reportError(details.exception, details.stack ?? StackTrace.current, deviceInfo);
|
||||
};
|
||||
|
||||
runZonedGuarded(() {
|
||||
runApp(const ProviderScope(child: MyApp()));
|
||||
}, (error, stackTrace) {
|
||||
ErrorService.reportError(error, stackTrace, deviceInfo);
|
||||
});
|
||||
|
||||
//runApp(const MyApp());
|
||||
}
|
||||
|
||||
class MyApp extends StatefulWidget {
|
||||
|
||||
39
lib/services/device_info_service.dart
Normal file
39
lib/services/device_info_service.dart
Normal file
@ -0,0 +1,39 @@
|
||||
import 'dart:io';
|
||||
//import 'package:device_info/device_info.dart';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:package_info_plus/package_info_plus.dart';
|
||||
import 'package:device_info_plus/device_info_plus.dart';
|
||||
|
||||
class DeviceInfoService {
|
||||
static Future<Map<String, dynamic>> getDeviceInfo() async {
|
||||
final DeviceInfoPlugin deviceInfo = DeviceInfoPlugin();
|
||||
final PackageInfo packageInfo = await PackageInfo.fromPlatform();
|
||||
|
||||
if (Platform.isAndroid) {
|
||||
final AndroidDeviceInfo androidInfo = await deviceInfo.androidInfo;
|
||||
return {
|
||||
'os': 'Android',
|
||||
'os_version': androidInfo.version.release,
|
||||
'device_model': androidInfo.model,
|
||||
'app_version': packageInfo.version,
|
||||
'app_build_number': packageInfo.buildNumber,
|
||||
};
|
||||
} else if (Platform.isIOS) {
|
||||
final IosDeviceInfo iosInfo = await deviceInfo.iosInfo;
|
||||
return {
|
||||
'os': 'iOS',
|
||||
'os_version': iosInfo.systemVersion,
|
||||
'device_model': iosInfo.model,
|
||||
'app_version': packageInfo.version,
|
||||
'app_build_number': packageInfo.buildNumber,
|
||||
};
|
||||
} else {
|
||||
return {
|
||||
'os': Platform.operatingSystem,
|
||||
'os_version': Platform.operatingSystemVersion,
|
||||
'app_version': packageInfo.version,
|
||||
'app_build_number': packageInfo.buildNumber,
|
||||
};
|
||||
}
|
||||
}
|
||||
}
|
||||
48
lib/services/error_service.dart
Normal file
48
lib/services/error_service.dart
Normal file
@ -0,0 +1,48 @@
|
||||
import 'dart:async';
|
||||
import 'dart:io';
|
||||
import 'package:flutter/foundation.dart';
|
||||
import 'package:http/http.dart' as http;
|
||||
|
||||
class ErrorService {
|
||||
static Future<void> reportError(dynamic error, StackTrace stackTrace, Map<String, dynamic> deviceInfo) async {
|
||||
try {
|
||||
final String errorMessage = error.toString();
|
||||
final String stackTraceString = stackTrace.toString();
|
||||
final String estimatedCause = _estimateErrorCause(errorMessage);
|
||||
// final String deviceInfo = await _getDeviceInfo();
|
||||
|
||||
final Uri url = Uri.parse('https://rogaining.sumasen.net/report-error');
|
||||
final response = await http.post(
|
||||
url,
|
||||
body: {
|
||||
'error_message': errorMessage,
|
||||
'stack_trace': stackTraceString,
|
||||
'estimated_cause': estimatedCause,
|
||||
'device_info': deviceInfo,
|
||||
},
|
||||
);
|
||||
|
||||
if (response.statusCode == 200) {
|
||||
// エラー報告が成功した場合の処理(必要に応じて)
|
||||
} else {
|
||||
// エラー報告が失敗した場合の処理(必要に応じて)
|
||||
}
|
||||
} catch (e) {
|
||||
// エラー報告中にエラーが発生した場合の処理(必要に応じて)
|
||||
}
|
||||
}
|
||||
|
||||
static String _estimateErrorCause(String errorMessage) {
|
||||
// エラーメッセージに基づいてエラーの原因を推定するロジックを追加する
|
||||
if (errorMessage.contains('NetworkException')) {
|
||||
return 'ネットワーク接続エラー';
|
||||
} else if (errorMessage.contains('DatabaseException')) {
|
||||
return 'データベースエラー';
|
||||
} else if (errorMessage.contains('AuthenticationException')) {
|
||||
return '認証エラー';
|
||||
} else {
|
||||
return '不明なエラー';
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user