Created
May 21, 2019 08:57
-
-
Save Maistho/40ffeef4d9c91db6879a38340bf5460e to your computer and use it in GitHub Desktop.
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 Data { | |
| /// This class holds all the data from the API | |
| final String a; | |
| final int b; | |
| Data.fromJson(Map<String, dynamic> data) : a = data['a'], b = data['b']; | |
| } | |
| class UIProperty { | |
| /// This class is used inside a widget in order to display a value with a label and later be able to update it | |
| final String key; | |
| final String label; | |
| // Would like to type it as String | int, but doesn't seem like that is possible | |
| dynamic value; | |
| UIProperty({@required this.key, @required this.label, this.value}); | |
| } | |
| Future<Data> getData() { | |
| /// Mock API | |
| return Future(() => Data.fromJson({'a': 'a', 'b': 2})); | |
| } | |
| void createPropertyList() { | |
| /// This is probably run inside a bloc or a service | |
| List<UIProperty> list = [ | |
| UIProperty(key: 'a', label: 'Label A'), | |
| UIProperty(key: 'b', label: 'Label B'), | |
| ]; | |
| getData().then((data) { | |
| // This is pretty shitty code | |
| list[0].value = data.a; | |
| list[1].value = data.b; | |
| }); | |
| } |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment