fixed up url pizza fetch page, with ValueNotifier

This commit is contained in:
broodjeaap89 2021-09-14 19:43:59 +02:00
parent 8cdfed1946
commit 2f821c7e09
2 changed files with 48 additions and 43 deletions

View file

@ -18,7 +18,7 @@ class AddRecipeURLPage extends StatefulWidget {
class AddRecipeURLPageState extends State<AddRecipeURLPage> {
String? url;
String tempUrl = "?";
List<Widget> itemList = <Widget>[];
final ValueNotifier<List<Widget>> itemListNotifier = ValueNotifier(<Widget>[]);
@override
void initState() {
@ -39,7 +39,7 @@ class AddRecipeURLPageState extends State<AddRecipeURLPage> {
width: double.infinity,
child: TextButton(
onPressed: () async {
showDialog(context: context, builder: (BuildContext context) {
await showDialog(context: context, builder: (BuildContext context) {
return AlertDialog(
title: const Text("URL"),
content: TextFormField(
@ -48,9 +48,7 @@ class AddRecipeURLPageState extends State<AddRecipeURLPage> {
),
initialValue: url ?? "",
onChanged: (String newUrl) {
setState(() {
tempUrl = newUrl;
});
},
),
actions: <Widget>[
@ -61,17 +59,17 @@ class AddRecipeURLPageState extends State<AddRecipeURLPage> {
child: const Text("Cancel"),
),
TextButton(
onPressed: () {
onPressed: () async {
Navigator.pop(context);
url = tempUrl;
setState(() {
fetchUrl();
});
},
child: const Text("Fetch"),
),
],
);
}).then((_) {
setState(() {});
});
},
child: Text(url ?? "Tap to load URL", style: const TextStyle(color: Colors.white)),
@ -81,8 +79,14 @@ class AddRecipeURLPageState extends State<AddRecipeURLPage> {
const Divider(),
Expanded(
flex: 45,
child: ListView(
children: itemList,
child: ValueListenableBuilder<List<Widget>>(
valueListenable: itemListNotifier,
builder: (BuildContext context, List<Widget> widgets, Widget? child) {
print("test");
return ListView(
children: widgets
);
}
)
)
]
@ -105,11 +109,13 @@ class AddRecipeURLPageState extends State<AddRecipeURLPage> {
}
final yamlBody = response.body;
if (!(yamlBody.startsWith("recipe:") || yamlBody.startsWith("recipes"))){
return;
}
final pizzaRecipe = await PizzaRecipe.fromYaml(yamlBody);
itemList.clear();
itemList.add(
itemListNotifier.value.clear();
itemListNotifier.value = <Widget>[ // inefficient probably but otherwise it doesn't trigger notify...
InkWell(
onTap: () {
showDialog(context: context, builder: (BuildContext context) {
@ -137,7 +143,7 @@ class AddRecipeURLPageState extends State<AddRecipeURLPage> {
},
child: PizzaRecipeWidget(pizzaRecipe),
)
);
];
} catch (exception) {
print(exception);
return;

View file

@ -13,7 +13,6 @@
- RecipeStep.waitUnit should probably be an enum?
- refactor to const page names instead of loose strings everywhere ('/path/page')
- also do this with hive box names
- probably use a stream for adding fetched url data to the listview ?
## Bug
- add option to start recipe step instruction after step datetime and not completed