flutter 网络请求以及数据处理

网络请求使用FutureBuilder来处理

import 'dart:convert';

  Widget build(BuildContext context) {
    return FutureBuilder(
      future: httpReq.get(sevicePath['homeArticle']+'${widget.id}'),
      builder: (context,snapshot){
        if (snapshot.hasData){
              var data = jsonDecode(snapshot.data.toString());
              datas = (data['data'] as List).cast();
              return SingleChildScrollView(
                child: _cellList(),
              );
        }else{
          return Center(
            child: Text('加载中...'),
          );
        }
      },
    );
  }
posted @ 2019-08-21 16:58  qqcc1388  阅读(1467)  评论(0编辑  收藏  举报