This commit is contained in:
2026-07-12 04:33:48 +08:00
parent f8a90ad305
commit e7ce0f7bae
151 changed files with 2765 additions and 2947 deletions

View File

@@ -6,8 +6,8 @@ import 'style.dart';
class Carousel extends StatefulWidget {
Carousel({
double height = 200.0,
List<Widget> pages,
bool autoPlay,
List<Widget>? pages,
bool autoPlay = false,
Duration duration = const Duration(seconds: 2),
Duration animationDuration = const Duration(milliseconds: 1000),
})
@@ -17,11 +17,11 @@ class Carousel extends StatefulWidget {
duration = duration,
animationDuration = animationDuration;
final double height;
final List<Widget> pages;
final bool autoPlay;
final Duration duration;
final Duration animationDuration;
final double? height;
final List<Widget>? pages;
final bool? autoPlay;
final Duration? duration;
final Duration? animationDuration;
@override
createState() => new CarouselState();
@@ -30,7 +30,7 @@ class Carousel extends StatefulWidget {
class CarouselState extends State<Carousel> {
final _pageController = new PageController();
Timer _timer;
Timer? _timer;
int _currentPage = 0;
bool reverse = false;
GlobalKey<IndicatorState> _indicatorStateKey = new GlobalKey();
@@ -38,13 +38,13 @@ class CarouselState extends State<Carousel> {
@override
void initState() {
super.initState();
if (widget.autoPlay) {
_timer = new Timer.periodic(widget.duration, (timer) {
if (widget.autoPlay!) {
_timer = new Timer.periodic(widget.duration!, (timer) {
_pageController.animateToPage(_currentPage,
duration: widget.animationDuration, curve: Curves.linear);
duration: widget.animationDuration!, curve: Curves.linear);
if (!reverse) {
_currentPage += 1;
if (_currentPage == widget.pages.length) {
if (_currentPage == widget.pages?.length) {
_currentPage -= 1;
reverse = true;
}
@@ -61,9 +61,9 @@ class CarouselState extends State<Carousel> {
@override
void dispose() {
_pageController?.dispose();
_pageController.dispose();
if (_timer != null) {
_timer.cancel();
_timer!.cancel();
}
super.dispose();
}
@@ -77,10 +77,10 @@ class CarouselState extends State<Carousel> {
color: Style.backgroundColor,
child: new PageView(
controller: _pageController,
children: widget.pages,
children: widget.pages!,
onPageChanged: (index) {
_currentPage = index;
_indicatorStateKey.currentState.changeIndex(index);
_indicatorStateKey.currentState?.changeIndex(index);
},
),
),
@@ -91,7 +91,7 @@ class CarouselState extends State<Carousel> {
child: new Align(
child: new Indicator(
key: _indicatorStateKey,
count: widget.pages.length,
count: widget.pages!.length,
),
alignment: Alignment.center,
),
@@ -102,11 +102,11 @@ class CarouselState extends State<Carousel> {
}
class Indicator extends StatefulWidget {
Indicator({Key key, int count})
Indicator({Key? key, int? count})
: count = count,
super(key: key);
final int count;
final int? count;
@override
createState() => new IndicatorState();
@@ -124,7 +124,7 @@ class IndicatorState extends State<Indicator> {
@override
Widget build(BuildContext context) {
var indicators = <Widget>[];
for (var i = 0; i < widget.count; ++i) {
for (var i = 0; i < widget.count!; ++i) {
indicators.add(new Container(
width: 5.0,
height: 5.0,
@@ -135,7 +135,7 @@ class IndicatorState extends State<Indicator> {
));
}
return new SizedBox(
width: widget.count * 15.0,
width: widget.count! * 15.0,
height: 30.0,
child: new Row(
children: indicators,