Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to use button to move forward/backward from the carousel. #382

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion example/android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
buildscript {
ext.kotlin_version = '1.3.50'
ext.kotlin_version = '1.6.10'
repositories {
google()
jcenter()
Expand Down
2 changes: 1 addition & 1 deletion example/android/gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.6.2-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-6.9.3-all.zip
31 changes: 30 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ class CarouselDemo extends StatelessWidget {
routes: {
'/': (ctx) => CarouselDemoHome(),
'/basic': (ctx) => BasicDemo(),
'/basicbutton': (ctx) => BasicWithButtonDemo(),
'/nocenter': (ctx) => NoCenterDemo(),
'/image': (ctx) => ImageSliderDemo(),
'/complicated': (ctx) => ComplicatedImageDemo(),
Expand Down Expand Up @@ -82,6 +83,7 @@ class CarouselDemoHome extends StatelessWidget {
body: ListView(
children: <Widget>[
DemoItem('Basic demo', '/basic'),
DemoItem('Basic with button demo', '/basicbutton'),
DemoItem('No center mode demo', '/nocenter'),
DemoItem('Image carousel slider', '/image'),
DemoItem('More complicated image slider', '/complicated'),
Expand Down Expand Up @@ -122,6 +124,29 @@ class BasicDemo extends StatelessWidget {
}
}

class BasicWithButtonDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
List<int> list = [1, 2, 3, 4, 5];
return Scaffold(
appBar: AppBar(title: Text('Basic demo')),
body: Container(
child: CarouselSlider(
options: CarouselOptions(
withButtons: true,
enableInfiniteScroll: false,
),
items: list
.map((item) => Container(
child: Center(child: Text(item.toString())),
color: Colors.green,
))
.toList(),
)),
);
}
}

class NoCenterDemo extends StatelessWidget {
@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -217,6 +242,7 @@ class ComplicatedImageDemo extends StatelessWidget {
autoPlay: true,
aspectRatio: 2.0,
enlargeCenterPage: true,
withButtons: true,
),
items: imageSliders,
),
Expand Down Expand Up @@ -269,7 +295,10 @@ class _ManuallyControlledSliderState extends State<ManuallyControlledSlider> {
children: <Widget>[
CarouselSlider(
items: imageSliders,
options: CarouselOptions(enlargeCenterPage: true, height: 200),
options: CarouselOptions(
enlargeCenterPage: true,
height: 200,
),
carouselController: _controller,
),
Row(
Expand Down
9 changes: 9 additions & 0 deletions lib/carousel_options.dart
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,12 @@ class CarouselOptions {
/// Exposed clipBehavior of PageView
final Clip clipBehavior;

/// Whether to show previous/next buttons on the side of
/// the carousels or not.
///
/// Defaults to false.
final bool withButtons;

CarouselOptions({
this.height,
this.aspectRatio: 16 / 9,
Expand All @@ -132,6 +138,7 @@ class CarouselOptions {
this.enableInfiniteScroll: true,
this.reverse: false,
this.autoPlay: false,
this.withButtons: false,
this.autoPlayInterval: const Duration(seconds: 4),
this.autoPlayAnimationDuration = const Duration(milliseconds: 800),
this.autoPlayCurve: Curves.fastOutSlowIn,
Expand Down Expand Up @@ -161,6 +168,7 @@ class CarouselOptions {
bool? enableInfiniteScroll,
bool? reverse,
bool? autoPlay,
bool? withButtons,
Duration? autoPlayInterval,
Duration? autoPlayAnimationDuration,
Curve? autoPlayCurve,
Expand All @@ -186,6 +194,7 @@ class CarouselOptions {
enableInfiniteScroll: enableInfiniteScroll ?? this.enableInfiniteScroll,
reverse: reverse ?? this.reverse,
autoPlay: autoPlay ?? this.autoPlay,
withButtons: withButtons ?? this.withButtons,
autoPlayInterval: autoPlayInterval ?? this.autoPlayInterval,
autoPlayAnimationDuration:
autoPlayAnimationDuration ?? this.autoPlayAnimationDuration,
Expand Down
Loading