1
1
import 'dart:async' ;
2
+ import 'dart:io' ;
2
3
import 'package:flutter/material.dart' ;
3
4
import '../services/enhanced_update_service.dart' ;
4
5
import '../services/update_manager.dart' ;
@@ -28,12 +29,21 @@ class _UpdateProgressDialogState extends State<UpdateProgressDialog> {
28
29
bool _isDownloading = false ;
29
30
bool _isCompleted = false ;
30
31
bool _hasError = false ;
32
+ bool _isInitialized = false ; // 初期化フラグを追加
31
33
String ? _downloadedFilePath;
32
-
33
34
@override
34
35
void initState () {
35
36
super .initState ();
36
- _startDownload ();
37
+ // Theme.of(context)を使用する処理はdidChangeDependenciesに移動
38
+ }
39
+ @override
40
+ void didChangeDependencies () {
41
+ super .didChangeDependencies ();
42
+ // 初回実行時のみアップデートチェックを開始
43
+ if (! _isInitialized && ! _isDownloading && ! _isCompleted && ! _hasError) {
44
+ _isInitialized = true ;
45
+ _startDownload ();
46
+ }
37
47
}
38
48
39
49
@override
@@ -42,28 +52,41 @@ class _UpdateProgressDialogState extends State<UpdateProgressDialog> {
42
52
_updateService.disposeProgressStream ();
43
53
super .dispose ();
44
54
}
45
-
46
55
void _startDownload () async {
47
56
setState (() {
48
57
_isDownloading = true ;
49
58
_hasError = false ;
50
59
});
51
60
52
61
// Check permissions for Android
53
- if (Theme .of (context).platform == TargetPlatform .android) {
54
- bool permissionGranted = await _updateService.requestStoragePermission ();
55
- if (! permissionGranted) {
56
- setState (() {
57
- _hasError = true ;
58
- _currentProgress = UpdateProgress (
59
- progress: 0.0 ,
60
- status: 'ストレージ権限が必要です' ,
61
- errorMessage: 'Storage permission denied' ,
62
- );
63
- _isDownloading = false ;
64
- });
65
- return ;
62
+ try {
63
+ // Use Platform.isAndroid instead of Theme.of(context).platform
64
+ if (Platform .isAndroid) {
65
+ bool permissionGranted = await _updateService.requestStoragePermission ();
66
+ if (! permissionGranted) {
67
+ setState (() {
68
+ _hasError = true ;
69
+ _currentProgress = UpdateProgress (
70
+ progress: 0.0 ,
71
+ status: 'ストレージ権限が必要です' ,
72
+ errorMessage: 'Storage permission denied' ,
73
+ );
74
+ _isDownloading = false ;
75
+ });
76
+ return ;
77
+ }
66
78
}
79
+ } catch (e) {
80
+ setState (() {
81
+ _hasError = true ;
82
+ _currentProgress = UpdateProgress (
83
+ progress: 0.0 ,
84
+ status: '権限チェックエラー' ,
85
+ errorMessage: e.toString (),
86
+ );
87
+ _isDownloading = false ;
88
+ });
89
+ return ;
67
90
}
68
91
69
92
// Listen to progress stream
0 commit comments