質問編集履歴

3

追記

2021/01/23 14:46

投稿

narururu
narururu

スコア170

test CHANGED
File without changes
test CHANGED
@@ -237,3 +237,251 @@
237
237
  以上、どなたか教えてくださると助かります。
238
238
 
239
239
  お願いいたします。
240
+
241
+
242
+
243
+
244
+
245
+ ## 追記
246
+
247
+ 修正後のコード
248
+
249
+ ```ここに言語を入力
250
+
251
+ //入力画面
252
+
253
+ import 'package:flutter/material.dart';
254
+
255
+
256
+
257
+ void main() {
258
+
259
+ runApp(MyApp());
260
+
261
+ }
262
+
263
+
264
+
265
+ class MyApp extends StatelessWidget {
266
+
267
+ String name;
268
+
269
+
270
+
271
+ @override
272
+
273
+ Widget build(BuildContext context) {
274
+
275
+ return MaterialApp(
276
+
277
+ theme: ThemeData(
278
+
279
+ primarySwatch: Colors.blue,
280
+
281
+ visualDensity: VisualDensity.adaptivePlatformDensity,
282
+
283
+ ),
284
+
285
+ home: Scaffold(
286
+
287
+ appBar: AppBar(
288
+
289
+ title: Text('入力画面'),
290
+
291
+ ),
292
+
293
+ body: Center(
294
+
295
+ child: Column(
296
+
297
+ mainAxisAlignment: MainAxisAlignment.center,
298
+
299
+ children: [
300
+
301
+ TextField(
302
+
303
+ onChanged: (value) {
304
+
305
+ setState((){
306
+
307
+ name = value;
308
+
309
+ });
310
+
311
+ },
312
+
313
+ decoration: InputDecoration(
314
+
315
+ hintText: 'ここに入力した値を次の画面に渡したい'
316
+
317
+ ),
318
+
319
+ ),
320
+
321
+ TextField(
322
+
323
+ decoration: InputDecoration(
324
+
325
+ hintText: 'ここに入力した値を次の画面に渡したい'
326
+
327
+ ),
328
+
329
+ ),
330
+
331
+ RaisedButton(
332
+
333
+ child: Text('確認画面へ'),
334
+
335
+ onPressed: (){
336
+
337
+ Navigator.push(
338
+
339
+ context,
340
+
341
+ MaterialPageRoute(builder: (context) => Scaffold(
342
+
343
+ appBar: AppBar(
344
+
345
+ title: Text('確認画面'),
346
+
347
+ ),
348
+
349
+ body: Center(
350
+
351
+ child: Column(
352
+
353
+ mainAxisAlignment: MainAxisAlignment.center,
354
+
355
+ children: [
356
+
357
+ Text(name),
358
+
359
+ Text(name),
360
+
361
+ ],
362
+
363
+ ),
364
+
365
+ ),
366
+
367
+ ),
368
+
369
+ ),
370
+
371
+ );
372
+
373
+ }
374
+
375
+ ),
376
+
377
+ ],
378
+
379
+ ),
380
+
381
+ ),
382
+
383
+ )
384
+
385
+ );
386
+
387
+ }
388
+
389
+ }
390
+
391
+
392
+
393
+ //確認画面
394
+
395
+ class NextPage extends StatelessWidget{
396
+
397
+
398
+
399
+ @override
400
+
401
+ Widget build(BuildContext context) {
402
+
403
+ return MaterialApp(
404
+
405
+ theme: ThemeData(
406
+
407
+ primarySwatch: Colors.blue,
408
+
409
+ visualDensity: VisualDensity.adaptivePlatformDensity,
410
+
411
+ ),
412
+
413
+ home: NextPage2(),
414
+
415
+ );
416
+
417
+ }
418
+
419
+ }
420
+
421
+
422
+
423
+ class NextPage2 extends StatelessWidget{
424
+
425
+ NextPage2({this.name});
426
+
427
+ final String name;
428
+
429
+
430
+
431
+ @override
432
+
433
+ Widget build(BuildContext context){
434
+
435
+ return Scaffold(
436
+
437
+ appBar: AppBar(
438
+
439
+ title: Text('確認画面'),
440
+
441
+ ),
442
+
443
+ body: Center(
444
+
445
+ child: Column(
446
+
447
+ mainAxisAlignment: MainAxisAlignment.center,
448
+
449
+ children: [
450
+
451
+ Text(name),
452
+
453
+ Text(name),
454
+
455
+ ],
456
+
457
+ ),
458
+
459
+ ),
460
+
461
+ );
462
+
463
+ }
464
+
465
+ }
466
+
467
+ ```
468
+
469
+
470
+
471
+ エラー
472
+
473
+ ```ここに言語を入力
474
+
475
+ lib/main.dart:28:21: Error: The method 'setState' isn't defined for the class 'MyApp'.
476
+
477
+ - 'MyApp' is from 'package:test20210124/main.dart' ('lib/main.dart').
478
+
479
+ Try correcting the name to the name of an existing method, or defining a method named 'setState'.
480
+
481
+ setState((){
482
+
483
+ ^^^^^^^^
484
+
485
+
486
+
487
+ ```

