dropdownbutton still not working fully

...but it works a bit more than before!
This commit is contained in:
Felix 2019-07-19 15:15:04 +01:00
parent 2e0802ac73
commit 525a092f40
No known key found for this signature in database
GPG key ID: 130EF6DC43E4DD07
3 changed files with 122 additions and 77 deletions

View file

@ -70,7 +70,9 @@ Future<List<Category>> getCategories() async { // confusing name
// });
// print(categories[10].name.toString()); // prints "Banana"
return categories;
return categories; // categories is List<Category>
// Category is defined at the top^^
} else {
// not successful
return null;

View file

@ -1,35 +1,25 @@
import 'package:flutter/material.dart';
import 'package:local_spend/common/apifunctions/categories.dart';
import 'dart:async';
class DropDownMenu extends StatefulWidget {
Future<List<DropdownMenuItem>> getDropDownItems(String type) async {
List<DropdownMenuItem<String>> items = new List<DropdownMenuItem<String>>();
final List<DropdownMenuItem> items;
final Function onChanged;
final String value;
DropDownMenu({
this.items,
this.onChanged,
this.value,
});
// if (type == "categories") {
var categories = await getCategories();
@override
_DropDownMenuState createState() => _DropDownMenuState(items: this.items, onNewValue: this.onChanged, value: this.value);
categories.forEach((thisValue) {
items.add(
new DropdownMenuItem(
child: new Text(thisValue.name),
value: thisValue.index,
key: Key(thisValue.index),
),
);
});
print("oof");
return items;
// }
}
class _DropDownMenuState extends State<DropDownMenu> {
final List<DropdownMenuItem> items;
final Function onNewValue;
final String value;
_DropDownMenuState({
this.items,
this.onNewValue,
this.value
});
@override
Widget build(BuildContext context) {
return new DropdownButton(value: this.value, items: this.items, onChanged: (newValue) => onNewValue(newValue),);
}
}