質問編集履歴
1
修正
title
CHANGED
File without changes
|
body
CHANGED
@@ -1,124 +1,57 @@
|
|
1
1
|
## 解決したい課題
|
2
|
-
画像
|
2
|
+
画像を表示させたいです。
|
3
3
|
|
4
4
|
## 現状
|
5
|
-
画像をギャラリーから選択すると画面が真っ暗になり操作できなくなってしまいます。
|
6
|
-
|
5
|
+
何も表示されません。
|
7
|
-

|
8
|
-

|
9
|
-

|
10
6
|
|
11
7
|
## コード
|
12
8
|
```ここに言語を入力
|
13
|
-
import 'dart:io';
|
14
9
|
import 'package:flutter/material.dart';
|
15
|
-
import 'package:image_picker/image_picker.dart';
|
16
10
|
|
11
|
+
void main() {
|
17
|
-
|
12
|
+
runApp(MyApp());
|
13
|
+
}
|
18
14
|
|
19
15
|
class MyApp extends StatelessWidget {
|
20
16
|
@override
|
21
17
|
Widget build(BuildContext context) {
|
22
18
|
return MaterialApp(
|
23
|
-
theme: ThemeData(
|
24
|
-
primarySwatch: Colors.blue,
|
25
|
-
),
|
26
|
-
home: MyAppPage(),
|
27
|
-
);
|
28
|
-
}
|
29
|
-
}
|
30
|
-
|
31
|
-
class MyAppPage extends StatefulWidget {
|
32
|
-
ImagePage createState() => ImagePage();
|
33
|
-
}
|
34
|
-
|
35
|
-
class ImagePage extends State<MyAppPage> {
|
36
|
-
File imageFile;
|
37
|
-
final picker = ImagePicker();
|
38
|
-
|
39
|
-
Future getImageFromGallery() async {
|
40
|
-
final pickedFile = await picker.getImage(source: ImageSource.gallery);
|
41
|
-
|
42
|
-
setState(() {
|
43
|
-
imageFile = File(pickedFile.path);
|
44
|
-
});
|
45
|
-
Navigator.of(context).pop();
|
46
|
-
}
|
47
|
-
|
48
|
-
@override
|
49
|
-
Widget build(BuildContext context) {
|
50
|
-
|
19
|
+
home: Scaffold(
|
51
|
-
|
20
|
+
appBar: AppBar(
|
21
|
+
backgroundColor: Colors.blue,
|
52
|
-
|
22
|
+
title: Text("TEST"),
|
53
|
-
),
|
54
|
-
body: Center(
|
55
|
-
child: Column(
|
56
|
-
mainAxisAlignment: MainAxisAlignment.start,
|
57
|
-
children: [
|
58
|
-
_imageClass(),
|
59
|
-
Text('画像を選択'),
|
60
|
-
RaisedButton(
|
61
|
-
child: Text('次へ'),
|
62
|
-
onPressed: () {
|
63
|
-
Navigator.push(
|
64
|
-
context,
|
65
|
-
MaterialPageRoute(builder: (context) => NextPage()),
|
66
|
-
);
|
67
|
-
}
|
68
|
-
),
|
69
|
-
],
|
70
23
|
),
|
24
|
+
body: Center(
|
25
|
+
child: Column(mainAxisAlignment: MainAxisAlignment.center, children: [
|
26
|
+
Image.asset('images/test.PNG'),
|
27
|
+
]),
|
28
|
+
),
|
71
29
|
),
|
72
30
|
);
|
73
31
|
}
|
74
|
-
Widget _imageClass() {
|
75
|
-
if (imageFile == null) {
|
76
|
-
return GestureDetector(
|
77
|
-
child: Container(
|
78
|
-
margin: EdgeInsets.only(top: 30),
|
79
|
-
decoration: BoxDecoration(
|
80
|
-
color: Colors.grey,
|
81
|
-
),
|
82
|
-
width: 100,
|
83
|
-
height: 100,
|
84
|
-
),
|
85
|
-
onTap: () {
|
86
|
-
getImageFromGallery();
|
87
|
-
},
|
88
|
-
);
|
89
|
-
} else {
|
90
|
-
Container(
|
91
|
-
margin: EdgeInsets.only(top: 30),
|
92
|
-
width: 100,
|
93
|
-
height: 100,
|
94
|
-
child: Image.file(imageFile),
|
95
|
-
);
|
96
|
-
}
|
97
|
-
}
|
98
32
|
}
|
99
33
|
|
100
|
-
class NextPage extends StatefulWidget {
|
101
|
-
ConfirmPage createState() => ConfirmPage();
|
102
|
-
|
34
|
+
```
|
103
|
-
class ConfirmPage extends State<NextPage> {
|
104
35
|
|
105
|
-
@override
|
106
|
-
Widget build(BuildContext context) =>
|
107
|
-
Scaffold(
|
108
|
-
appBar: AppBar(
|
109
|
-
title: Text('画像確認画面'),
|
110
|
-
|
36
|
+
##
|
111
|
-
body: Center(
|
112
|
-
child: Container(
|
113
|
-
|
37
|
+
imageフォルダの中にtest.PNGを格納しています。
|
114
|
-
|
38
|
+
pubspec.yamlに下記コードを入れています。
|
39
|
+
```ここに言語を入力
|
40
|
+
flutter:
|
115
|
-
|
41
|
+
assets:
|
116
|
-
),
|
117
|
-
|
42
|
+
- images/test.PNG
|
118
|
-
}
|
119
43
|
```
|
120
44
|
|
45
|
+
## エラー内容
|
46
|
+
```ここに言語を入力
|
47
|
+
Error detected in pubspec.yaml:
|
48
|
+
No file or variants found for asset: images/test.PNG.
|
49
|
+
```
|
50
|
+
|
121
51
|
##
|
122
|
-
|
52
|
+
エラー内容を確認しましたが、pubspec.yamlに間違いが見つかりません。
|
53
|
+
pub getやpub upgradeはしました。
|
123
|
-
|
54
|
+
また、flutter cleanも試しました。
|
55
|
+
しかし、エラーは改善されません。
|
56
|
+
|
124
|
-
|
57
|
+
以上、何か不備がありましたらご教示お願いいたします。
|