前提
Stepperウィジェットで手順画面を作ろうと思っています。
実現したいこと
要約すると
stepsプロパティの値を動的に変更できて、前ページからもらった値によって変更できるか
Providerを使ってmodelの値(現段階で考えているのはString値)を受け取り、
値渡しをしていま受け取っている値によって、
Stepperのstepsプロパティの値を変えることで
表示の中身を変えたい。
発生している問題・エラーメッセージ
強いて言うなら The argument type 'String?' can't be assigned to the parameter type 'List<Step>'.
該当のソースコード
main
1class WorkStepPage extends StatefulWidget { 2 WorkStepPage( 3 {Key? key, 4 required this.workname, 5 required this.phase, 6 required this.documentId}) 7 : super(key: key); 8 final String workname; 9 final int phase; 10 final String documentId; 11 @override 12 State<WorkStepPage> createState() => _WorkStepPageState(); 13} 14 15class _WorkStepPageState extends State<WorkStepPage> 16 with SingleTickerProviderStateMixin { 17 late int currentStep = int.parse(widget.phase.toString()); 18 19 List<Step> cleanSteps = [ 20 Step( 21 isActive: true, 22 title: Text("用具の準備"), 23 content: Container(), 24 ), 25 Step( 26 isActive: true, 27 title: Text("濡れ拭き"), 28 content: Container(), 29 ), 30 Step( 31 isActive: true, 32 title: Text("乾拭き"), 33 content: Container(), 34 ), 35 Step( 36 isActive: true, 37 title: Text("ゴミ捨て"), 38 content: Container(), 39 ), 40 Step( 41 isActive: true, 42 title: Text("用具の片付け"), 43 content: Container(), 44 ), 45 ]; 46 47 List<Step> programnSteps = [ 48 Step( 49 isActive: true, 50 title: Text("エディター起動"), 51 content: Container(), 52 ), 53 Step( 54 isActive: true, 55 title: Text("コーディング"), 56 content: Container(), 57 ), 58 Step( 59 isActive: true, 60 title: Text("ビルド"), 61 content: Container(), 62 ), 63 Step( 64 isActive: true, 65 title: Text("デバッグ"), 66 content: Container(), 67 ), 68 Step( 69 isActive: true, 70 title: Text("リファクタリング"), 71 content: Container(), 72 ), 73 ]; 74 75 76 @override 77 Widget build(BuildContext context) { 78 return ChangeNotifierProvider<WorkStepModel>( 79 create: (_) => WorkStepModel(), 80 child: Consumer<WorkStepModel>( 81 builder: (context, model, child) { 82 return Scaffold( 83 appBar: AppBar(), 84 body: Center( 85 child: Stepper( 86 steps: (model.workName), //ここを可変にしたい 87 currentStep: currentStep, 88 type: StepperType.vertical, 89 // onStepTapped: (step) { 90 // setState(() { 91 // currentStep = step; 92 // }); 93 // }, 94 onStepCancel: () { 95 setState( 96 () { 97 if (currentStep > 0) { 98 currentStep = currentStep - 1; 99 } else { 100 currentStep = 0; 101 } 102 }, 103 ); 104 }, 105 onStepContinue: () { 106 setState( 107 () { 108 if (currentStep < cleanSteps.length - 1) { 109 currentStep = currentStep + 1; 110 } else { 111 currentStep = 0; 112 } 113 }, 114 ); 115 }, 116 ), 117 ), 118 119 ); 120 }, 121 ), 122 ); 123 } 124} 125
補足情報(FW/ツールのバージョンなど)
Flutter 3.0.5
回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/10/02 23:35
2022/10/02 23:54
2022/10/03 02:37