Skip to content

Commit

Permalink
fix #3
Browse files Browse the repository at this point in the history
1、change customer layout ,add widget Center as parent
2、fix #3
  • Loading branch information
jzoom committed Jul 11, 2018
1 parent ba0eedf commit 2e5c566
Show file tree
Hide file tree
Showing 9 changed files with 109 additions and 248 deletions.
8 changes: 0 additions & 8 deletions .idea/libraries/Dart_Packages.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

265 changes: 75 additions & 190 deletions .idea/workspace.xml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -213,7 +213,7 @@ The `Controller` is used to control the `index` of the Swiper, start or stop aut

| Parameter | Default | Description |
| :------------ |:---------------:| :-----|
| autoplayDely | 3000 | Autoplay delay milliseconds. |
| autoplayDelay | 3000 | Autoplay delay milliseconds. |
| autoplayDiableOnInteraction | true | Disable autoplay when user drag. |


Expand Down
1 change: 0 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ class MyApp extends StatelessWidget {
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Swiper'),

routes: {
'/example01': (BuildContext context) => ExampleHorizontal(),
'/example02': (BuildContext context) => ExampleVertical(),
Expand Down
2 changes: 1 addition & 1 deletion example/lib/src/ExampleCustom.dart
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ class _ExampleCustomState extends State<ExampleCustom> {
outer: _outer,
itemHeight: 200.0,
viewportFraction: _viewportFraction,
autoplayDely: _autoplayDely,
autoplayDelay: _autoplayDely,
loop: _loop,
autoplay: _autoplay,
itemBuilder: _buildItem,
Expand Down
7 changes: 0 additions & 7 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,6 @@ packages:
url: "https://pub.flutter-io.cn"
source: hosted
version: "1.0.3"
carousel_slider:
dependency: "direct main"
description:
name: carousel_slider
url: "https://pub.flutter-io.cn"
source: hosted
version: "0.0.5"
charcode:
dependency: transitive
description:
Expand Down
1 change: 0 additions & 1 deletion example/pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ dependencies:
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.0
carousel_slider: 0.0.5

flutter_swiper:
path: ../
Expand Down
1 change: 1 addition & 0 deletions flutter_swiper.iml
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
<excludeFolder url="file://$MODULE_DIR$/example/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
<excludeFolder url="file://$MODULE_DIR$/example/build" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/Flutter/flutter_assets/packages" />
</content>
<orderEntry type="jdk" jdkName="Android API 25 Platform" jdkType="Android SDK" />
<orderEntry type="sourceFolder" forTests="false" />
Expand Down
70 changes: 31 additions & 39 deletions lib/src/swiper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -44,8 +44,8 @@ class Swiper extends StatefulWidget {
///auto play config
final bool autoplay;

///Delay between auto play transitions (in millisecond).
final int autoplayDely;
///Duration of the animation between transactions (in millisecond).
final int autoplayDelay;

///disable auto play when interaction
final bool autoplayDiableOnInteraction;
Expand Down Expand Up @@ -82,9 +82,6 @@ class Swiper extends StatefulWidget {
///other plugins, you can cutom your own plugin
final List<SwiperPlugin> plugins;

/// decoration of inner swiper
final BoxDecoration decoration;

///
final SwiperController controller;

Expand All @@ -102,9 +99,8 @@ class Swiper extends StatefulWidget {
@required this.itemBuilder,
@required this.itemCount,
this.autoplay: false,
this.decoration,
this.layout,
this.autoplayDely: kDefaultAutoplayDelayMs,
this.autoplayDelay: kDefaultAutoplayDelayMs,
this.reverse: false,
this.autoplayDiableOnInteraction: true,
this.duration: kDefaultAutopayTransactionDuration,
Expand Down Expand Up @@ -169,7 +165,7 @@ class Swiper extends StatefulWidget {
outer: outer,
scale: scale,
autoplay: autoplay,
autoplayDely: autoplayDely,
autoplayDelay: autoplayDely,
autoplayDiableOnInteraction: autoplayDiableOnInteraction,
reverse: reverse,
duration: duration,
Expand Down Expand Up @@ -228,7 +224,7 @@ class Swiper extends StatefulWidget {
outer: outer,
scale: scale,
autoplay: autoplay,
autoplayDely: autoplayDely,
autoplayDelay: autoplayDely,
autoplayDiableOnInteraction: autoplayDiableOnInteraction,
reverse: reverse,
duration: duration,
Expand Down Expand Up @@ -333,7 +329,7 @@ abstract class _SwiperTimerMixin extends State<Swiper> {
void _startAutoplay() {
assert(_timer == null, "Timer must be stopped before start!");
_timer =
Timer.periodic(Duration(milliseconds: widget.autoplayDely), _onTimer);
Timer.periodic(Duration(milliseconds: widget.autoplayDelay), _onTimer);
}

void _onTimer(Timer timer) {
Expand Down Expand Up @@ -579,7 +575,8 @@ class _TinderSwiper extends _SubSwiper {
IndexedWidgetBuilder itemBuilder,
int index,
int itemCount})
: assert(itemWidth != null && itemHeight != null), super(
: assert(itemWidth != null && itemHeight != null),
super(
key: key,
itemWidth: itemWidth,
itemHeight: itemHeight,
Expand Down Expand Up @@ -673,24 +670,18 @@ class _TinderState extends _CustomLayoutStateBase<_TinderSwiper> {
List<double> opacity;
List<double> rotates;

double getOffsetY(double scale){
double getOffsetY(double scale) {
return widget.itemHeight - widget.itemHeight * scale;
}

@override
void didChangeDependencies() {
super.didChangeDependencies();
_startIndex = -3;
_animationCount = 5;
opacity = [0.0, 0.9, 0.9, 1.0, 0.0, 0.0];
scales = [0.80, 0.80, 0.85, 0.90, 1.0, 1.0, 1.0];
offsetsX = [
0.0,
0.0,
0.0,
0.0,
_screenWidth,
_screenWidth
];
offsetsX = [0.0, 0.0, 0.0, 0.0, _screenWidth, _screenWidth];
offsetsY = [
0.0,
0.0,
Expand All @@ -710,26 +701,24 @@ class _TinderState extends _CustomLayoutStateBase<_TinderSwiper> {
double o = _getValue(opacity, animationValue, i);
double a = _getValue(rotates, animationValue, i);

return new Center(
child: new Opacity(
opacity: o,
child: new Transform.rotate(
angle: a / 180.0,
child: new Transform.translate(
key: new ValueKey<int>(_currentIndex + i),
offset: new Offset(f, fy),
child: new Transform.scale(
scale: s,
alignment: Alignment.bottomCenter,
child: new SizedBox(
width: widget.itemWidth ?? double.infinity,
height: widget.itemHeight ?? double.infinity,
child: widget.itemBuilder(context, realIndex),
),
),
return new Opacity(
opacity: o,
child: new Transform.rotate(
angle: a / 180.0,
child: new Transform.translate(
key: new ValueKey<int>(_currentIndex + i),
offset: new Offset(f, fy),
child: new Transform.scale(
scale: s,
alignment: Alignment.bottomCenter,
child: new SizedBox(
width: widget.itemWidth ?? double.infinity,
height: widget.itemHeight ?? double.infinity,
child: widget.itemBuilder(context, realIndex),
),
),
),
),
);
}
}
Expand All @@ -749,7 +738,7 @@ class _StackViewState extends _CustomLayoutStateBase<_StackSwiper> {
//Array below this line, '0' index is 1.0 ,witch is the first item show in swiper.
_startIndex = -3;
scales = [0.7, 0.8, 0.9, 1.0, 1.0];
offsets = [0.0, space / 3, space / 3 * 2, space, _screenWidth];
offsets = [-space, -space / 3 * 2, -space / 3, 0.0, _screenWidth];
opacity = [0.0, 0.5, 1.0, 1.0, 1.0];
}

Expand Down Expand Up @@ -865,10 +854,13 @@ abstract class _CustomLayoutStateBase<T extends _SubSwiper> extends State<T>
}

return new GestureDetector(
behavior: HitTestBehavior.opaque,
onPanStart: _onPanStart,
onPanEnd: _onPanEnd,
onPanUpdate: _onPanUpdate,
child: _buildContainer(list),
child: new Center(
child: _buildContainer(list),
),
);
}

Expand Down

0 comments on commit 2e5c566

Please sign in to comment.