回答編集履歴

1

コードを追記

2021/01/23 15:33

投稿

hiroshihorie
hiroshihorie

スコア192

test CHANGED
@@ -43,3 +43,179 @@
43
43
  }
44
44
 
45
45
  ```
46
+
47
+
48
+
49
+ 追記(検証済み)
50
+
51
+ ```dart
52
+
53
+ //入力画面
54
+
55
+ import 'package:flutter/material.dart';
56
+
57
+
58
+
59
+ void main() {
60
+
61
+ runApp(MyApp());
62
+
63
+ }
64
+
65
+
66
+
67
+ class MyApp extends StatelessWidget {
68
+
69
+ @override
70
+
71
+ Widget build(BuildContext context) {
72
+
73
+ return MaterialApp(
74
+
75
+ theme: ThemeData(
76
+
77
+ primarySwatch: Colors.blue,
78
+
79
+ visualDensity: VisualDensity.adaptivePlatformDensity,
80
+
81
+ ),
82
+
83
+ home: HomePage(),
84
+
85
+ );
86
+
87
+ }
88
+
89
+ }
90
+
91
+
92
+
93
+ class HomePage extends StatefulWidget {
94
+
95
+ @override
96
+
97
+ createState() => HomePageState();
98
+
99
+ }
100
+
101
+
102
+
103
+ class HomePageState extends State<HomePage> {
104
+
105
+ //
106
+
107
+ String name;
108
+
109
+
110
+
111
+ @override
112
+
113
+ Widget build(BuildContext context) => Scaffold(
114
+
115
+ appBar: AppBar(
116
+
117
+ title: Text('入力画面'),
118
+
119
+ ),
120
+
121
+ body: Center(
122
+
123
+ child: Column(
124
+
125
+ mainAxisAlignment: MainAxisAlignment.center,
126
+
127
+ children: [
128
+
129
+ TextField(
130
+
131
+ onChanged: (value) {
132
+
133
+ setState(() {
134
+
135
+ name = value;
136
+
137
+ });
138
+
139
+ },
140
+
141
+ decoration: InputDecoration(hintText: 'ここに入力した値を次の画面に渡したい'),
142
+
143
+ ),
144
+
145
+ RaisedButton(
146
+
147
+ child: Text('確認画面へ'),
148
+
149
+ onPressed: () {
150
+
151
+ Navigator.push(
152
+
153
+ context,
154
+
155
+ MaterialPageRoute(builder: (context) => NextPage(name: name)),
156
+
157
+ );
158
+
159
+ }),
160
+
161
+ ],
162
+
163
+ ),
164
+
165
+ ),
166
+
167
+ );
168
+
169
+ }
170
+
171
+
172
+
173
+ class NextPage extends StatelessWidget {
174
+
175
+ //
176
+
177
+ final String name;
178
+
179
+
180
+
181
+ NextPage({
182
+
183
+ this.name,
184
+
185
+ });
186
+
187
+
188
+
189
+ @override
190
+
191
+ Widget build(BuildContext context) => Scaffold(
192
+
193
+ appBar: AppBar(
194
+
195
+ title: Text('確認画面'),
196
+
197
+ ),
198
+
199
+ body: Center(
200
+
201
+ child: Column(
202
+
203
+ mainAxisAlignment: MainAxisAlignment.center,
204
+
205
+ children: [
206
+
207
+ Text(name),
208
+
209
+ ],
210
+
211
+ ),
212
+
213
+ ),
214
+
215
+ );
216
+
217
+ }
218
+
219
+
220
+
221
+ ```