2

修正

2021/01/23 14:46

投稿

narururu
narururu

スコア170

test CHANGED
File without changes
test CHANGED
@@ -158,7 +158,35 @@
158
158
 
159
159
  class NextPage extends StatelessWidget{
160
160
 
161
+
162
+
163
+ @override
164
+
165
+ Widget build(BuildContext context) {
166
+
167
+ return MaterialApp(
168
+
169
+ theme: ThemeData(
170
+
171
+ primarySwatch: Colors.blue,
172
+
173
+ visualDensity: VisualDensity.adaptivePlatformDensity,
174
+
175
+ ),
176
+
177
+ home: NextPage2(),
178
+
179
+ );
180
+
181
+ }
182
+
183
+ }
184
+
185
+
186
+
187
+ class NextPage2 extends StatelessWidget{
188
+
161
- NextPage({this.name});
189
+ NextPage2({this.name});
162
190
 
163
191
  final String name;
164
192
 
@@ -166,45 +194,33 @@
166
194
 
167
195
  @override
168
196
 
169
- Widget build(BuildContext context) {
197
+ Widget build(BuildContext context){
170
-
198
+
171
- return MaterialApp(
199
+ return Scaffold(
200
+
172
-
201
+ appBar: AppBar(
202
+
203
+ title: Text('確認画面'),
204
+
205
+ ),
206
+
207
+ body: Center(
208
+
173
- theme: ThemeData(
209
+ child: Column(
174
-
175
- primarySwatch: Colors.blue,
210
+
176
-
177
- visualDensity: VisualDensity.adaptivePlatformDensity,
211
+ mainAxisAlignment: MainAxisAlignment.center,
212
+
213
+ children: [
214
+
215
+ Text(name),
216
+
217
+ Text(name),
218
+
219
+ ],
178
220
 
179
221
  ),
180
222
 
181
- home: Scaffold(
182
-
183
- appBar: AppBar(
184
-
185
- title: Text('確認画面'),
186
-
187
- ),
223
+ ),
188
-
189
- body: Center(
190
-
191
- child: Column(
192
-
193
- mainAxisAlignment: MainAxisAlignment.center,
194
-
195
- children: [
196
-
197
- Text(name),
198
-
199
- Text(name),
200
-
201
- ],
202
-
203
- ),
204
-
205
- ),
206
-
207
- )
208
224
 
209
225
  );
210
226
 

1

追記

2021/01/23 09:40

投稿

narururu
narururu

スコア170

test CHANGED
File without changes
test CHANGED
@@ -18,6 +18,24 @@
18
18
 
19
19
 
20
20
 
21
+ 実行ボタンを押すと下記エラーが表示される。
22
+
23
+ ```ここに言語を入力
24
+
25
+ lib/main.dart:28:21: Error: The method 'setState' isn't defined for the class 'MyApp'.
26
+
27
+ - 'MyApp' is from 'package:test20210123/main.dart' ('lib/main.dart').
28
+
29
+ Try correcting the name to the name of an existing method, or defining a method named 'setState'.
30
+
31
+ setState((){
32
+
33
+ ^^^^^^^^
34
+
35
+ ```
36
+
37
+
38
+
21
39
  ## コード
22
40
 
23
41
  ```ここに言語を入力
@@ -38,6 +56,8 @@
38
56
 
39
57
  class MyApp extends StatelessWidget {
40
58
 
59
+ String name;
60
+
41
61
 
42
62
 
43
63
  @override
@@ -46,75 +66,145 @@
46
66
 
47
67
  return MaterialApp(
48
68
 
49
- theme: ThemeData(
69
+ theme: ThemeData(
50
-
70
+
51
- primarySwatch: Colors.blue,
71
+ primarySwatch: Colors.blue,
52
-
72
+
53
- visualDensity: VisualDensity.adaptivePlatformDensity,
73
+ visualDensity: VisualDensity.adaptivePlatformDensity,
54
-
55
- ),
56
-
57
- home: Scaffold(
58
-
59
- appBar: AppBar(
60
-
61
- title: Text('入力画面'),
62
74
 
63
75
  ),
64
76
 
77
+ home: Scaffold(
78
+
79
+ appBar: AppBar(
80
+
81
+ title: Text('入力画面'),
82
+
83
+ ),
84
+
65
- body: Center(
85
+ body: Center(
66
-
86
+
67
- child: Column(
87
+ child: Column(
68
-
88
+
69
- mainAxisAlignment: MainAxisAlignment.center,
89
+ mainAxisAlignment: MainAxisAlignment.center,
70
-
90
+
71
- children: [
91
+ children: [
72
-
92
+
73
- TextField(
93
+ TextField(
94
+
74
-
95
+ onChanged: (value) {
96
+
97
+ setState((){
98
+
99
+ name = value;
100
+
101
+ });
102
+
103
+ },
104
+
75
- decoration: InputDecoration(
105
+ decoration: InputDecoration(
76
-
106
+
77
- hintText: 'ここに入力した値を次の画面に渡したい'
107
+ hintText: 'ここに入力した値を次の画面に渡したい'
108
+
109
+ ),
110
+
111
+ ),
112
+
113
+ TextField(
114
+
115
+ decoration: InputDecoration(
116
+
117
+ hintText: 'ここに入力した値を次の画面に渡したい'
118
+
119
+ ),
120
+
121
+ ),
122
+
123
+ RaisedButton(
124
+
125
+ child: Text('確認画面へ'),
126
+
127
+ onPressed: (){
128
+
129
+ Navigator.push(
130
+
131
+ context,
132
+
133
+ MaterialPageRoute(builder: (context) => NextPage(name: name)),
134
+
135
+ );
136
+
137
+ }
138
+
139
+ ),
140
+
141
+ ],
78
142
 
79
143
  ),
80
144
 
81
145
  ),
82
146
 
147
+ )
148
+
149
+ );
150
+
151
+ }
152
+
153
+ }
154
+
155
+
156
+
157
+ //確認画面
158
+
159
+ class NextPage extends StatelessWidget{
160
+
161
+ NextPage({this.name});
162
+
163
+ final String name;
164
+
165
+
166
+
83
- TextField(
167
+ @override
168
+
84
-
169
+ Widget build(BuildContext context) {
170
+
85
- decoration: InputDecoration(
171
+ return MaterialApp(
172
+
86
-
173
+ theme: ThemeData(
174
+
175
+ primarySwatch: Colors.blue,
176
+
87
- hintText: 'ここに入力した値を次の画面に渡したい'
177
+ visualDensity: VisualDensity.adaptivePlatformDensity,
88
-
178
+
89
- ),
179
+ ),
180
+
181
+ home: Scaffold(
182
+
183
+ appBar: AppBar(
184
+
185
+ title: Text('確認画面'),
186
+
187
+ ),
188
+
189
+ body: Center(
190
+
191
+ child: Column(
192
+
193
+ mainAxisAlignment: MainAxisAlignment.center,
194
+
195
+ children: [
196
+
197
+ Text(name),
198
+
199
+ Text(name),
200
+
201
+ ],
90
202
 
91
203
  ),
92
204
 
93
- RaisedButton(
94
-
95
- child: Text('確認画面へ'),
96
-
97
- onPressed: (){
98
-
99
- Navigator.push(
100
-
101
- context,
102
-
103
- MaterialPageRoute(builder: (context) => NextPage()),
104
-
105
- );
106
-
107
- }
108
-
109
- ),
205
+ ),
110
-
111
- ],
206
+
112
-
113
- ),
114
-
115
- ),
116
-
117
- )
207
+ )
118
208
 
119
209
  );
120
210
 
@@ -122,60 +212,6 @@
122
212
 
123
213
  }
124
214
 
125
-
126
-
127
- //確認画面
128
-
129
- class NextPage extends StatelessWidget{
130
-
131
- @override
132
-
133
- Widget build(BuildContext context) {
134
-
135
- return MaterialApp(
136
-
137
- theme: ThemeData(
138
-
139
- primarySwatch: Colors.blue,
140
-
141
- visualDensity: VisualDensity.adaptivePlatformDensity,
142
-
143
- ),
144
-
145
- home: Scaffold(
146
-
147
- appBar: AppBar(
148
-
149
- title: Text('確認画面'),
150
-
151
- ),
152
-
153
- body: Center(
154
-
155
- child: Column(
156
-
157
- mainAxisAlignment: MainAxisAlignment.center,
158
-
159
- children: [
160
-
161
- Text('ここに入力した値が反映させたい'),
162
-
163
- Text('ここに入力した値が反映させたい'),
164
-
165
- ],
166
-
167
- ),
168
-
169
- ),
170
-
171
- )
172
-
173
- );
174
-
175
- }
176
-
177
- }
178
-
179
215
  ```
180
216
 
181
217