feat: make cards non-nullable
This commit is contained in:
parent
712685e20c
commit
bc14c3f747
|
|
@ -4,7 +4,7 @@ import 'package:flutter/material.dart';
|
||||||
|
|
||||||
class CardSwiper extends StatefulWidget {
|
class CardSwiper extends StatefulWidget {
|
||||||
/// list of widgets for the swiper
|
/// list of widgets for the swiper
|
||||||
final List<Widget?>? cards;
|
final List<Widget?> cards;
|
||||||
|
|
||||||
/// controller to trigger actions
|
/// controller to trigger actions
|
||||||
final CardSwiperController? controller;
|
final CardSwiperController? controller;
|
||||||
|
|
@ -81,7 +81,7 @@ class _CardSwiperState extends State<CardSwiper>
|
||||||
|
|
||||||
CardSwiperDirection detectedDirection = CardSwiperDirection.none;
|
CardSwiperDirection detectedDirection = CardSwiperDirection.none;
|
||||||
|
|
||||||
bool get _isLastCard => _currentIndex == widget.cards!.length - 1;
|
bool get _isLastCard => _currentIndex == widget.cards.length - 1;
|
||||||
int get _nextCardIndex => _isLastCard ? 0 : _currentIndex + 1;
|
int get _nextCardIndex => _isLastCard ? 0 : _currentIndex + 1;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
|
|
@ -93,7 +93,7 @@ class _CardSwiperState extends State<CardSwiper>
|
||||||
//swipe widget from the outside
|
//swipe widget from the outside
|
||||||
..addListener(() {
|
..addListener(() {
|
||||||
if (widget.controller!.state == CardSwiperState.swipe) {
|
if (widget.controller!.state == CardSwiperState.swipe) {
|
||||||
if (widget.cards!.isNotEmpty) {
|
if (widget.cards.isNotEmpty) {
|
||||||
switch (widget.direction) {
|
switch (widget.direction) {
|
||||||
case CardSwiperDirection.right:
|
case CardSwiperDirection.right:
|
||||||
_swipeHorizontal(context);
|
_swipeHorizontal(context);
|
||||||
|
|
@ -117,7 +117,7 @@ class _CardSwiperState extends State<CardSwiper>
|
||||||
//swipe widget left from the outside
|
//swipe widget left from the outside
|
||||||
..addListener(() {
|
..addListener(() {
|
||||||
if (widget.controller!.state == CardSwiperState.swipeLeft) {
|
if (widget.controller!.state == CardSwiperState.swipeLeft) {
|
||||||
if (widget.cards!.isNotEmpty) {
|
if (widget.cards.isNotEmpty) {
|
||||||
_left = -1;
|
_left = -1;
|
||||||
_swipeHorizontal(context);
|
_swipeHorizontal(context);
|
||||||
_animationController.forward();
|
_animationController.forward();
|
||||||
|
|
@ -127,7 +127,7 @@ class _CardSwiperState extends State<CardSwiper>
|
||||||
//swipe widget right from the outside
|
//swipe widget right from the outside
|
||||||
..addListener(() {
|
..addListener(() {
|
||||||
if (widget.controller!.state == CardSwiperState.swipeRight) {
|
if (widget.controller!.state == CardSwiperState.swipeRight) {
|
||||||
if (widget.cards!.isNotEmpty) {
|
if (widget.cards.isNotEmpty) {
|
||||||
_left = widget.threshold + 1;
|
_left = widget.threshold + 1;
|
||||||
_swipeHorizontal(context);
|
_swipeHorizontal(context);
|
||||||
_animationController.forward();
|
_animationController.forward();
|
||||||
|
|
@ -218,7 +218,7 @@ class _CardSwiperState extends State<CardSwiper>
|
||||||
angle: _angle,
|
angle: _angle,
|
||||||
child: Container(
|
child: Container(
|
||||||
constraints: constraints,
|
constraints: constraints,
|
||||||
child: widget.cards![index],
|
child: widget.cards[index],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
|
|
@ -259,7 +259,7 @@ class _CardSwiperState extends State<CardSwiper>
|
||||||
|
|
||||||
Widget _backItem(BoxConstraints constraints, int index) {
|
Widget _backItem(BoxConstraints constraints, int index) {
|
||||||
return Visibility(
|
return Visibility(
|
||||||
visible: widget.cards!.length - index <= 2,
|
visible: widget.cards.length - index <= 2,
|
||||||
child: Positioned(
|
child: Positioned(
|
||||||
top: _difference,
|
top: _difference,
|
||||||
left: 0,
|
left: 0,
|
||||||
|
|
@ -269,7 +269,7 @@ class _CardSwiperState extends State<CardSwiper>
|
||||||
scale: _scale,
|
scale: _scale,
|
||||||
child: Container(
|
child: Container(
|
||||||
constraints: constraints,
|
constraints: constraints,
|
||||||
child: widget.cards![index],
|
child: widget.cards[index],
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue