-
Notifications
You must be signed in to change notification settings - Fork 0
/
restore_data_page.dart
185 lines (172 loc) · 5.12 KB
/
restore_data_page.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
import 'package:flutter/material.dart';
import 'package:connectivity_plus/connectivity_plus.dart';
import 'class_definition.dart';
class RestoreDataPage extends StatefulWidget {
const RestoreDataPage({Key? key}) : super(key: key);
@override
RestoreDataPageState createState() => RestoreDataPageState();
}
class RestoreDataPageState extends State<RestoreDataPage> {
List<BackupSet> _backupSetList = [];
bool _symbolSet = false;
Function? _restoreData;
Function? _removeBackup;
@override
Widget build(BuildContext context) {
final args = ModalRoute.of(context)!.settings.arguments as FullRestoreData;
_backupSetList = args.backupSetList;
_symbolSet = args.symbolSet;
_restoreData = args.restoreData;
_removeBackup = args.removeBackup;
return Scaffold(
appBar: AppBar(
title: const Text('リストアデータ選択'),
),
body: _makeDisplayForm(),
);
}
// 表示フォームウィジェット
Widget _makeDisplayForm() {
return Container(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Align(
alignment: Alignment.topLeft,
child: Column(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Flexible(
child: ListView.builder(
itemCount: _backupSetList.length,
itemBuilder: (BuildContext context, int index) {
return _item(_backupSetList[index]);
},
),
),
],
),
),
);
}
// 項目表示ウィジェット
Widget _item(BackupSet backupSet) {
String describe = (backupSet.describe ?? '');
return Card(
child: Container(
decoration: BoxDecoration(
border: Border.all(width: 1.0, color: Colors.blue),
),
child: ListTile(
visualDensity: VisualDensity.comfortable,
leading: const Icon(
Icons.backup_table,
size: 30.0,
),
title: Text(
'''${backupSet.title}
$describe''',
style: const TextStyle(fontSize: 14),
),
onTap: () {
if (_symbolSet) {
_overwriteConfirmDialog(backupSet.title);
} else {
_restore(backupSet.title);
}
},
trailing: IconButton(
icon: const Icon(
Icons.delete,
size: 20.0,
),
onPressed: () {
_deleteConfirmDialog(backupSet.title);
},
),
),
),
);
}
// 確認ダイアログ(既存データ上書き・モバイル通信でのリストア)
Future<void> _overwriteConfirmDialog(String backupTitle) async {
final ConnectivityResult connectivityResult =
await (Connectivity().checkConnectivity());
final String message = (connectivityResult == ConnectivityResult.mobile
? '''現在モバイル通信中です。
本当にリストアしますか?
(既存データは上書きされます)'''
: '既存データを上書きしてもよろしいですか?');
if (!mounted) return;
showDialog(
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('確認'),
content: Text(message),
actions: <Widget>[
TextButton(
child: const Text('いいえ'),
onPressed: () {
Navigator.pop(context);
},
),
TextButton(
child: const Text('はい(リストア)'),
onPressed: () {
_restore(backupTitle);
},
),
],
),
);
}
// リストア
Future<void> _restore(String backupTitle) async {
await _restoreData!(backupTitle);
await _finishDialog(backupTitle);
}
// 完了ダイアログ
Future<void> _finishDialog(String backupTitle) async {
showDialog(
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('完了'),
content: Text('''$backupTitle
のリストアが完了しました。'''),
actions: <Widget>[
TextButton(
child: const Text('戻る'),
onPressed: () {
Navigator.popUntil(context, ModalRoute.withName('/'));
},
),
],
),
);
}
// 既存データ削除(確認ダイアログ)
Future<void> _deleteConfirmDialog(String backupTitle) async {
showDialog(
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('確認'),
content: Text('''バックアップデータ
$backupTitle
を削除してもよろしいですか?'''),
actions: <Widget>[
TextButton(
child: const Text('いいえ'),
onPressed: () {
Navigator.pop(context);
},
),
TextButton(
child: const Text('はい'),
onPressed: () {
_removeBackup!(backupTitle);
},
),
],
),
);
}
}