carousel_slider 1.3.0

  • README.md
  • CHANGELOG.md
  • Example
  • Installing
  • Versions
  • 99

carousel_slider #

A carousel slider widget, support infinite scroll and custom child widget, with auto play feature.

Installation #

Add carousel_slider: ^1.3.0 in your pubspec.yaml dependencies. And import it:

import 'package:carousel_slider/carousel_slider.dart';

How to use #

Simply create a CarouselSlider widget, and pass the required params:

CarouselSlider(
  height: 400.0,
  items: [1,2,3,4,5].map((i) {
    return Builder(
      builder: (BuildContext context) {
        return Container(
          width: MediaQuery.of(context).size.width,
          margin: EdgeInsets.symmetric(horizontal: 5.0),
          decoration: BoxDecoration(
            color: Colors.amber
          ),
          child: Text('text $i', style: TextStyle(fontSize: 16.0),)
        );
      },
    );
  }).toList(),
)

Params #


CarouselSlider(
   items: items,
   height: 400,
   aspectRatio: 16/9,
   viewportFraction: 0.8,
   initialPage: 0,
   enableInfiniteScroll: true,
   reverse: false,
   autoPlay: true,
   autoPlayInterval: Duration(seconds: 3),
   autoPlayAnimationDuration: Duration(milliseconds: 800),
   autoPlayCurve: Curve.fastOutSlowIn,
   pauseAutoPlayOnTouch: Duration(seconds: 10),
   enlargeCenterPage: true,
   onPageChanged: callbackFunction,
   scrollDirection: Axis.horizontal,
 )

You can pass the above params to the class. If you pass the height params, the aspectRatio param will be ignore.

Instance methods #

You can use the instance methods to programmatically take control of the pageView's position.

.nextPage({Duration duration, Curve curve}) #

Animate to the next page

.previousPage({Duration duration, Curve curve}) #

Animate to the previous page

.jumpToPage(int page) #

Jump to the given page.

.animateToPage(int page, {Duration duration, Curve curve}) #

Animate to the given page.

Example #

Let a carousel slide play automatically or use buttons:

auto_button_loop.gif

Show dot indicator or play carousel in cover mode:

indicator_fullscreen_loop.gif

Pause slideshow for a set amount of time on user touch input:

touch_pause_loop.gif

For a more detail example please take a look at the example folder.

Faq #

Can I display a dotted indicator for the slider? #

Yes, you can.

class CarouselWithIndicator extends StatefulWidget {
  @override
  _CarouselWithIndicatorState createState() => _CarouselWithIndicatorState();
}

class _CarouselWithIndicatorState extends State<CarouselWithIndicator> {
  int _current = 0;

  @override
  Widget build(BuildContext context) {
    return Stack(
      children: [
        CarouselSlider(
          items: child,
          autoPlay: true,
          aspectRatio: 2.0,
          onPageChangedCallback: (index) {
            setState(() {
              _current = index;
            });
          },
        ),
        Positioned(
          top: 0.0,
          left: 0.0,
          right: 0.0,
          child: Row(
            mainAxisAlignment: MainAxisAlignment.center,
            children: map<Widget>(imgList, (index, url) {
              return Container(
                width: 8.0,
                height: 8.0,
                margin: EdgeInsets.symmetric(vertical: 10.0, horizontal: 2.0),
                decoration: BoxDecoration(
                  shape: BoxShape.circle,
                  color: _current == index ? Color.fromRGBO(0, 0, 0, 0.9) : Color.fromRGBO(0, 0, 0, 0.4)
                ),
              );
            }),
          )
        )
      ]
    );
  }
}

Can I pause the slider if i touch it? #

Yes. Use the pauseAutoPlayOnTouch which takes a duration and when set, enables touch detection. Touch Detection is only active if the autoPlay property is set to true. If the screen is touched it will pause the automatic playback for the set duration. if touched again during the time out the timer is reset to the duration passed to pauseAutoPlayOnTouch.

This feature can be useful if you want users to be able to interact with the screen and not have the pages continue sliding, forcing the user to repeatedly swipe back. One such example could be a commercial advertisement where the customers can react to something they like.

Can I disable the infinite loop mode? #

Yes. This was added by popular demand in patch 1.2.0.
Just set the constructor argument enableInfiniteScroll to false.

##

The example folder contains an example showcasing all features.

If something is missing, feel free to open a ticket or contribute!

v0.0.1 #

Initial version.

v0.0.2 #

Remove useless dependencies, add changelog.

0.0.5 #

Fix initialPage bug, fix crash when widget is disposed.

0.0.6 #

Fix hard coded number

1.0.0 #

Added distortion option

1.0.1 #

Update doc

1.1.0 #

Added pauseAutoPlayOnTouch option

Sets a timer on touch detected that pause the auto play with the given Duration. Touch Detection is only active if the autoPlay property is set to true. If screen is touched again during the time out the timer is reset to the given duration.

Added documentation to public properties.

Refactored ambiguous property names and deprecated the old ones.

Updated example project displaying the new feature and refactored the code to follow flutters style guidelines.

Updated .readme

1.2.0 #

Introducing two new features, Vertical scroll and enable/disable infinite scroll .

Pass an Axis as the scrollDirection argument to specify direction.
Use enableInfiniteScroll to toggle between finite and infinite scroll mode. When enableInfiniteScroll is set to false the carousel will not scroll past the first or last item.

1.3.0 #

Breaking change #

  • Remove the deprecated param: interval, autoPlayDuration, distortion, updateCallback. Please use the new param.

Bugfix #

  • Fix enlargeCenterPage option is not working in vertical carousel slider.

example/README.md

carousel_slider_example #

This exmaple shows four carousel slider examples:

  • Image slider with custom button control
  • Image slider with custom caption
  • Image slider with full width display
  • Image slider with indicator

screenshot

Running #

flutter run

Building #

flutter build ios # or flutter build apk

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  carousel_slider: ^1.3.0

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter packages get

Alternatively, your editor might support flutter packages get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:carousel_slider/carousel_slider.dart';
  
Version Uploaded Documentation Archive
1.3.0 Mar 19, 2019 Go to the documentation of carousel_slider 1.3.0 Download carousel_slider 1.3.0 archive
1.2.0 Mar 19, 2019 Go to the documentation of carousel_slider 1.2.0 Download carousel_slider 1.2.0 archive
1.1.0 Feb 20, 2019 Go to the documentation of carousel_slider 1.1.0 Download carousel_slider 1.1.0 archive
1.0.1 Dec 6, 2018 Go to the documentation of carousel_slider 1.0.1 Download carousel_slider 1.0.1 archive
1.0.0 Dec 6, 2018 Go to the documentation of carousel_slider 1.0.0 Download carousel_slider 1.0.0 archive
0.0.7 Aug 29, 2018 Go to the documentation of carousel_slider 0.0.7 Download carousel_slider 0.0.7 archive
0.0.6 Jul 8, 2018 Go to the documentation of carousel_slider 0.0.6 Download carousel_slider 0.0.6 archive
0.0.5 Jul 3, 2018 Go to the documentation of carousel_slider 0.0.5 Download carousel_slider 0.0.5 archive
0.0.4 May 8, 2018 Go to the documentation of carousel_slider 0.0.4 Download carousel_slider 0.0.4 archive
0.0.3 May 8, 2018 Go to the documentation of carousel_slider 0.0.3 Download carousel_slider 0.0.3 archive

All 12 versions...

Popularity:
Describes how popular the package is relative to other packages. [more]
99
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
100
Overall:
Weighted score of the above. [more]
99
Learn more about scoring.

We analyzed this package on Apr 24, 2019, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.2.0
  • pana: 0.12.14
  • Flutter: 1.4.7

Platforms

Detected platforms: Flutter

References Flutter, and has no conflicting libraries.

Health suggestions

Format lib/carousel_slider.dart.

Run flutter format to format lib/carousel_slider.dart.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.0.0-dev.28.0 <3.0.0
flutter 0.0.0
Transitive dependencies
collection 1.14.11
meta 1.1.6 1.1.7
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test