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

- make autoplayDelay can change in onIndexChange #183

Open
wants to merge 2 commits 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
6 changes: 6 additions & 0 deletions example/lib/InnerSwiper.dart
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ class InnerSwiper extends StatefulWidget {

class _InnerSwiperState extends State<InnerSwiper> {
SwiperController controller;
int autoPlayDelay = 3000;

List<bool> autoplayes;

Expand Down Expand Up @@ -60,6 +61,11 @@ class _InnerSwiperState extends State<InnerSwiper> {
child: new Text("jkfjkldsfjd"),
);
},
onIndexChanged: (i) {
setState(() {
autoPlayDelay = autoPlayDelay * i;
});
},
autoplay: autoplayes[index],
),
height: 300.0,
Expand Down
123 changes: 86 additions & 37 deletions example/pubspec.lock
Original file line number Diff line number Diff line change
@@ -1,41 +1,69 @@
# Generated by pub
# See https://www.dartlang.org/tools/pub/glossary#lockfile
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description:
name: archive
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.11"
args:
dependency: transitive
description:
name: args
url: "https://pub.dartlang.org"
source: hosted
version: "1.5.2"
async:
dependency: transitive
description:
name: async
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
version: "2.4.0"
boolean_selector:
dependency: transitive
description:
name: boolean_selector
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
version: "1.0.5"
charcode:
dependency: transitive
description:
name: charcode
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.2"
collection:
dependency: transitive
description:
name: collection
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.14.11"
convert:
dependency: transitive
description:
name: convert
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.1"
crypto:
dependency: transitive
description:
name: crypto
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.3"
cupertino_icons:
dependency: "direct main"
description:
name: cupertino_icons
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.2"
version: "0.1.3"
flutter:
dependency: "direct main"
description: flutter
Expand All @@ -45,7 +73,7 @@ packages:
dependency: transitive
description:
name: flutter_page_indicator
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.3"
flutter_swiper:
Expand All @@ -54,47 +82,61 @@ packages:
path: ".."
relative: true
source: path
version: "1.1.5"
version: "1.1.6"
flutter_test:
dependency: "direct dev"
description: flutter
source: sdk
version: "0.0.0"
image:
dependency: transitive
description:
name: image
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.4"
matcher:
dependency: transitive
description:
name: matcher
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "0.12.3+1"
version: "0.12.6"
meta:
dependency: transitive
description:
name: meta
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
version: "1.1.8"
path:
dependency: transitive
description:
name: path
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.2"
version: "1.6.4"
percent_indicator:
dependency: "direct main"
description:
name: percent_indicator
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.9"
version: "2.1.1+1"
petitparser:
dependency: transitive
description:
name: petitparser
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
quiver:
dependency: transitive
description:
name: quiver
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.1"
version: "2.0.5"
sky_engine:
dependency: transitive
description: flutter
Expand All @@ -104,65 +146,72 @@ packages:
dependency: transitive
description:
name: source_span
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.4.1"
version: "1.5.5"
stack_trace:
dependency: transitive
description:
name: stack_trace
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.9.3"
stream_channel:
dependency: transitive
description:
name: stream_channel
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.8"
version: "2.0.0"
string_scanner:
dependency: transitive
description:
name: string_scanner
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.4"
version: "1.0.5"
term_glyph:
dependency: transitive
description:
name: term_glyph
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
version: "1.1.0"
test_api:
dependency: transitive
description:
name: test_api
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "0.2.1"
version: "0.2.14"
transformer_page_view:
dependency: transitive
description:
name: transformer_page_view
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.5"
version: "0.1.6"
typed_data:
dependency: transitive
description:
name: typed_data
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "1.1.6"
vector_math:
dependency: transitive
description:
name: vector_math
url: "https://pub.flutter-io.cn"
url: "https://pub.dartlang.org"
source: hosted
version: "2.0.8"
xml:
dependency: transitive
description:
name: xml
url: "https://pub.dartlang.org"
source: hosted
version: "3.5.0"
sdks:
dart: ">=2.0.0 <3.0.0"
dart: ">=2.4.0 <3.0.0"
flutter: ">=0.1.4 <3.0.0"
17 changes: 10 additions & 7 deletions lib/src/swiper.dart
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
import 'package:flutter/material.dart';
import 'dart:async';

import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_page_indicator/flutter_page_indicator.dart';
import 'package:flutter_swiper/flutter_swiper.dart';
import 'dart:async';

import 'package:transformer_page_view/transformer_page_view.dart';

part 'custom_layout.dart';
Expand Down Expand Up @@ -48,13 +48,13 @@ class Swiper extends StatefulWidget {
/// count of the display items
final int itemCount;

final ValueChanged<int> onIndexChanged;
final Function(int) onIndexChanged;

///auto play config
final bool autoplay;

///Duration of the animation between transactions (in millisecond).
final int autoplayDelay;
int autoplayDelay;

///disable auto play when interaction
final bool autoplayDisableOnInteraction;
Expand Down Expand Up @@ -285,7 +285,7 @@ class Swiper extends StatefulWidget {

@override
State<StatefulWidget> createState() {
return new _SwiperState();
return new _SwiperState(delay: this.autoplayDelay);
}
}

Expand Down Expand Up @@ -380,7 +380,8 @@ abstract class _SwiperTimerMixin extends State<Swiper> {

class _SwiperState extends _SwiperTimerMixin {
int _activeIndex;

int delay;
_SwiperState({this.delay});
TransformerPageController _pageController;

Widget _wrapTap(BuildContext context, int index) {
Expand Down Expand Up @@ -456,6 +457,8 @@ class _SwiperState extends _SwiperTimerMixin {
_activeIndex = index;
});
if (widget.onIndexChanged != null) {
_stopAutoplay();
_startAutoplay();
widget.onIndexChanged(index);
}
}
Expand Down
Loading