Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import 'package:flutter/material.dart';
- import 'package:flutter_carousel_widget/flutter_carousel_widget.dart';
- void main() {
- runApp(const MyApp());
- }
- class MyApp extends StatelessWidget {
- const MyApp({super.key});
- @override
- Widget build(BuildContext context) {
- return const MaterialApp(
- title: 'Demo',
- home: MyHomePage(title: 'Flutter Demo Home Page'),
- );
- }
- }
- class MyHomePage extends StatefulWidget {
- const MyHomePage({super.key, required this.title});
- final String title;
- @override
- State<MyHomePage> createState() => _MyHomePageState();
- }
- class _MyHomePageState extends State<MyHomePage> {
- CarouselController? controller = CarouselController();
- bool autoplay = false;
- CarouselPageChangedReason? lastReason;
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- elevation: 10,
- title: Text(widget.title),
- actions: [
- IconButton(
- onPressed: () => setState(() {
- autoplay = !autoplay;
- print('autoplay toggled');
- }),
- icon: Icon(autoplay ? Icons.pause : Icons.play_arrow),
- ),
- IconButton(
- onPressed: () => setState(() {
- controller = controller == null ? CarouselController() : null;
- print('controller toggled');
- }),
- icon: Icon(
- controller == null ? Icons.gamepad_outlined : Icons.gamepad,
- ),
- )
- ],
- ),
- body: Center(
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- children: <Widget>[
- Text(
- 'Last changed reason:\n${lastReason != null ? lastReason!.toString() : 'None'}'),
- FlutterCarousel(
- items: const [
- Padding(
- padding: EdgeInsets.all(8.0),
- child: Placeholder(),
- )
- ],
- options: CarouselOptions(
- onPageChanged: (_, reason) => setState(
- () {
- lastReason = reason;
- print(reason);
- },
- ),
- controller: controller,
- enableInfiniteScroll: true,
- autoPlay: autoplay,
- ),
- ),
- ],
- ),
- ),
- );
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement