flutter_swiper 已经明确提示不支持 Flutter空安全. so....
pubspec.yaml:
environment:
sdk: '>=3.0.5 <4.0.0'
dependencies:
flutter:
sdk: flutter
flutter_swiper_null_safety: ^1.0.2
home_page.dart:
import 'package:flutter/material.dart';
import 'package:flutter_swiper_null_safety/flutter_swiper_null_safety.dart';
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
// 定义轮播图
List _imagesUrls = [
'http://xx.jpg',
'https://xx.jpg',
'https://xx.jpg',
];
@override
Widget build(BuildContext context) {
// 创建根节点: 导航
return Scaffold(
body: Center(
child: Column(
children: [
Container(
height: 160,
child: Swiper(
itemCount: _imagesUrls.length,
autoplay: true,
itemBuilder: (BuildContext context, int index) {
return Image.network(
_imagesUrls[index],
fit: BoxFit.fill,
);
},
pagination: SwiperPagination(),
),
),
],
),
),
);
}
}