Skip to content

Commit

Permalink
Merge pull request #4 from long1eu/master
Browse files Browse the repository at this point in the history
Add support for TabPageSelector
  • Loading branch information
Theo Bouwman authored Mar 7, 2018
2 parents d9214e0 + 7432d69 commit 46b97d1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 29 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
## [0.4.0+1]
* you can provide a TabController if you want to add a TabPageSelector

## [0.4.0]

* **API CHANGE**: must provide `ImageProvider` object instead of custom class
Expand Down
53 changes: 26 additions & 27 deletions lib/src/image_carousel.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ import 'dart:async';
import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter/widgets.dart';
import 'package:zoomable_image/zoomable_image.dart';

Expand All @@ -13,37 +12,31 @@ class ImageCarousel extends StatefulWidget {
final TargetPlatform platform;
final Duration interval;
final bool allowZoom;
final TabController tabController;
final BoxFit fit;

// Images will shrink according to the value of [height]
// If you prefer to use the Material or Cupertino style activity indicator set the [platform] parameter
// Set [interval] to let the carousel loop through each photo automatically
// Pinch to zoom will be turned on by default
ImageCarousel(this.imageProviders,
{this.height = 250.0,
this.platform,
this.interval,
this.allowZoom = true});
{this.height = 250.0, this.platform, this.interval, this.allowZoom = true, this.tabController, this.fit = BoxFit.cover});

@override
State createState() => new _ImageCarouselState();
}

class _ImageCarouselState extends State<ImageCarousel>
with SingleTickerProviderStateMixin {
class _ImageCarouselState extends State<ImageCarousel> with SingleTickerProviderStateMixin {
TabController _tabController;

@override
void initState() {
super.initState();
_tabController =
new TabController(vsync: this, length: widget.imageProviders.length);
_tabController = widget.tabController ?? new TabController(vsync: this, length: widget.imageProviders.length);

if (widget.interval != null) {
new Timer.periodic(widget.interval, (_) {
_tabController.animateTo(
_tabController.index == _tabController.length - 1
? 0
: ++_tabController.index);
_tabController.animateTo(_tabController.index == _tabController.length - 1 ? 0 : ++_tabController.index);
});
}
}
Expand All @@ -61,7 +54,7 @@ class _ImageCarouselState extends State<ImageCarousel>
child: new TabBarView(
controller: _tabController,
children: widget.imageProviders.map((ImageProvider provider) {
return new CarouselImageWidget(widget, provider);
return new CarouselImageWidget(widget, provider, widget.fit, widget.height);
}).toList(),
),
);
Expand All @@ -71,8 +64,10 @@ class _ImageCarouselState extends State<ImageCarousel>
class CarouselImageWidget extends StatefulWidget {
final ImageCarousel carousel;
final ImageProvider imageProvider;
final BoxFit fit;
final double height;

CarouselImageWidget(this.carousel, this.imageProvider);
CarouselImageWidget(this.carousel, this.imageProvider, this.fit, this.height);

@override
State createState() => new _CarouselImageState();
Expand All @@ -85,12 +80,17 @@ class _CarouselImageState extends State<CarouselImageWidget> {
if (platform == TargetPlatform.iOS) {
return new CupertinoActivityIndicator();
} else {
return new CircularProgressIndicator();
return new Container(
height: 40.0,
width: 40.0,
child: new CircularProgressIndicator(),
);
}
}

void _toZoomRoute() {
Widget scaffold = new Scaffold(
appBar: new AppBar(),
body: new Center(
child: new ZoomableImage(
widget.imageProvider,
Expand All @@ -101,14 +101,11 @@ class _CarouselImageState extends State<CarouselImageWidget> {

Navigator.of(context).push(
defaultTargetPlatform == TargetPlatform.iOS
? new CupertinoPageRoute(
builder: (BuildContext context) => scaffold)
: new MaterialPageRoute(
builder: (BuildContext context) => scaffold),
? new CupertinoPageRoute(builder: (BuildContext context) => scaffold, fullscreenDialog: true)
: new MaterialPageRoute(builder: (BuildContext context) => scaffold, fullscreenDialog: true),
);
}


@override
void initState() {
super.initState();
Expand All @@ -124,13 +121,15 @@ class _CarouselImageState extends State<CarouselImageWidget> {

@override
Widget build(BuildContext context) {
return new Center(
return new Container(
height: widget.height,
child: _loading
? _getIndicator(widget.carousel.platform == null
? defaultTargetPlatform
: widget.carousel.platform)
? _getIndicator(widget.carousel.platform == null ? defaultTargetPlatform : widget.carousel.platform)
: new GestureDetector(
child: new Image(image: widget.imageProvider),
child: new Image(
image: widget.imageProvider,
fit: widget.fit,
),
onTap: () {
if (widget.carousel.allowZoom) {
_toZoomRoute();
Expand All @@ -139,4 +138,4 @@ class _CarouselImageState extends State<CarouselImageWidget> {
),
);
}
}
}
3 changes: 1 addition & 2 deletions pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,10 @@ name: image_carousel
author: Theo Bouwman <theobouwman98@gmail.com>
homepage: https://github.com/theobouwman/flutter_image_carousel
description: A image carousel flutter plugin
version: 0.4.0
version: 0.4.0+1

dependencies:
zoomable_image: 1.1.2
cached_network_image: 0.1.0

flutter:
sdk: flutter
Expand Down

0 comments on commit 46b97d1

Please # to comment.