Skip to content

Instantly share code, notes, and snippets.

@arthurcohen
Created December 16, 2018 05:04
Show Gist options
  • Save arthurcohen/2fbd566192ec86e2edcec7244458ea70 to your computer and use it in GitHub Desktop.
Save arthurcohen/2fbd566192ec86e2edcec7244458ea70 to your computer and use it in GitHub Desktop.
Dart experience - Http request, List manipulation, DOM manipulation
<div>Insert a String</div>
<input type="text" id="text-in"/>
<input type="button" value="ok" id="btn-in"/>
<div id="text-res">_______</div>
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