回答編集履歴
1
Builderを使った方法について追記
test
CHANGED
@@ -155,3 +155,101 @@
|
|
155
155
|
}
|
156
156
|
|
157
157
|
```
|
158
|
+
|
159
|
+
|
160
|
+
|
161
|
+
---
|
162
|
+
|
163
|
+
|
164
|
+
|
165
|
+
**追記 :**
|
166
|
+
|
167
|
+
ボタン部分を`Builder`で囲むという方法もあります。
|
168
|
+
|
169
|
+
|
170
|
+
|
171
|
+
```dart
|
172
|
+
|
173
|
+
class CookApp extends StatelessWidget {
|
174
|
+
|
175
|
+
var titleText = 'cookapp';
|
176
|
+
|
177
|
+
|
178
|
+
|
179
|
+
@override
|
180
|
+
|
181
|
+
Widget build(BuildContext context) {
|
182
|
+
|
183
|
+
return MaterialApp(
|
184
|
+
|
185
|
+
home: Scaffold(
|
186
|
+
|
187
|
+
appBar: AppBar(
|
188
|
+
|
189
|
+
leading: Icon(Icons.menu),
|
190
|
+
|
191
|
+
title: Text('レシピ一覧'),
|
192
|
+
|
193
|
+
),
|
194
|
+
|
195
|
+
body: Container(
|
196
|
+
|
197
|
+
child: Center(
|
198
|
+
|
199
|
+
child: Column(
|
200
|
+
|
201
|
+
children: <Widget>[
|
202
|
+
|
203
|
+
Text(titleText),
|
204
|
+
|
205
|
+
// ここがポイント
|
206
|
+
|
207
|
+
Builder(
|
208
|
+
|
209
|
+
builder: (context) {
|
210
|
+
|
211
|
+
return RaisedButton(
|
212
|
+
|
213
|
+
child: Text("Button"),
|
214
|
+
|
215
|
+
color: Colors.orange,
|
216
|
+
|
217
|
+
textColor: Colors.white,
|
218
|
+
|
219
|
+
onPressed: () {
|
220
|
+
|
221
|
+
Navigator.push(
|
222
|
+
|
223
|
+
context,
|
224
|
+
|
225
|
+
MaterialPageRoute(builder: (context) => AddRecipe()),
|
226
|
+
|
227
|
+
);
|
228
|
+
|
229
|
+
},
|
230
|
+
|
231
|
+
);
|
232
|
+
|
233
|
+
},
|
234
|
+
|
235
|
+
),
|
236
|
+
|
237
|
+
],
|
238
|
+
|
239
|
+
),
|
240
|
+
|
241
|
+
),
|
242
|
+
|
243
|
+
),
|
244
|
+
|
245
|
+
),
|
246
|
+
|
247
|
+
);
|
248
|
+
|
249
|
+
}
|
250
|
+
|
251
|
+
}
|
252
|
+
|
253
|
+
|
254
|
+
|
255
|
+
```
|