Skip to main content

curved_carousel_plus 1.0.0 copy "curved_carousel_plus: ^1.0.0" to clipboard
curved_carousel_plus: ^1.0.0 copied to clipboard

A beautiful curved carousel widget for Flutter with customizable curve height, item spacing, and smooth animations.

example/lib/main.dart

import 'package:curved_carousel_plus/curved_carousel_plus.dart';
import 'package:flutter/material.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Curved Carousel Plus Examples',
      theme: ThemeData(
        colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
        useMaterial3: true,
      ),
      home: const CarouselDemo(),
    );
  }
}

class CarouselDemo extends StatefulWidget {
  const CarouselDemo({super.key});

  @override
  State<CarouselDemo> createState() => _CarouselDemoState();
}

class _CarouselDemoState extends State<CarouselDemo> {
  final _carouselController = CurvedCarouselController();
  int _currentIndex = 0;
  bool _autoPlay = false;

  @override
  void dispose() {
    _carouselController.dispose();
    super.dispose();
  }

  // Car items similar to the screenshot
  final List<Map<String, dynamic>> _carItems = [
    {
      'name': 'Kia Soul EV',
      'color': Colors.black,
      'accentColor': Colors.red,
      'icon': '🚗',
    },
    {
      'name': 'Hatchback',
      'color': Colors.grey,
      'accentColor': Colors.blue,
      'icon': '🚙',
    },
    {
      'name': 'Sports Car',
      'color': Colors.grey.shade300,
      'accentColor': Colors.orange,
      'icon': '🏎️',
    },
    {
      'name': 'SUV',
      'color': Colors.blueGrey,
      'accentColor': Colors.green,
      'icon': '🚐',
    },
    {
      'name': 'Sedan',
      'color': Colors.indigo,
      'accentColor': Colors.purple,
      'icon': '🚕',
    },
  ];

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[900],
      appBar: AppBar(
        title: const Text('Curved Carousel Demo'),
        backgroundColor: Colors.grey[850],
        foregroundColor: Colors.white,
      ),
      body: Column(
        children: [
          const SizedBox(height: 40),
          // Main Carousel - Center item prominent, side items below
          CurvedCarousel(
            controller: _carouselController,
            items: _carItems.map((car) {
              final index = _carItems.indexOf(car);
              final isCenter = index == _currentIndex;

              return Container(
                decoration: BoxDecoration(
                  color: car['color'] as Color,
                  borderRadius: BorderRadius.circular(20),
                  border: Border.all(
                    color: (car['accentColor'] as Color).withValues(alpha: 0.5),
                    width: 2,
                  ),
                  boxShadow: [
                    if (isCenter)
                      BoxShadow(
                        color: (car['accentColor'] as Color)
                            .withValues(alpha: 0.6),
                        blurRadius: 30,
                        spreadRadius: 10,
                      ),
                  ],
                ),
                child: Stack(
                  children: [
                    // Glow effect for center item
                    if (isCenter)
                      Positioned.fill(
                        child: Container(
                          decoration: BoxDecoration(
                            borderRadius: BorderRadius.circular(20),
                            gradient: RadialGradient(
                              center: Alignment.center,
                              radius: 0.8,
                              colors: [
                                (car['accentColor'] as Color)
                                    .withValues(alpha: 0.3),
                                Colors.transparent,
                              ],
                            ),
                          ),
                        ),
                      ),
                    // Car content
                    Center(
                      child: Column(
                        mainAxisAlignment: MainAxisAlignment.center,
                        children: [
                          Text(
                            car['icon'] as String,
                            style: const TextStyle(fontSize: 100),
                          ),
                          const SizedBox(height: 20),
                          Text(
                            car['name'] as String,
                            style: TextStyle(
                              color: Colors.white,
                              fontSize: isCenter ? 24 : 20,
                              fontWeight: isCenter
                                  ? FontWeight.bold
                                  : FontWeight.normal,
                            ),
                          ),
                          if (isCenter) ...[
                            const SizedBox(height: 10),
                            Container(
                              padding: const EdgeInsets.symmetric(
                                horizontal: 16,
                                vertical: 8,
                              ),
                              decoration: BoxDecoration(
                                color: (car['accentColor'] as Color)
                                    .withValues(alpha: 0.8),
                                borderRadius: BorderRadius.circular(20),
                              ),
                              child: const Text(
                                'FOCUSED',
                                style: TextStyle(
                                  color: Colors.white,
                                  fontSize: 12,
                                  fontWeight: FontWeight.bold,
                                ),
                              ),
                            ),
                          ],
                        ],
                      ),
                    ),
                  ],
                ),
              );
            }).toList(),
            curveHeight: 120.0,
            itemSpacing: 15.0,
            itemHeight: 250,
            itemWidth: 500,
            viewportFraction: 0.4,
            autoPlay: _autoPlay,
            autoPlayDuration: const Duration(seconds: 3),
            animationDuration: const Duration(milliseconds: 200),
            scaleFactor: 0.3,
            opacityFactor: 0.2,
            onItemTap: (index) {
              ScaffoldMessenger.of(context).showSnackBar(
                SnackBar(
                  content: Text('${_carItems[index]['name']} tapped!'),
                  duration: const Duration(seconds: 1),
                  backgroundColor: Colors.grey[800],
                ),
              );
            },
            onIndexChanged: (index) {
              setState(() {
                _currentIndex = index;
              });
              // Also get current index from controller
              print(
                  'Current index from controller: ${_carouselController.currentIndex}');
            },
          ),
          const SizedBox(height: 60),
          // Current car info
          Container(
            margin: const EdgeInsets.symmetric(horizontal: 20),
            padding: const EdgeInsets.all(20),
            decoration: BoxDecoration(
              color: Colors.grey[800],
              borderRadius: BorderRadius.circular(15),
            ),
            child: Column(
              children: [
                Text(
                  _carItems[_currentIndex]['name'] as String,
                  style: const TextStyle(
                    color: Colors.white,
                    fontSize: 24,
                    fontWeight: FontWeight.bold,
                  ),
                ),
                const SizedBox(height: 10),
                Text(
                  'Item ${_currentIndex + 1} of ${_carItems.length}',
                  style: TextStyle(
                    color: Colors.grey[400],
                    fontSize: 16,
                  ),
                ),
                const SizedBox(height: 10),
                // Show current index from controller
                Text(
                  'Controller index: ${_carouselController.currentIndex ?? 'N/A'}',
                  style: TextStyle(
                    color: Colors.grey[500],
                    fontSize: 14,
                    fontStyle: FontStyle.italic,
                  ),
                ),
              ],
            ),
          ),
          const SizedBox(height: 30),
          // Auto-play toggle
          Container(
            margin: const EdgeInsets.symmetric(horizontal: 20),
            padding: const EdgeInsets.all(16),
            decoration: BoxDecoration(
              color: Colors.grey[800],
              borderRadius: BorderRadius.circular(15),
            ),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.center,
              children: [
                const Text(
                  'Auto-play: ',
                  style: TextStyle(color: Colors.white, fontSize: 16),
                ),
                Switch(
                  value: _autoPlay,
                  onChanged: (value) {
                    setState(() {
                      _autoPlay = value;
                    });
                  },
                ),
              ],
            ),
          ),
          const SizedBox(height: 20),
          // Page indicators
          Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: List.generate(
              _carItems.length,
              (index) => Container(
                width: _currentIndex == index ? 24 : 10,
                height: 10,
                margin: const EdgeInsets.symmetric(horizontal: 4),
                decoration: BoxDecoration(
                  borderRadius: BorderRadius.circular(5),
                  color: _currentIndex == index
                      ? (_carItems[_currentIndex]['accentColor'] as Color)
                      : Colors.grey[600],
                ),
              ),
            ),
          ),
        ],
      ),
    );
  }
}
0
likes
140
points
78
downloads

Documentation

API reference

Publisher

unverified uploader

Weekly Downloads

A beautiful curved carousel widget for Flutter with customizable curve height, item spacing, and smooth animations.

License

MIT (license)

Dependencies

flutter

More

Packages that depend on curved_carousel_plus