用 flutter 实现轮播图

本博客使用 flutter 实现轮播图。
了解更多


源代码
///第一个dart文件
import 'package:flutter/material.dart';
import 'package:flutter_shop/pages/index_page.dart';

///能套一个方便的组件的话,就套一个,方便以后修改
void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  const MyApp({Key key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: IndexPage(),
    );
  }
}

///第二个dart 文件
import 'package:flutter/material.dart';
import 'package:flutter_shop/service/service_method.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'dart:convert';

class HomePage extends StatefulWidget {
  HomePage({Key key}) : super(key: key);

  _HomePageState createState() => _HomePageState();
}

class _HomePageState extends State<HomePage> {

  String homePageContent = '正在获取数据';

  List swiperDateList = [
    'https://i0.hdslb.com/bfs/sycp/creative_img/201907/752528c6f4b9dc2724dd02fd5a92f689.jpg@880w_440h.jpg',
    'https://i0.hdslb.com/bfs/sycp/creative_img/201907/c25fad63f4c27dc59c597b779454ae16.jpg@880w_440h.jpg',
    'https://i0.hdslb.com/bfs/archive/0c735996f2ec270a2bb6e003136dea541c493e2f.jpg@880w_440h.jpg',
    'https://i0.hdslb.com/bfs/archive/2a17825d9738c3f862149d74342d2b27d99653c5.jpg@880w_440h.jpg',
  ];
  
  @override
  Widget build(BuildContext context) {
    return Container(
       child: Scaffold(
        body:SingleChildScrollView(
          // controller: controller,
          child: Column(
            children: <Widget>[Container(
              height: 333,
              child: Swiper(
                itemBuilder: (BuildContext context, int index){
                  return Image.network('${swiperDateList[index]}');
                },
                itemCount: swiperDateList.length,
                pagination: SwiperPagination(),
                autoplay: true,
              )
            )],
          ),
        ),
       ),
    );
  }
}


使用 Swiper 组件实现图片的轮播
Swiper(
itemBuilder: (BuildContext context, int index){
return Image.network(’${swiperDateList[index]}’);
},
itemCount: swiperDateList.length,
pagination: SwiperPagination(),
autoplay: true,
)

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值