質問編集履歴
1
該当ソースコードを全文記載しました。
title
CHANGED
File without changes
|
body
CHANGED
@@ -2,6 +2,7 @@
|
|
2
2
|
|
3
3
|
flutter学習で画面遷移を実装しようとしています。
|
4
4
|
KboyさんのYouTube動画を見て、写経していました。
|
5
|
+
Navigate with named routesを使おうとしています。
|
5
6
|
|
6
7
|
### 発生している問題・エラーメッセージ
|
7
8
|
|
@@ -22,6 +23,14 @@
|
|
22
23
|
### 該当のソースコード
|
23
24
|
|
24
25
|
```dart
|
26
|
+
|
27
|
+
//以下、main.dart
|
28
|
+
import 'package:flutter/material.dart';
|
29
|
+
|
30
|
+
void main() {
|
31
|
+
runApp(MyApp());
|
32
|
+
}
|
33
|
+
|
25
34
|
class MyApp extends StatelessWidget {
|
26
35
|
// This widget is the root of your application.
|
27
36
|
@override
|
@@ -33,17 +42,87 @@
|
|
33
42
|
primarySwatch: Colors.blue,
|
34
43
|
|
35
44
|
),
|
36
|
-
initialRoute: '/',
|
37
|
-
routes: {
|
38
|
-
|
39
|
-
'/': (context) => MyHomePage(),
|
40
|
-
|
41
|
-
|
45
|
+
home: MyHomePage(title: 'Flutter Demo Home Page'),
|
46
|
+
);
|
42
|
-
|
47
|
+
}
|
48
|
+
}
|
43
49
|
|
50
|
+
class MyHomePage extends StatefulWidget {
|
51
|
+
MyHomePage({Key key, this.title}) : super(key: key);
|
52
|
+
|
53
|
+
|
54
|
+
|
55
|
+
final String title;
|
56
|
+
|
57
|
+
@override
|
58
|
+
_MyHomePageState createState() => _MyHomePageState();
|
59
|
+
}
|
60
|
+
|
61
|
+
class _MyHomePageState extends State<MyHomePage> {
|
62
|
+
int _counter = 0;
|
63
|
+
|
64
|
+
void _incrementCounter() {
|
65
|
+
setState(() {
|
66
|
+
|
67
|
+
_counter++;
|
68
|
+
});
|
69
|
+
}
|
70
|
+
|
71
|
+
@override
|
72
|
+
Widget build(BuildContext context) {
|
73
|
+
|
74
|
+
return Scaffold(
|
75
|
+
appBar: AppBar(
|
76
|
+
|
77
|
+
title: Text(widget.title),
|
78
|
+
),
|
79
|
+
body: Center(
|
80
|
+
|
81
|
+
child: RaisedButton(
|
82
|
+
child: Text('次へ'),
|
83
|
+
onPressed: (){
|
84
|
+
Navigator.pushNamed(context, '/next');
|
85
|
+
},
|
86
|
+
),
|
87
|
+
),
|
88
|
+
floatingActionButton: FloatingActionButton(
|
89
|
+
onPressed: _incrementCounter,
|
90
|
+
tooltip: 'Increment',
|
91
|
+
child: Icon(Icons.add),
|
92
|
+
), // This trailing comma makes auto-formatting nicer for build methods.
|
44
93
|
);
|
94
|
+
}
|
95
|
+
}
|
45
96
|
|
97
|
+
|
98
|
+
|
99
|
+
//以下、next_page.dart
|
100
|
+
import 'package:flutter/material.dart';
|
101
|
+
|
102
|
+
class NextPage extends StatelessWidget {
|
103
|
+
@override
|
104
|
+
Widget build(BuildContext context) {
|
105
|
+
// TODO: implement build
|
106
|
+
return Scaffold(
|
107
|
+
appBar: AppBar(
|
108
|
+
|
109
|
+
title: Text('次の画面'),
|
110
|
+
),
|
111
|
+
body: Container(
|
112
|
+
height: double.infinity,
|
113
|
+
color: Colors.red,
|
114
|
+
child: Center(
|
115
|
+
child: RaisedButton(
|
116
|
+
child: Text('戻る'),
|
117
|
+
onPressed: () {
|
118
|
+
Navigator.pop(context);
|
119
|
+
},
|
120
|
+
),
|
121
|
+
),
|
122
|
+
),
|
123
|
+
);
|
46
124
|
}
|
125
|
+
|
47
126
|
}
|
48
127
|
```
|
49
128
|
|