adding stateful widget

This commit is contained in:
talksik
2019-05-24 09:19:05 -07:00
parent cfc10fd5f1
commit c6de0ce9b2
+35 -6
View File
@@ -2,7 +2,17 @@ import 'package:flutter/material.dart';
void main() => runApp(MyApp()); void main() => runApp(MyApp());
class MyApp extends StatelessWidget { class MyApp extends StatefulWidget {
@override
State<StatefulWidget> createState() {
// TODO: implement createState
return _MyAppState();
}
}
class _MyAppState extends State<MyApp> {
List<String> _products = ['Test'];
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return MaterialApp( return MaterialApp(
@@ -10,12 +20,31 @@ class MyApp extends StatelessWidget {
appBar: AppBar( appBar: AppBar(
title: Text('Do Everything Bar'), title: Text('Do Everything Bar'),
), ),
body: Card( body: Column(
child: Column(children: <Widget>[ children: [
Container(
margin: EdgeInsets.all(10),
child: RaisedButton(
onPressed: () {
setState(() {
_products.add('Advanced Food Tester');
});
},
child: Text('Click Me!'),
)),
Column(
children: _products
.map((elem) => Card(
child: Column(
children: <Widget>[
Image.asset('assets/food.jpg'), Image.asset('assets/food.jpg'),
Text('Food Paradise') Text(elem)
])), ],
)))
.toList(),
), ),
); ],
),
));
} }
} }