carousel_slider 0.0.7

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

carousel_slider

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

Installation

Add carousel_slider: ^0.0.6 in your pubspec.yaml dependencies.

How to use

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

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

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

screenshot

Params

new CarouselSlider(
  items: items,
  viewportFraction: 0.8,
  initialPage: 0,
  aspectRatio: 16/9,
  height: 400,
  reverse: false,
  autoPlay: false,
  interval: const Duration(seconds: 4),
  autoPlayCurve: Curves.fastOutSlowIn,
  autoPlayDuration: const Duration(milliseconds: 800),
  updateCallback: someFunction
)

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.

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

example/lib/main.dart

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

final List<String> imgList = [
  'https://images.unsplash.com/photo-1520342868574-5fa3804e551c?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=6ff92caffcdd63681a35134a6770ed3b&auto=format&fit=crop&w=1951&q=80',
  'https://images.unsplash.com/photo-1522205408450-add114ad53fe?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=368f45b0888aeb0b7b08e3a1084d3ede&auto=format&fit=crop&w=1950&q=80',
  'https://images.unsplash.com/photo-1519125323398-675f0ddb6308?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=94a1e718d89ca60a6337a6008341ca50&auto=format&fit=crop&w=1950&q=80',
  'https://images.unsplash.com/photo-1523205771623-e0faa4d2813d?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=89719a0d55dd05e2deae4120227e6efc&auto=format&fit=crop&w=1953&q=80',
  'https://images.unsplash.com/photo-1508704019882-f9cf40e475b4?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=8c6e5e3aba713b17aa1fe71ab4f0ae5b&auto=format&fit=crop&w=1352&q=80',
  'https://images.unsplash.com/photo-1519985176271-adb1088fa94c?ixlib=rb-0.3.5&ixid=eyJhcHBfaWQiOjEyMDd9&s=a0c8d632e977f94e5d312d9893258f59&auto=format&fit=crop&w=1355&q=80'
];

void main() => runApp(new CarouselDemo());

final Widget placeholder = new Container(color: Colors.grey);

List<T> map<T>(List list, Function handler) {
  List<T> result = [];
  for (var i = 0; i < list.length; i  ++) {
    result.add(handler(i, list[i]));
  }

  return result;
}

class CarouselDemo extends StatelessWidget {
  CarouselSlider instance;

  nextSlider() {
    instance.nextPage(duration: new Duration(milliseconds: 300), curve: Curves.linear);
  }

  prevSlider() {
    instance.previousPage(duration: new Duration(milliseconds: 800), curve: Curves.easeIn);
  }

  @override
  Widget build(BuildContext context) {
    instance = new CarouselSlider(
      items: imgList.map((url) {
        return new Container(
          margin: new EdgeInsets.all(5.0),
          child: new ClipRRect(
            borderRadius: new BorderRadius.all(new Radius.circular(5.0)),
              child: new Image.network(url,
              fit: BoxFit.cover,
              width: 1000.0,
            )
          )
        );
      }).toList(),
      viewportFraction: 0.9,
      aspectRatio: 2.0,
      autoPlay: true,
    );
    // print(instance.nextPage());
    return new MaterialApp(
      title: 'demo',
      home: new Scaffold(
        appBar: new AppBar(title: new Text('Carousel slider demo')),
        body: new ListView(
          children: <Widget>[
            new Padding(
              padding: new EdgeInsets.symmetric(vertical: 15.0),
              child: instance
            ),
            new Row(
              children: <Widget>[
                new Expanded(
                  child: new RaisedButton(
                    onPressed: nextSlider,
                    child: new Text('next slider')
                  ),
                ),
                new Expanded(
                  child: new RaisedButton(
                    onPressed: prevSlider,
                    child: new Text(' prev slider')
                  )
                )
              ],
            ),
            new Padding(
              padding: new EdgeInsets.symmetric(vertical: 15.0),
              child: new CarouselSlider(
                items: map<Widget>(imgList, (index, i) {
                  return new Container(
                    margin: new EdgeInsets.all(5.0),
                    child: new ClipRRect(
                      borderRadius: new BorderRadius.all(new Radius.circular(5.0)),
                      child: new Stack(
                        children: <Widget>[
                          new Image.network(i,
                            fit: BoxFit.cover,
                            width: 1000.0,
                          ),
                          new Positioned(
                            bottom: 0.0,
                            left: 0.0,
                            right: 0.0,
                            child: new Container(
                              decoration: new BoxDecoration(
                                gradient: new LinearGradient(
                                  colors: [Color.fromARGB(200, 0, 0, 0), Color.fromARGB(0, 0, 0, 0)],
                                  begin: Alignment.bottomCenter,
                                  end: Alignment.topCenter,
                                )
                              ),
                              padding: EdgeInsets.symmetric(vertical: 10.0, horizontal: 20.0),
                              child: new Text('No. $index image',
                                style: new TextStyle(
                                  color: Colors.white,
                                  fontSize: 20.0,
                                  fontWeight: FontWeight.bold,
                                ),
                              )
                            )
                          ),
                        ],
                      )
                    )
                  );
                }).toList(),
                autoPlay: false,
                viewportFraction: 0.9,
                aspectRatio: 2.0,
              )
            ),
          ],
        )
      )
    );
  }
}

Use this package as a library

1. Depend on it

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


dependencies:
  carousel_slider: ^0.0.7

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
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
0.0.2 Apr 17, 2018 Go to the documentation of carousel_slider 0.0.2 Download carousel_slider 0.0.2 archive
0.0.1 Apr 17, 2018 Go to the documentation of carousel_slider 0.0.1 Download carousel_slider 0.0.1 archive
Popularity:
Describes how popular the package is relative to other packages. [more]
93
Health:
Code health derived from static analysis. [more]
100
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
90
Overall:
Weighted score of the above. [more]
95
Learn more about scoring.

We analyzed this package on Oct 10, 2018, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.0.0
  • pana: 0.12.4
  • Flutter: 0.9.5

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.

Maintenance suggestions

Package is pre-v0.1 release. (-10 points)

While there is nothing inherently wrong with versions of 0.0.*, it usually means that the author is still experimenting with the general direction of the API.

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
sky_engine 0.0.99
typed_data 1.1.6
vector_math 2.0.8
Dev dependencies
flutter_test