adding stateful widget
This commit is contained in:
+40
-11
@@ -2,20 +2,49 @@ 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(
|
||||||
home: Scaffold(
|
home: Scaffold(
|
||||||
appBar: AppBar(
|
appBar: AppBar(
|
||||||
title: Text('Do Everything Bar'),
|
title: Text('Do Everything Bar'),
|
||||||
),
|
|
||||||
body: Card(
|
|
||||||
child: Column(children: <Widget>[
|
|
||||||
Image.asset('assets/food.jpg'),
|
|
||||||
Text('Food Paradise')
|
|
||||||
])),
|
|
||||||
),
|
),
|
||||||
);
|
body: Column(
|
||||||
|
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'),
|
||||||
|
Text(elem)
|
||||||
|
],
|
||||||
|
)))
|
||||||
|
.toList(),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user