carousel_banner 0.0.1
carousel_banner: ^0.0.1 copied to clipboard
A swipeable, infinitely looping Flutter banner carousel with color or image backgrounds and a mandatory bottom-anchored title and subtitle.
example/lib/main.dart
import 'package:carousel_banner/carousel_banner.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: 'Carousel Banner Example',
theme: ThemeData(
colorScheme: ColorScheme.fromSeed(seedColor: Colors.indigo),
useMaterial3: true,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
const MyHomePage({super.key});
@override
State<MyHomePage> createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
String? _tapped;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('Carousel Banner'),
),
body: ListView(
padding: const EdgeInsets.symmetric(vertical: 16),
children: [
BannerCarousel(
autoplay: true,
items: const [
CarouselItem(
id: '1',
title: 'Aurora',
subtitle: 'Soft violet light over a dark horizon.',
background: CarouselColorBackground(Color(0xFF3B2F63)),
),
CarouselItem(
id: '2',
title: 'Deep Blue',
subtitle: 'Calm gradients for calm dashboards.',
background: CarouselColorBackground(Color(0xFF1D3A5F)),
),
CarouselItem(
id: '3',
title: 'Sunset',
subtitle: 'Warm tones to end the day.',
background: CarouselColorBackground(Color(0xFF6B3A33)),
),
],
onTap: (item) => setState(() => _tapped = item.title),
),
const SizedBox(height: 32),
if (_tapped != null)
Padding(
padding: const EdgeInsets.symmetric(horizontal: 16),
child: Text(
'Last tapped: $_tapped',
style: Theme.of(context).textTheme.titleMedium,
),
),
],
),
);
}
}