Created
December 16, 2018 05:04
-
-
Save arthurcohen/2fbd566192ec86e2edcec7244458ea70 to your computer and use it in GitHub Desktop.
Dart experience - Http request, List manipulation, DOM manipulation
This file contains 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
<div>Insert a String</div> | |
<input type="text" id="text-in"/> | |
<input type="button" value="ok" id="btn-in"/> | |
<div id="text-res">_______</div> |
This file contains 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
import 'dart:html'; | |
import 'dart:convert'; | |
void main() { | |
querySelector('#btn-in').onClick.listen((e) => get()); | |
} | |
void get(){ | |
HttpRequest.getString('https://swapi.co/api/people') | |
.then((res) => filter(res)); | |
} | |
void filter(String data){ | |
print((querySelector('#text-in') as InputElement).value); | |
List sData = json.decode(data)['results']; | |
sData.retainWhere((el) => el['name'].toString().contains( | |
(querySelector('#text-in') as InputElement).value)); | |
print(sData); | |
querySelector('#text-res').text = ''; | |
sData.forEach((el) => | |
querySelector('#text-res').text = | |
querySelector('#text-res').text + ', ' + el['name']); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment