simple widget tree with managing data with each
This commit is contained in:
@@ -0,0 +1,44 @@
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import './products.dart';
|
||||
|
||||
class ProductManager extends StatefulWidget {
|
||||
final String startingProduct;
|
||||
|
||||
ProductManager(this.startingProduct);
|
||||
|
||||
@override
|
||||
State<StatefulWidget> createState() {
|
||||
return _ProductManagerState();
|
||||
}
|
||||
}
|
||||
|
||||
class _ProductManagerState extends State<ProductManager> {
|
||||
List<String> _products = [];
|
||||
|
||||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
_products.add(widget.startingProduct);
|
||||
}
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Column(
|
||||
children: [
|
||||
Container(
|
||||
margin: EdgeInsets.all(10),
|
||||
child: RaisedButton(
|
||||
onPressed: () {
|
||||
setState(() {
|
||||
_products.add('Advanced Food Tester');
|
||||
});
|
||||
},
|
||||
child: Text('Click Me!'),
|
||||
),
|
||||
),
|
||||
Products(_products),
|
||||
],
|
||||
);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user