flutter实战项目05 屏幕适配与轮播

屏幕适配flutter_screenutil

//1引入包
import 'package:flutter_screenutil/flutter_screenutil.dart';
//2初始化尺寸
ScreenUtil.instance = ScreenUtil(width: 755,height: 1334,allowFontScaling: true)..init(context);
//3设置尺寸
ScreenUtil().setWidth(1125)

轮播flutter_swiper

var data = json.decode(snapshot.data.toString());
List swiperDataList = (data['data']['slides'] as List).cast();
child: ListView(
    children: [
      SwiperDiy(swiperDataList:swiperDataList)
    ],
  ),
import 'package:flutter_swiper/flutter_swiper.dart';

class SwiperDiy extends StatelessWidget{
  final List swiperDataList;//传值
  SwiperDiy({Key key,this.swiperDataList}):super(key:key);
  @override
  Widget build(BuildContext context){
    return Container(
      color: Colors.white,
      width: ScreenUtil().setWidth(1125),
      height: ScreenUtil().setHeight(233),
      child: Swiper(
        itemBuilder: (BuildContext context, int index){
          return InkWell(
            onTap: (){},
            child: Image.network("${swiperDataList[index]['image']}"),
          );
        },
        itemCount: swiperDataList.length,
        pagination: SwiperPagination(),
        autoplay: true,
      ),
    );
  }
}

你可能感兴趣的:(Flutter)