美文网首页
2021-12-16

2021-12-16

作者: 笨的很想飞 | 来源:发表于2021-12-16 23:35 被阅读0次

FutureBuilder 笔记


image.png

1.FutureBuilder

FutureBuilder(
          future: getHomePageContent(), //异步网络请求
          builder: (BuildContext context,AsyncSnapshot snapshot){
            if(snapshot.hasData){//如何返回数据
              Map newMap = snapshot.data;  //网络返回的数据源
              List<Map> rst = (newMap['rst'] as List).cast();
              List<Map> swiper =  rst;
              // (_data['data']['slides'] as List).cast();
              return Column(
                children: [
                  SwiperDiy(swiper) //录播图显示
                ],
              );

            }else{ //如果没有返回
              return Center(
                child: Text('加载中'),
              );

            }
          },
        ),

2.轮播图

import 'package:flutter/material.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
class SwiperDiy extends StatelessWidget {
  // const SwiperDiy({Key? key}) : super(key: key);
  //
  final List wiperDateList;
  SwiperDiy(this.wiperDateList);

  @override
  Widget build(BuildContext context) {
    return Container(
      height: 250,
      child: Swiper(
        itemBuilder: (BuildContext context, int index) {
          return Image.network("${wiperDateList[index]['extData']['images']}",fit: BoxFit.fill);
        },
        itemCount:wiperDateList.length,
        pagination: new SwiperPagination(),
        autoplay: true,
        // control: new SwiperControl(),
      ),

    );
  }
}

相关文章

网友评论

      本文标题:2021-12-16

      本文链接:https://www.haomeiwen.com/subject/eyubfrtx.html