20240903 pre release
This commit is contained in:
133
lib/main.dart
133
lib/main.dart
@ -43,6 +43,8 @@ import 'package:gifunavi/provider/cached_tile_provider.dart';
|
||||
|
||||
import 'package:timezone/timezone.dart' as tz;
|
||||
|
||||
import 'package:gifunavi/services/motion_service.dart';
|
||||
|
||||
Map<String, dynamic> deviceInfo = {};
|
||||
|
||||
/*
|
||||
@ -70,7 +72,9 @@ Future<void> saveGameState() async {
|
||||
if(indexController.currentUser[0]["user"]["event_date"]!=null) {
|
||||
final date = indexController.currentUser[0]["user"]["event_date"];
|
||||
pref.setString('eventDate', date.toIso8601String());
|
||||
|
||||
debugPrint("Saved date is ${date} => ${date.toIso8601String()}");
|
||||
|
||||
pref.setString('eventCode', indexController.currentUser[0]["user"]["event_code"]);
|
||||
pref.setString('teamName', indexController.currentUser[0]["user"]["team_name"]);
|
||||
pref.setString('group', indexController.currentUser[0]["user"]["group"]);
|
||||
@ -197,6 +201,11 @@ void _showEventSelectionWarning() {
|
||||
void main() async {
|
||||
WidgetsFlutterBinding.ensureInitialized();
|
||||
|
||||
if (Platform.isIOS) {
|
||||
// アプリの起動時にモーション更新を開始
|
||||
await MotionService.startMotionUpdates();
|
||||
}
|
||||
|
||||
final IndexController _indexController;
|
||||
|
||||
FlutterError.onError = (FlutterErrorDetails details) {
|
||||
@ -207,20 +216,7 @@ void main() async {
|
||||
};
|
||||
|
||||
try {
|
||||
//await Get.putAsync(() => ApiService().init());
|
||||
await _initApiService();
|
||||
debugPrint("1: start ApiService");
|
||||
|
||||
// すべてのコントローラーとサービスを非同期で初期化
|
||||
Get.lazyPut(() => IndexController(apiService: Get.find<ApiService>()));
|
||||
debugPrint("2: start IndexController");
|
||||
|
||||
|
||||
// その他のコントローラーを遅延初期化
|
||||
Get.lazyPut(() => SettingsController());
|
||||
debugPrint("2: start SettingsController");
|
||||
Get.lazyPut(() => DestinationController());
|
||||
debugPrint("3: start DestinationController");
|
||||
|
||||
await initServices();
|
||||
|
||||
@ -237,12 +233,37 @@ void main() async {
|
||||
Future<void> initServices() async {
|
||||
print('Starting services ...');
|
||||
try {
|
||||
//await Get.putAsync(() => ApiService().init());
|
||||
await _initApiService();
|
||||
debugPrint("1: start ApiService");
|
||||
|
||||
// コントローラーを初期化
|
||||
Get.put(IndexController(apiService: Get.find<ApiService>()), permanent: true);
|
||||
Get.put(SettingsController(), permanent: true);
|
||||
Get.put(DestinationController(), permanent: true);
|
||||
Get.put(LocationController(), permanent: true);
|
||||
|
||||
debugPrint("2: Controllers initialized");
|
||||
/*
|
||||
// すべてのコントローラーとサービスを非同期で初期化
|
||||
Get.lazyPut(() => IndexController(apiService: Get.find<ApiService>()));
|
||||
debugPrint("2: start IndexController");
|
||||
|
||||
// その他のコントローラーを遅延初期化
|
||||
Get.lazyPut(() => SettingsController());
|
||||
debugPrint("2: start SettingsController");
|
||||
Get.lazyPut(() => DestinationController());
|
||||
debugPrint("3: start DestinationController");
|
||||
Get.lazyPut(() => LocationController());
|
||||
debugPrint("4: start LocationController");
|
||||
*/
|
||||
|
||||
// 非同期処理を並列実行
|
||||
await Future.wait([
|
||||
_initTimeZone(),
|
||||
_initCacheProvider(),
|
||||
]);
|
||||
|
||||
print('=== 5. Initialized TimeZone...');
|
||||
print('=== 6. CacheProvider started...');
|
||||
|
||||
@ -520,6 +541,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
||||
late final DestinationController _destinationController;
|
||||
late final PermissionController _permissionController;
|
||||
Timer? _memoryCheckTimer;
|
||||
bool _isControllerInitialized = false;
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
@ -545,24 +567,94 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
||||
// ここに他の初期化処理を追加できます
|
||||
}
|
||||
|
||||
void _initializeControllers() {
|
||||
Future <void> _initializeControllers() async {
|
||||
|
||||
while (!Get.isRegistered<LocationController>() ||
|
||||
!Get.isRegistered<IndexController>() ||
|
||||
!Get.isRegistered<DestinationController>() ||
|
||||
!Get.isRegistered<PermissionController>()) {
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
}
|
||||
|
||||
if (!_isControllerInitialized) {
|
||||
_locationController = Get.find<LocationController>();
|
||||
_indexController = Get.find<IndexController>();
|
||||
_destinationController = Get.find<DestinationController>();
|
||||
_permissionController = Get.find<PermissionController>();
|
||||
_isControllerInitialized = true;
|
||||
}
|
||||
|
||||
/*
|
||||
if (!Get.isRegistered<IndexController>()) {
|
||||
while (true) {
|
||||
try {
|
||||
_locationController = Get.find<LocationController>();
|
||||
break; // DestinationControllerが見つかったらループを抜ける
|
||||
} catch (e) {
|
||||
// DestinationControllerがまだ利用可能でない場合は少し待ってから再試行
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
if (!Get.isRegistered<LocationController>()) {
|
||||
_locationController = Get.put(LocationController(), permanent: true);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
while (true) {
|
||||
try {
|
||||
_indexController = Get.find<IndexController>();
|
||||
break; // DestinationControllerが見つかったらループを抜ける
|
||||
} catch (e) {
|
||||
// DestinationControllerがまだ利用可能でない場合は少し待ってから再試行
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
if (!Get.isRegistered<IndexController>()) {
|
||||
_indexController = Get.put(IndexController(apiService: Get.find<ApiService>()), permanent: true);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
while (true) {
|
||||
try {
|
||||
_destinationController = Get.find<DestinationController>();
|
||||
break; // DestinationControllerが見つかったらループを抜ける
|
||||
} catch (e) {
|
||||
// DestinationControllerがまだ利用可能でない場合は少し待ってから再試行
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
if (!Get.isRegistered<DestinationController>()) {
|
||||
_destinationController =
|
||||
Get.put(DestinationController(), permanent: true);
|
||||
}
|
||||
*/
|
||||
|
||||
/*
|
||||
while (true) {
|
||||
try {
|
||||
_permissionController = Get.find<PermissionController>();
|
||||
break; // DestinationControllerが見つかったらループを抜ける
|
||||
} catch (e) {
|
||||
// DestinationControllerがまだ利用可能でない場合は少し待ってから再試行
|
||||
await Future.delayed(const Duration(milliseconds: 100));
|
||||
}
|
||||
}
|
||||
*/
|
||||
/*
|
||||
if (!Get.isRegistered<PermissionController>()) {
|
||||
_permissionController = Get.put(PermissionController());
|
||||
}
|
||||
*/
|
||||
// 他の必要なコントローラーの初期化
|
||||
|
||||
*/
|
||||
|
||||
}
|
||||
|
||||
void _startMemoryMonitoring() {
|
||||
@ -677,6 +769,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
||||
|
||||
@override
|
||||
void dispose() {
|
||||
_isControllerInitialized = false;
|
||||
WidgetsBinding.instance.removeObserver(this);
|
||||
_memoryCheckTimer?.cancel();
|
||||
super.dispose();
|
||||
@ -704,6 +797,9 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
||||
|
||||
switch (state) {
|
||||
case AppLifecycleState.resumed:
|
||||
if (Platform.isIOS) {
|
||||
MotionService.startMotionUpdates();
|
||||
}
|
||||
//await _onResumed();
|
||||
await _onResumed();
|
||||
break;
|
||||
@ -714,6 +810,7 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
||||
break;
|
||||
|
||||
case AppLifecycleState.paused:
|
||||
MotionService.stopMotionUpdates();
|
||||
// バックグラウンドに移行したときの処理
|
||||
//locationController.resumePositionStream();
|
||||
await _onPaused();
|
||||
@ -740,7 +837,9 @@ class _MyAppState extends State<MyApp> with WidgetsBindingObserver {
|
||||
Future<void> _onResumed() async {
|
||||
debugPrint("==(Status Changed)==> RESUMED");
|
||||
try {
|
||||
_initializeControllers();
|
||||
if (!_isControllerInitialized) {
|
||||
await _initializeControllers();
|
||||
}
|
||||
|
||||
await stopBackgroundTracking();
|
||||
_destinationController.restartGPS();
|
||||
|
||||
Reference in New Issue
Block a user