回答編集履歴
1
追記
test
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
推測ですが、その方法はTabBarViewなどの画面切り替えでしか使えず、Navigatorを使用した画面遷移ではできないようです。
|
2
2
|
|
3
|
+
ただ、以下のようにすれば実現可能です。
|
4
|
+
|
3
5
|
|
4
6
|
|
5
7
|
```
|
@@ -99,3 +101,523 @@
|
|
99
101
|
|
100
102
|
|
101
103
|
[ここ](https://stackoverflow.com/questions/51195114/flutter-persistent-state-between-pages)を参考にしてください。
|
104
|
+
|
105
|
+
|
106
|
+
|
107
|
+
また、すごい雑ですが、以下のソースをまるごとコピーして、[DartPad](https://dartpad.dev/flutter)に張り付けて実行してみてください。
|
108
|
+
|
109
|
+
```
|
110
|
+
|
111
|
+
import 'package:flutter/material.dart';
|
112
|
+
|
113
|
+
|
114
|
+
|
115
|
+
void main() => runApp(new MyApp());
|
116
|
+
|
117
|
+
PageStorageKey mykey = new PageStorageKey("testkey");
|
118
|
+
|
119
|
+
final PageStorageBucket _bucket = new PageStorageBucket();
|
120
|
+
|
121
|
+
|
122
|
+
|
123
|
+
class MyApp extends StatelessWidget{
|
124
|
+
|
125
|
+
final title = 'Flutter サンプル';
|
126
|
+
|
127
|
+
|
128
|
+
|
129
|
+
@override
|
130
|
+
|
131
|
+
Widget build(BuildContext context){
|
132
|
+
|
133
|
+
return MaterialApp(
|
134
|
+
|
135
|
+
title: 'Flutter Demo',
|
136
|
+
|
137
|
+
home: PageStorage(
|
138
|
+
|
139
|
+
bucket: _bucket,
|
140
|
+
|
141
|
+
key: mykey,
|
142
|
+
|
143
|
+
child: MyHomePage(
|
144
|
+
|
145
|
+
title:this.title,
|
146
|
+
|
147
|
+
),
|
148
|
+
|
149
|
+
),
|
150
|
+
|
151
|
+
);
|
152
|
+
|
153
|
+
}
|
154
|
+
|
155
|
+
}
|
156
|
+
|
157
|
+
|
158
|
+
|
159
|
+
class MyHomePage extends StatefulWidget{
|
160
|
+
|
161
|
+
MyHomePage({Key key, this.title}) : super(key: key);
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
final String title;
|
166
|
+
|
167
|
+
|
168
|
+
|
169
|
+
@override
|
170
|
+
|
171
|
+
_MyHomePageState createState() => new _MyHomePageState();
|
172
|
+
|
173
|
+
}
|
174
|
+
|
175
|
+
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
//インスタンスからウィジェットを作る
|
180
|
+
|
181
|
+
|
182
|
+
|
183
|
+
class _MyHomePageState extends State<MyHomePage>{
|
184
|
+
|
185
|
+
|
186
|
+
|
187
|
+
|
188
|
+
|
189
|
+
bool _checked1 = false;
|
190
|
+
|
191
|
+
bool result;
|
192
|
+
|
193
|
+
|
194
|
+
|
195
|
+
|
196
|
+
|
197
|
+
@override
|
198
|
+
|
199
|
+
|
200
|
+
|
201
|
+
Widget build(BuildContext context){
|
202
|
+
|
203
|
+
|
204
|
+
|
205
|
+
return Scaffold(
|
206
|
+
|
207
|
+
|
208
|
+
|
209
|
+
appBar: AppBar(
|
210
|
+
|
211
|
+
title: Text('課題管理App(曜日別)')
|
212
|
+
|
213
|
+
),
|
214
|
+
|
215
|
+
body: Container(
|
216
|
+
|
217
|
+
|
218
|
+
|
219
|
+
child: ListView(
|
220
|
+
|
221
|
+
children: <Widget>[
|
222
|
+
|
223
|
+
|
224
|
+
|
225
|
+
ListTile(
|
226
|
+
|
227
|
+
|
228
|
+
|
229
|
+
title: Text('月曜締め切り'),
|
230
|
+
|
231
|
+
trailing: Icon(Icons.arrow_forward_ios),
|
232
|
+
|
233
|
+
|
234
|
+
|
235
|
+
onTap: (){
|
236
|
+
|
237
|
+
Navigator.push(
|
238
|
+
|
239
|
+
context,
|
240
|
+
|
241
|
+
MaterialPageRoute(
|
242
|
+
|
243
|
+
builder: (context) => MondayPage(),
|
244
|
+
|
245
|
+
)
|
246
|
+
|
247
|
+
|
248
|
+
|
249
|
+
);
|
250
|
+
|
251
|
+
|
252
|
+
|
253
|
+
},
|
254
|
+
|
255
|
+
|
256
|
+
|
257
|
+
),
|
258
|
+
|
259
|
+
ListTile(
|
260
|
+
|
261
|
+
title: Text('金曜締め切り'),
|
262
|
+
|
263
|
+
trailing: Icon(Icons.arrow_forward_ios),
|
264
|
+
|
265
|
+
onTap: (){
|
266
|
+
|
267
|
+
Navigator.push(
|
268
|
+
|
269
|
+
context,
|
270
|
+
|
271
|
+
MaterialPageRoute(
|
272
|
+
|
273
|
+
builder: (context) => MyHomePageF(),
|
274
|
+
|
275
|
+
)
|
276
|
+
|
277
|
+
);
|
278
|
+
|
279
|
+
},
|
280
|
+
|
281
|
+
),
|
282
|
+
|
283
|
+
Text('備考欄'),
|
284
|
+
|
285
|
+
TextField(
|
286
|
+
|
287
|
+
autofocus: true,
|
288
|
+
|
289
|
+
decoration: InputDecoration(
|
290
|
+
|
291
|
+
hintText: '臨時課題があれば記入'
|
292
|
+
|
293
|
+
),
|
294
|
+
|
295
|
+
|
296
|
+
|
297
|
+
),
|
298
|
+
|
299
|
+
Row(
|
300
|
+
|
301
|
+
children: <Widget>[
|
302
|
+
|
303
|
+
Checkbox(
|
304
|
+
|
305
|
+
value: _checked1,
|
306
|
+
|
307
|
+
onChanged: (bool value) {
|
308
|
+
|
309
|
+
setState(() {
|
310
|
+
|
311
|
+
_checked1 = value;
|
312
|
+
|
313
|
+
});
|
314
|
+
|
315
|
+
},
|
316
|
+
|
317
|
+
),
|
318
|
+
|
319
|
+
|
320
|
+
|
321
|
+
|
322
|
+
|
323
|
+
Text('全課題クリア!')
|
324
|
+
|
325
|
+
],
|
326
|
+
|
327
|
+
)
|
328
|
+
|
329
|
+
|
330
|
+
|
331
|
+
|
332
|
+
|
333
|
+
],
|
334
|
+
|
335
|
+
),
|
336
|
+
|
337
|
+
|
338
|
+
|
339
|
+
)
|
340
|
+
|
341
|
+
|
342
|
+
|
343
|
+
);
|
344
|
+
|
345
|
+
}
|
346
|
+
|
347
|
+
|
348
|
+
|
349
|
+
}
|
350
|
+
|
351
|
+
|
352
|
+
|
353
|
+
class MyHomePageF extends StatefulWidget{
|
354
|
+
|
355
|
+
|
356
|
+
|
357
|
+
@override
|
358
|
+
|
359
|
+
|
360
|
+
|
361
|
+
State<StatefulWidget> createState() {
|
362
|
+
|
363
|
+
return _MyHomePageFState();
|
364
|
+
|
365
|
+
}
|
366
|
+
|
367
|
+
}
|
368
|
+
|
369
|
+
class FridayPageParams {
|
370
|
+
|
371
|
+
bool _checked1= false ;
|
372
|
+
|
373
|
+
}
|
374
|
+
|
375
|
+
|
376
|
+
|
377
|
+
class _MyHomePageFState extends State<MyHomePageF>{
|
378
|
+
|
379
|
+
FridayPageParams _params;
|
380
|
+
|
381
|
+
|
382
|
+
|
383
|
+
@override
|
384
|
+
|
385
|
+
void didChangeDependencies() { // このメソッドをオーバーライド
|
386
|
+
|
387
|
+
FridayPageParams p = _bucket.readState(context, identifier: ValueKey(mykey));
|
388
|
+
|
389
|
+
print(p);
|
390
|
+
|
391
|
+
if (p != null) {
|
392
|
+
|
393
|
+
_params = p;
|
394
|
+
|
395
|
+
} else {
|
396
|
+
|
397
|
+
_params = FridayPageParams();
|
398
|
+
|
399
|
+
print(_params._checked1);
|
400
|
+
|
401
|
+
}
|
402
|
+
|
403
|
+
super.didChangeDependencies();
|
404
|
+
|
405
|
+
}
|
406
|
+
|
407
|
+
|
408
|
+
|
409
|
+
Widget build(BuildContext context){
|
410
|
+
|
411
|
+
return Scaffold(
|
412
|
+
|
413
|
+
appBar: AppBar(
|
414
|
+
|
415
|
+
title: Text('金曜締め切り'),
|
416
|
+
|
417
|
+
),
|
418
|
+
|
419
|
+
|
420
|
+
|
421
|
+
body: Column(
|
422
|
+
|
423
|
+
mainAxisAlignment: MainAxisAlignment.start,
|
424
|
+
|
425
|
+
crossAxisAlignment: CrossAxisAlignment.start,
|
426
|
+
|
427
|
+
children: <Widget>[
|
428
|
+
|
429
|
+
Text(
|
430
|
+
|
431
|
+
'応用数学 ',
|
432
|
+
|
433
|
+
style: TextStyle(fontSize: 16.0),
|
434
|
+
|
435
|
+
),
|
436
|
+
|
437
|
+
|
438
|
+
|
439
|
+
Row(
|
440
|
+
|
441
|
+
|
442
|
+
|
443
|
+
children: <Widget>[
|
444
|
+
|
445
|
+
|
446
|
+
|
447
|
+
Checkbox(
|
448
|
+
|
449
|
+
value: _params._checked1,
|
450
|
+
|
451
|
+
onChanged: (bool value) {
|
452
|
+
|
453
|
+
setState(() {
|
454
|
+
|
455
|
+
_params._checked1 = value;
|
456
|
+
|
457
|
+
});
|
458
|
+
|
459
|
+
_bucket.writeState(context, _params, identifier: ValueKey(mykey));
|
460
|
+
|
461
|
+
},
|
462
|
+
|
463
|
+
),
|
464
|
+
|
465
|
+
Text('提出済み',)
|
466
|
+
|
467
|
+
|
468
|
+
|
469
|
+
],
|
470
|
+
|
471
|
+
),
|
472
|
+
|
473
|
+
|
474
|
+
|
475
|
+
Text('備考欄'),
|
476
|
+
|
477
|
+
TextField(
|
478
|
+
|
479
|
+
autofocus: true,
|
480
|
+
|
481
|
+
decoration: InputDecoration(
|
482
|
+
|
483
|
+
hintText: '特記事項があれば記入'
|
484
|
+
|
485
|
+
),
|
486
|
+
|
487
|
+
),
|
488
|
+
|
489
|
+
RaisedButton(
|
490
|
+
|
491
|
+
onPressed: (){
|
492
|
+
|
493
|
+
Navigator.pop(context,);
|
494
|
+
|
495
|
+
|
496
|
+
|
497
|
+
},
|
498
|
+
|
499
|
+
child: Center(child: Text('戻る')),
|
500
|
+
|
501
|
+
)
|
502
|
+
|
503
|
+
],
|
504
|
+
|
505
|
+
|
506
|
+
|
507
|
+
) ,
|
508
|
+
|
509
|
+
);
|
510
|
+
|
511
|
+
|
512
|
+
|
513
|
+
|
514
|
+
|
515
|
+
|
516
|
+
|
517
|
+
|
518
|
+
|
519
|
+
}
|
520
|
+
|
521
|
+
|
522
|
+
|
523
|
+
|
524
|
+
|
525
|
+
|
526
|
+
|
527
|
+
}
|
528
|
+
|
529
|
+
|
530
|
+
|
531
|
+
class MondayPage extends StatelessWidget{
|
532
|
+
|
533
|
+
|
534
|
+
|
535
|
+
@override
|
536
|
+
|
537
|
+
Widget build(BuildContext context) {
|
538
|
+
|
539
|
+
return
|
540
|
+
|
541
|
+
new MyHomePageM(
|
542
|
+
|
543
|
+
|
544
|
+
|
545
|
+
|
546
|
+
|
547
|
+
|
548
|
+
|
549
|
+
|
550
|
+
|
551
|
+
);
|
552
|
+
|
553
|
+
}
|
554
|
+
|
555
|
+
}
|
556
|
+
|
557
|
+
|
558
|
+
|
559
|
+
class MyHomePageM extends StatefulWidget{
|
560
|
+
|
561
|
+
MyHomePageM({this.title}): super();
|
562
|
+
|
563
|
+
|
564
|
+
|
565
|
+
final String title;
|
566
|
+
|
567
|
+
|
568
|
+
|
569
|
+
@override
|
570
|
+
|
571
|
+
_MyHomePageMState createState() => new _MyHomePageMState();
|
572
|
+
|
573
|
+
}
|
574
|
+
|
575
|
+
|
576
|
+
|
577
|
+
|
578
|
+
|
579
|
+
//インスタンスからウィジェットを作る
|
580
|
+
|
581
|
+
|
582
|
+
|
583
|
+
class _MyHomePageMState extends State<MyHomePageM>{
|
584
|
+
|
585
|
+
|
586
|
+
|
587
|
+
|
588
|
+
|
589
|
+
@override
|
590
|
+
|
591
|
+
|
592
|
+
|
593
|
+
Widget build(BuildContext context){
|
594
|
+
|
595
|
+
return Scaffold(
|
596
|
+
|
597
|
+
appBar: AppBar(
|
598
|
+
|
599
|
+
title: Text('月曜締め切り'),
|
600
|
+
|
601
|
+
),
|
602
|
+
|
603
|
+
body: Text('課題の入力')
|
604
|
+
|
605
|
+
|
606
|
+
|
607
|
+
);
|
608
|
+
|
609
|
+
|
610
|
+
|
611
|
+
|
612
|
+
|
613
|
+
}
|
614
|
+
|
615
|
+
|
616
|
+
|
617
|
+
|
618
|
+
|
619
|
+
|
620
|
+
|
621
|
+
}
|
622
|
+
|
623
|
+
```
|