stacked_trio_carousel 1.0.2 copy "stacked_trio_carousel: ^1.0.2" to clipboard
stacked_trio_carousel: ^1.0.2 copied to clipboard

A flutter package provides a visually engaging card carousel with a stacked layout of three cards.

Stacked Trio Carousel #

Stacked Trio Carousel is a Flutter package that provides a visually engaging card carousel with a stacked layout of three cards.

Features #

The carousel features one prominent card in the foreground and two cards in the background, making it perfect for showcasing content in a layered and dynamic way. With built-in animations and customizable properties, users can swipe through the cards or enable automatic transitions for a smooth and interactive experience.

Getting Started #

To use this package, add stacked_trio_carousel as a dependency in your pubspec.yaml file. For example:

dependencies:
  stacked_trio_carousel: ^1.0.1

Usage #

Specify the background, and set the width and height of the card. Then, provide the children.

final List _color = [Colors.red, Colors.green, Colors.blue];
@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      backgroundColor: Theme.of(context).colorScheme.inversePrimary,
      title: Text(widget.title),
    ),
    body: Center(
      child: StackedTrioCarousel(
        background: Container(),
        params: StackedTrioCarouselParams(
          cardHeight: 200,
          cardWidth: 200,
        ),
        children: _color
            .map(
              (color) => GestureDetector(
                onTap: () {
                  Navigator.push(
                      context,
                      MaterialPageRoute(
                        builder: (context) => const SecondScreen(),
                      ));
                },
                child: Container(
                  decoration: BoxDecoration(
                    color: color,
                    borderRadius: BorderRadius.circular(25),
                  ),
                ),
              ),
            )
            .toList(),
      ),
    ),
  );
}

Change the Width and Height #

You can modify the dimensions of the cards by changing the cardHeight and cardWidth properties.

StackedTrioCarouselParams(
  cardHeight: 150,
  cardWidth: 150,
)

Add Padding #

To apply padding to the background cards (horizontal padding only), use the padding property.

StackedTrioCarouselParams(
  cardHeight: 150,
  cardWidth: 150,
  padding: const EdgeInsets.symmetric(horizontal: 10),
)

Change Scale and Minimum Opacity #

The scaleRatio and minimumOpacity properties affect the background cards only.

StackedTrioCarouselParams(
  cardHeight: 150,
  cardWidth: 150,
  padding: const EdgeInsets.symmetric(horizontal: 10),
  scaleRatio: 0.2,
  minimumOpacity: 0.1,
)

Add controller #

late StackedTrioCarouselController _carouselController;

@override
void initState() {
    _carouselController = StackedTrioCarouselController(tickerProvider: this);
    super.initState();
}
controller: _carouselController,

Change Animation Duration #

You can modify the animation duration and the delay between animations.

_carouselController = StackedTrioCarouselController(
    tickerProvider: this,
    animationDuration: const Duration(milliseconds: 200),
    autoPlayInterval: const Duration(seconds: 1),
);

Manual Swiping #

You can also allow manual swiping:

Stop Automatic Animation #

To stop the automatic animation, set autoPlay to false.

_carouselController = StackedTrioCarouselController(
    tickerProvider: this,
    animationDuration: const Duration(milliseconds: 200),
    autoPlayInterval: const Duration(seconds: 1),
    autoPlay: false
);

You can also use the startAutoPlay and stopAutoPlay functions

ElevatedButton(
    onPressed: () {
        _carouselController.autoPlay ? _carouselController.stopAutoPlay() : _carouselController.startAutoPlay();
        setState(() {});
    },
    child: Text(
        _carouselController.autoPlay ? "Stop Auto Play" : "Start Auto Play",
        style: const TextStyle(color: Colors.black),
    ),
)

If your app includes navigation functionality, you need to provide a RouteObserver to ensure the carousel behaves correctly when navigating between screens. Without this, the carousel might still be visible after navigation.

Steps to Add RouteObserver:

  1. Define the RouteObserver as a top-level variable and assign it to your MaterialApp:
final RouteObserver routeObserver = RouteObserver();

void main() {
  runApp(const MyApp());
}

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      navigatorObservers: [routeObserver],
      title: 'Flutter Demo',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const MyHomePage(title: 'Stacked Trio Carousel'),
    );
  }
}
  1. Pass the RouteObserver to the StackedTrioCarousel widget:
routeObserver: routeObserver,
  1. Perform a hot restart of the application.

Example #

For a full example, check out the example page.

22
likes
0
points
539
downloads

Publisher

unverified uploader

Weekly Downloads

A flutter package provides a visually engaging card carousel with a stacked layout of three cards.

Repository (GitHub)
View/report issues

License

unknown (license)

Dependencies

flutter

More

Packages that depend on stacked_trio_carousel