2018/04/18 Flutter JP Meetup
@ntaoo
同じようなプロダクションコードおよびテストコードを3回も書きたくない!
https://github.com/ntaoo/hacker_news_flutter_angular
プラットフォーム非依存の新しいDIライブラリ?
Widget _buildResults() {
return new StreamBuilder(
stream: hackerNewsService.results,
builder: (context, snapshot) => new ListView(
padding: EdgeInsets.fromLTRB(1.0, 20.0, 1.0, 0.0),
children: (snapshot?.data ?? <Item>[])
.map<NewsItem>((Item item) => new NewsItem(item))
.toList(),
),
);
}
<material-input leadingText="Filter" style="width: 100%" #input
(keyup)="hackerNewsService.filterQuery.add(input.inputText)">
</material-input>
<article *ngFor="let item of hackerNewsService.results | async">
<item [item]="item"></item>
</article>
import 'dart:async';
import 'package:http/http.dart' as http;
import 'dart:convert';
class HackerNewsService {
final http.Client _client;
StreamController<String> filterQuery = new StreamController();
Stream<List<Item>> results = new Stream.empty();
...
HackerNewsService(this._client) {
...
}
元ネタ
https://www.youtube.com/watch?v=PLHln7wHgPE