Last active
June 27, 2018 01:25
-
-
Save seanmavley/0a5f5190272c4f1a60b5a47203a06746 to your computer and use it in GitHub Desktop.
Dynamic list for FilterChips
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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