Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Dynamic list for FilterChips
class ActorFilterEntry<Widget> {
const ActorFilterEntry(this.id, this.name);
final String name;
final int id;
}
class InterestsFilterPage extends State<InterestPage> {
...
List<Widget> actorWidgets(interest) {
for (ActorFilterEntry actor in interest) {
Widget build(BuildContext context) {
return new Padding(
padding: const EdgeInsets.all(4.0),
child: new FilterChip(
shape: new BeveledRectangleBorder(
side: const BorderSide(
width: 0.66,
style: BorderStyle.solid,
color: Colors.grey,
),
borderRadius: new BorderRadius.circular(0.0),
),
label: new Text(
actor.name,
style: new TextStyle(fontSize: 16.0),
),
...
),
);
}
}
}
loadInterest() async {
print('Going to load interests');
SharedPreferences prefs = await SharedPreferences.getInstance();
final token = await prefs.getString('token');
this.api.interests(token).then((res) {
print('The response: ${res['interests']}');
return res['interest'];
});
}
@override
Widget build(BuildContext context) {
return Scaffold(
key: scaffoldKey,
backgroundColor: Colors.white,
body: Container(
child: Column(
mainAxisAlignment: MainAxisAlignment.start,
children: <Widget>[
...
new Text(
'What are your interests?',
style: new TextStyle(
color: Colors.black38,
fontSize: 18.0,
),
),
new Divider(
height: 16.0,
),
new FutureBuilder(
future: loadInterest(),
builder: (BuildContext context, snapshot) {
return new Wrap(
children: actorWidgets(snapshot),
);
},
),
...
],
),
),
);
}
...
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.