diff --git a/ios/Podfile.lock b/ios/Podfile.lock index 344575e..a8e7760 100644 --- a/ios/Podfile.lock +++ b/ios/Podfile.lock @@ -4,6 +4,8 @@ PODS: - connectivity_plus (0.0.1): - Flutter - ReachabilitySwift + - device_info_plus (0.0.1): + - Flutter - Flutter (1.0.0) - flutter_compass (0.0.1): - Flutter @@ -20,6 +22,8 @@ PODS: - Flutter - isar_flutter_libs (1.0.0): - Flutter + - package_info_plus (0.4.5): + - Flutter - path_provider_foundation (0.0.1): - Flutter - FlutterMacOS @@ -40,6 +44,7 @@ PODS: DEPENDENCIES: - camera_avfoundation (from `.symlinks/plugins/camera_avfoundation/ios`) - connectivity_plus (from `.symlinks/plugins/connectivity_plus/ios`) + - device_info_plus (from `.symlinks/plugins/device_info_plus/ios`) - Flutter (from `Flutter`) - flutter_compass (from `.symlinks/plugins/flutter_compass/ios`) - flutter_keyboard_visibility (from `.symlinks/plugins/flutter_keyboard_visibility/ios`) @@ -47,6 +52,7 @@ DEPENDENCIES: - image_gallery_saver (from `.symlinks/plugins/image_gallery_saver/ios`) - image_picker_ios (from `.symlinks/plugins/image_picker_ios/ios`) - isar_flutter_libs (from `.symlinks/plugins/isar_flutter_libs/ios`) + - package_info_plus (from `.symlinks/plugins/package_info_plus/ios`) - path_provider_foundation (from `.symlinks/plugins/path_provider_foundation/darwin`) - permission_handler_apple (from `.symlinks/plugins/permission_handler_apple/ios`) - pointer_interceptor_ios (from `.symlinks/plugins/pointer_interceptor_ios/ios`) @@ -64,6 +70,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/camera_avfoundation/ios" connectivity_plus: :path: ".symlinks/plugins/connectivity_plus/ios" + device_info_plus: + :path: ".symlinks/plugins/device_info_plus/ios" Flutter: :path: Flutter flutter_compass: @@ -78,6 +86,8 @@ EXTERNAL SOURCES: :path: ".symlinks/plugins/image_picker_ios/ios" isar_flutter_libs: :path: ".symlinks/plugins/isar_flutter_libs/ios" + package_info_plus: + :path: ".symlinks/plugins/package_info_plus/ios" path_provider_foundation: :path: ".symlinks/plugins/path_provider_foundation/darwin" permission_handler_apple: @@ -94,6 +104,7 @@ EXTERNAL SOURCES: SPEC CHECKSUMS: camera_avfoundation: 759172d1a77ae7be0de08fc104cfb79738b8a59e connectivity_plus: bf0076dd84a130856aa636df1c71ccaff908fa1d + device_info_plus: 97af1d7e84681a90d0693e63169a5d50e0839a0d Flutter: e0871f40cf51350855a761d2e70bf5af5b9b5de7 flutter_compass: cbbd285cea1584c7ac9c4e0c3e1f17cbea55e855 flutter_keyboard_visibility: 0339d06371254c3eb25eeb90ba8d17dca8f9c069 @@ -102,6 +113,7 @@ SPEC CHECKSUMS: image_gallery_saver: cb43cc43141711190510e92c460eb1655cd343cb image_picker_ios: 99dfe1854b4fa34d0364e74a78448a0151025425 isar_flutter_libs: b69f437aeab9c521821c3f376198c4371fa21073 + package_info_plus: 58f0028419748fad15bf008b270aaa8e54380b1c path_provider_foundation: 3784922295ac71e43754bd15e0653ccfd36a147c permission_handler_apple: 9878588469a2b0d0fc1e048d9f43605f92e6cec2 pointer_interceptor_ios: 9280618c0b2eeb80081a343924aa8ad756c21375 diff --git a/lib/main.dart b/lib/main.dart index f29f4e6..51ceaae 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -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 deviceInfo = {}; + void saveGameState() async { DestinationController destinationController = Get.find(); @@ -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 { diff --git a/lib/services/device_info_service.dart b/lib/services/device_info_service.dart new file mode 100644 index 0000000..aa7b24d --- /dev/null +++ b/lib/services/device_info_service.dart @@ -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> 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, + }; + } + } +} diff --git a/lib/services/error_service.dart b/lib/services/error_service.dart new file mode 100644 index 0000000..c432769 --- /dev/null +++ b/lib/services/error_service.dart @@ -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 reportError(dynamic error, StackTrace stackTrace, Map 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 '不明なエラー'; + } + } +} + diff --git a/macos/Flutter/GeneratedPluginRegistrant.swift b/macos/Flutter/GeneratedPluginRegistrant.swift index 0d0cd75..bdbe12c 100644 --- a/macos/Flutter/GeneratedPluginRegistrant.swift +++ b/macos/Flutter/GeneratedPluginRegistrant.swift @@ -6,9 +6,11 @@ import FlutterMacOS import Foundation import connectivity_plus +import device_info_plus import file_selector_macos import geolocator_apple import isar_flutter_libs +import package_info_plus import path_provider_foundation import shared_preferences_foundation import sqflite @@ -16,9 +18,11 @@ import url_launcher_macos func RegisterGeneratedPlugins(registry: FlutterPluginRegistry) { ConnectivityPlugin.register(with: registry.registrar(forPlugin: "ConnectivityPlugin")) + DeviceInfoPlusMacosPlugin.register(with: registry.registrar(forPlugin: "DeviceInfoPlusMacosPlugin")) FileSelectorPlugin.register(with: registry.registrar(forPlugin: "FileSelectorPlugin")) GeolocatorPlugin.register(with: registry.registrar(forPlugin: "GeolocatorPlugin")) IsarFlutterLibsPlugin.register(with: registry.registrar(forPlugin: "IsarFlutterLibsPlugin")) + FPPPackageInfoPlusPlugin.register(with: registry.registrar(forPlugin: "FPPPackageInfoPlusPlugin")) PathProviderPlugin.register(with: registry.registrar(forPlugin: "PathProviderPlugin")) SharedPreferencesPlugin.register(with: registry.registrar(forPlugin: "SharedPreferencesPlugin")) SqflitePlugin.register(with: registry.registrar(forPlugin: "SqflitePlugin")) diff --git a/pubspec.lock b/pubspec.lock index e736c6b..10df839 100644 --- a/pubspec.lock +++ b/pubspec.lock @@ -165,10 +165,10 @@ packages: dependency: transitive description: name: cross_file - sha256: fedaadfa3a6996f75211d835aaeb8fede285dae94262485698afd832371b9a5e + sha256: "55d7b444feb71301ef6b8838dbc1ae02e63dd48c8773f3810ff53bb1e2945b32" url: "https://pub.dev" source: hosted - version: "0.3.3+8" + version: "0.3.4+1" crypto: dependency: transitive description: @@ -201,6 +201,22 @@ packages: url: "https://pub.dev" source: hosted version: "0.7.10" + device_info_plus: + dependency: "direct main" + description: + name: device_info_plus + sha256: "50fb435ed30c6d2525cbfaaa0f46851ea6131315f213c0d921b0e407b34e3b84" + url: "https://pub.dev" + source: hosted + version: "10.0.1" + device_info_plus_platform_interface: + dependency: transitive + description: + name: device_info_plus_platform_interface + sha256: d3b01d5868b50ae571cd1dc6e502fc94d956b665756180f7b16ead09e836fd64 + url: "https://pub.dev" + source: hosted + version: "7.0.0" fake_async: dependency: transitive description: @@ -418,10 +434,10 @@ packages: dependency: "direct main" description: name: flutter_riverpod - sha256: da9591d1f8d5881628ccd5c25c40e74fc3eef50ba45e40c3905a06e1712412d5 + sha256: "0f1974eff5bbe774bf1d870e406fc6f29e3d6f1c46bd9c58e7172ff68a785d7d" url: "https://pub.dev" source: hosted - version: "2.4.9" + version: "2.5.1" flutter_test: dependency: "direct dev" description: flutter @@ -548,10 +564,10 @@ packages: dependency: "direct main" description: name: http - sha256: a2bbf9d017fcced29139daa8ed2bba4ece450ab222871df93ca9eec6f80c34ba + sha256: "761a297c042deedc1ffbb156d6e2af13886bb305c2a343a4d972504cd67dd938" url: "https://pub.dev" source: hosted - version: "1.2.0" + version: "1.2.1" http_parser: dependency: transitive description: @@ -816,6 +832,22 @@ packages: url: "https://pub.dev" source: hosted version: "0.5.0" + package_info_plus: + dependency: "direct main" + description: + name: package_info_plus + sha256: cb44f49b6e690fa766f023d5b22cac6b9affe741dd792b6ac7ad4fabe0d7b097 + url: "https://pub.dev" + source: hosted + version: "6.0.0" + package_info_plus_platform_interface: + dependency: transitive + description: + name: package_info_plus_platform_interface + sha256: "9bc8ba46813a4cc42c66ab781470711781940780fd8beddd0c3da62506d3a6c6" + url: "https://pub.dev" + source: hosted + version: "2.0.1" path: dependency: transitive description: @@ -980,10 +1012,10 @@ packages: dependency: transitive description: name: pointer_interceptor_web - sha256: "9386e064097fd16419e935c23f08f35b58e6aaec155dd39bd6a003b88f9c14b4" + sha256: a6237528b46c411d8d55cdfad8fcb3269fc4cbb26060b14bff94879165887d1e url: "https://pub.dev" source: hosted - version: "0.10.1+2" + version: "0.10.2" pointycastle: dependency: transitive description: @@ -1044,10 +1076,10 @@ packages: dependency: transitive description: name: riverpod - sha256: "942999ee48b899f8a46a860f1e13cee36f2f77609eb54c5b7a669bb20d550b11" + sha256: f21b32ffd26a36555e501b04f4a5dca43ed59e16343f1a30c13632b2351dfa4d url: "https://pub.dev" source: hosted - version: "2.4.9" + version: "2.5.1" shared_preferences: dependency: "direct main" description: @@ -1092,10 +1124,10 @@ packages: dependency: transitive description: name: shared_preferences_web - sha256: "7b15ffb9387ea3e237bb7a66b8a23d2147663d391cafc5c8f37b2e7b4bde5d21" + sha256: "9aee1089b36bd2aafe06582b7d7817fd317ef05fc30e6ba14bff247d0933042a" url: "https://pub.dev" source: hosted - version: "2.2.2" + version: "2.3.0" shared_preferences_windows: dependency: transitive description: @@ -1297,10 +1329,10 @@ packages: dependency: transitive description: name: url_launcher_web - sha256: fff0932192afeedf63cdd50ecbb1bc825d31aed259f02bb8dba0f3b729a5e88b + sha256: "3692a459204a33e04bc94f5fb91158faf4f2c8903281ddd82915adecdb1a901d" url: "https://pub.dev" source: hosted - version: "2.2.3" + version: "2.3.0" url_launcher_windows: dependency: transitive description: @@ -1345,10 +1377,10 @@ packages: dependency: transitive description: name: web - sha256: afe077240a270dcfd2aafe77602b4113645af95d0ad31128cc02bce5ac5d5152 + sha256: "97da13628db363c635202ad97068d47c5b8aa555808e7a9411963c533b449b27" url: "https://pub.dev" source: hosted - version: "0.3.0" + version: "0.5.1" win32: dependency: transitive description: @@ -1357,6 +1389,14 @@ packages: url: "https://pub.dev" source: hosted version: "5.2.0" + win32_registry: + dependency: transitive + description: + name: win32_registry + sha256: "41fd8a189940d8696b1b810efb9abcf60827b6cbfab90b0c43e8439e3a39d85a" + url: "https://pub.dev" + source: hosted + version: "1.1.2" wkt_parser: dependency: transitive description: @@ -1390,5 +1430,5 @@ packages: source: hosted version: "3.1.2" sdks: - dart: ">=3.2.3 <4.0.0" - flutter: ">=3.16.6" + dart: ">=3.3.0 <4.0.0" + flutter: ">=3.19.0" diff --git a/pubspec.yaml b/pubspec.yaml index acd11ef..5c79059 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -43,6 +43,8 @@ dependencies: # permission_handler_android 12.0.3 (12.0.5 available) # permission_handler_apple 9.3.0 (9.4.4 available) # permission_handler_platform_interface 4.1.0 (4.2.1 available) + package_info_plus: ^6.0.0 + device_info_plus: ^10.0.1 google_api_availability: ^5.0.0 tuple: ^2.0.0 latlong2: ^0.9.0 @@ -82,7 +84,7 @@ dependencies: shared_preferences: ^2.0.15 # gallery_saver: ^2.3.2 image_gallery_saver: ^2.0.3 - flutter_riverpod: ^2.4.0 + flutter_riverpod: ^2.5.1 http: ^1.1.0 flutter_icons: