-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdisplay_picture_page.dart
203 lines (191 loc) · 6.11 KB
/
display_picture_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
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
import 'dart:io';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:gap/gap.dart';
import 'package:share_plus/share_plus.dart';
import 'class_definition.dart';
class DisplayPicturePage extends StatefulWidget {
const DisplayPicturePage({Key? key}) : super(key: key);
@override
DisplayPicturePageState createState() => DisplayPicturePageState();
}
class DisplayPicturePageState extends State<DisplayPicturePage> {
Picture? _picture;
Function? _modifyPicture;
Function? _removePicture;
Function? _localFile;
Function? _localFilePath;
Function? _lookUpPicture;
String _comment = '';
@override
Widget build(BuildContext context) {
final args = ModalRoute.of(context)!.settings.arguments as PictureInfo;
_picture = args.picture;
_modifyPicture = args.modifyPicture;
_removePicture = args.removePicture;
_localFile = args.localFile;
_localFilePath = args.localFilePath;
_lookUpPicture = args.lookUpPicture;
_comment = args.picture.comment;
return Scaffold(
appBar: AppBar(
title: const Text('画像情報表示'),
),
body: _makeDisplayForm(),
bottomNavigationBar: _makeBottomAppBar(),
);
}
// 表示フォームウィジェット
Widget _makeDisplayForm() {
File? file = _localFile!(_picture!);
return Container(
padding: const EdgeInsets.symmetric(horizontal: 20.0),
child: Wrap(
children: <Widget>[
Align(
alignment: Alignment.topLeft,
child: Column(
mainAxisSize: MainAxisSize.min,
children: [
const Gap(12),
(file != null
? Image.file(file, height: 360.0, fit: BoxFit.scaleDown)
: const Icon(
Icons.no_photography,
size: 240.0,
)),
const Gap(12),
Text(_picture!.dateTime.toString().substring(0, 19),
textAlign: TextAlign.left,
style: const TextStyle(fontSize: 18.0)),
const Gap(12),
Text(_comment,
textAlign: TextAlign.left,
style: const TextStyle(fontSize: 16.0)),
const Gap(12),
Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
TextButton(
child: const Text('編集'),
onPressed: () {
_modifyPictureInfoDialog(context);
},
),
TextButton(
child: const Text('削除'),
onPressed: () {
_removePictureDialog(context);
},
),
TextButton(
child: const Text('閉じる'),
onPressed: () {
Navigator.pop(context);
},
),
],
),
],
),
),
],
),
);
}
// ボトムナビゲーションバー
BottomAppBar _makeBottomAppBar() {
return BottomAppBar(
child: Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
IconButton(
icon: const Icon(Icons.share),
color: Colors.black87,
onPressed: () {
// 共有
_sharePicture();
},
),
const Gap(4),
]));
}
// 共有
Future<void> _sharePicture() async {
List<XFile> imagePaths = [XFile(_localFilePath!(_picture!))];
await Share.shareXFiles(imagePaths,
text: _picture!.comment != '無題' ? _picture!.comment : '');
}
// 画像情報変更(ダイアログ)
void _modifyPictureInfoDialog(BuildContext context) {
showDialog(
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('画像情報変更'),
content: TextFormField(
initialValue: _comment,
autofocus: true,
maxLength: 40,
maxLengthEnforcement: MaxLengthEnforcement.none,
decoration: const InputDecoration(
hintText: 'コメントを入力してください',
labelText: 'コメント',
),
maxLines: null,
onChanged: (String text) => _comment = text,
),
actions: <Widget>[
TextButton(
child: const Text('キャンセル'),
onPressed: () {
Navigator.pop(context);
},
),
TextButton(
child: const Text('保存'),
onPressed: () {
int indexOf = _lookUpPicture!(_picture);
Picture newPicture = Picture(
_picture!.id,
_picture!.symbolId,
_comment,
_picture!.dateTime,
_picture!.filePath,
_picture!.cloudPath);
_modifyPicture!(indexOf, newPicture);
Navigator.popUntil(
context, ModalRoute.withName('/displaySymbol'));
},
),
],
),
);
}
// 画像削除(確認ダイアログ)
void _removePictureDialog(BuildContext context) {
showDialog(
context: context,
builder: (BuildContext context) => AlertDialog(
title: const Text('確認'),
content: const Text('削除してもよろしいですか?'),
actions: <Widget>[
TextButton(
child: const Text('いいえ'),
onPressed: () {
Navigator.pop(context);
},
),
TextButton(
child: const Text('はい(削除)'),
onPressed: () {
_removePicture!(_picture);
Navigator.popUntil(
context, ModalRoute.withName('/displaySymbol'));
},
),
],
),
);
}
}