Flutter FutureBuilder List

dev-nam·2022년 2월 13일
0

Flutter FutureBuilder Example


Widget build(BuildContext context) {
  return Scaffold(
    ...,
    body: Center(
      child: FutureBuilder<List<Model>>(
        future: DBHelper.instance.getItems(),
        builder: (BuildContext context, AsyncSnapshot<List<Model>> snapshot) {
          if (!snapshot.hasData) {
            return Container();
          }
          return snapshot.data!.isEmpty
            ? Container()
            : ListView(
                children: snapshot.data!
                .where((item) => true) 
                .map((item) => Model(
                  id: item.id,
                  title: item.title,
                  ...,
                ))
                .toList(),
              );
        }
      ),
    ),
  );
}

0개의 댓글