public override void didUpdateWidget(StatefulWidget _oldWidget) { TransformerPageView oldWidget = _oldWidget as TransformerPageView; this._transformer = this.widget.transformer; int index = this.widget.index ?? 0; bool created = false; if (this._pageController != this.widget.pageController) { if (this.widget.pageController != null) { this._pageController = this.widget.pageController; } else { created = true; this._pageController = new TransformerPageController( initialPage: this.widget.index, itemCount: this.widget.itemCount, loop: this.widget.loop, reverse: this.widget.transformer?.reverse ?? false); } } if (this._pageController.getRenderIndexFromRealIndex(this._activeIndex) != index) { this._fromIndex = this._activeIndex = this._pageController.initialPage; if (!created) { int initPage = this._pageController.getRealIndexFromRenderIndex(index); this._pageController.animateToPage(initPage, duration: this.widget.duration.Value, curve: this.widget.curve); } } if (this._transformer != null) { WidgetsBinding.instance.addPostFrameCallback(this._onGetSize); } if (this._controller != this.getNotifier()) { this._controller?.removeListener(this.onChangeNotifier); this._controller = this.getNotifier(); this._controller?.addListener(this.onChangeNotifier); } base.didUpdateWidget(oldWidget); }
public override void initState() { this._transformer = this.widget.transformer; this._pageController = this.widget.pageController; if (this._pageController == null) { this._pageController = new TransformerPageController( initialPage: this.widget.index, itemCount: this.widget.itemCount, loop: this.widget.loop, reverse: this.widget.transformer?.reverse ?? false); } this._fromIndex = this._activeIndex = this._pageController.initialPage; this._controller = this.getNotifier(); this._controller?.addListener(this.onChangeNotifier); base.initState(); }
public TransformerPageView( Key key = null, int?index = null, TimeSpan?duration = null, Curve curve = null, float viewportFraction = 1.0f, bool loop = false, Axis scrollDirection = Axis.horizontal, ScrollPhysics physics = null, bool pageSnapping = true, ValueChanged <int> onPageChanged = null, IndexController controller = null, PageTransformer transformer = null, IndexedWidgetBuilder itemBuilder = null, TransformerPageController pageController = null, int?itemCount = null ) : base(key: key) { D.assert(itemCount != null); D.assert(itemCount == 0 || itemBuilder != null || transformer != null); this.duration = duration ?? TimeSpan.FromMilliseconds(TransformerPageViewUtils.kDefaultTransactionDuration); this.index = index; this.duration = duration; this.curve = curve ?? Curves.ease; this.viewportFraction = viewportFraction; this.loop = loop; this.scrollDirection = scrollDirection; this.physics = physics; this.pageSnapping = pageSnapping; this.onPageChanged = onPageChanged; this.controller = controller; this.transformer = transformer; this.itemBuilder = itemBuilder; this.pageController = pageController; this.itemCount = itemCount.Value; }
public static TransformerPageView children( Key key = null, int?index = null, TimeSpan?duration = null, Curve curve = null, float viewportFraction = 1.0f, bool loop = false, Axis scrollDirection = Axis.horizontal, ScrollPhysics physics = null, bool pageSnapping = true, ValueChanged <int> onPageChanged = null, IndexController controller = null, PageTransformer transformer = null, List <Widget> children = null, TransformerPageController pageController = null ) { D.assert(children != null); return(new TransformerPageView( itemCount: children.Count, itemBuilder: (context, _index) => children[index: _index], pageController: pageController, transformer: transformer, pageSnapping: pageSnapping, key: key, index: index, duration: duration, curve: curve, viewportFraction: viewportFraction, loop: loop, scrollDirection: scrollDirection, physics: physics, onPageChanged: onPageChanged, controller: controller )); }
Widget _buildSwiper() { IndexedWidgetBuilder itemBuilder = this.widget.onTap != null ? this._wrapTap : this.widget.itemBuilder; if (this.widget.layout == SwiperLayout.stack) { return(new _StackSwiper( loop: this.widget.loop, itemWidth: this.widget.itemWidth, itemHeight: this.widget.itemHeight, itemCount: this.widget.itemCount, itemBuilder: itemBuilder, index: this._activeIndex, curve: this.widget.curve, duration: this.widget.duration, onIndexChanged: this._onIndexChanged, controller: this._controller, scrollDirection: this.widget.scrollDirection )); } else if (this._isPageViewLayout()) { PageTransformer transformer = this.widget.transformer; if (this.widget.scale != null || this.widget.fade != null) { transformer = new ScaleAndFadeTransformer(scale: this.widget.scale, fade: this.widget.fade); } Widget child = new TransformerPageView( pageController: this._pageController, loop: this.widget.loop, itemCount: this.widget.itemCount, itemBuilder: itemBuilder, transformer: transformer, viewportFraction: this.widget.viewportFraction, index: this._activeIndex, duration: TimeSpan.FromMilliseconds(this.widget.duration), scrollDirection: this.widget.scrollDirection, onPageChanged: this._onIndexChanged, curve: this.widget.curve, physics: this.widget.physics, controller: this._controller ); if (this.widget.autoplayDisableOnInteraction && this.widget.autoplay) { return(new NotificationListener <ScrollNotification>( child: child, onNotification: notification => { if (notification is ScrollStartNotification scrollStartNotification) { if (scrollStartNotification.dragDetails != null) { if (this._timer != null) { this._stopAutoplay(); } } } else if (notification is ScrollEndNotification) { if (this._timer == null) { this._startAutoplay(); } } return false; } )); } return(child); } else if (this.widget.layout == SwiperLayout.tinder) { return(new _TinderSwiper( loop: this.widget.loop, itemWidth: this.widget.itemWidth, itemHeight: this.widget.itemHeight, itemCount: this.widget.itemCount, itemBuilder: itemBuilder, index: this._activeIndex, curve: this.widget.curve, duration: this.widget.duration, onIndexChanged: this._onIndexChanged, controller: this._controller, scrollDirection: this.widget.scrollDirection )); } else if (this.widget.layout == SwiperLayout.custom) { return(new _CustomLayoutSwiper( loop: this.widget.loop, option: this.widget.customLayoutOption, itemWidth: this.widget.itemWidth, itemHeight: this.widget.itemHeight, itemCount: this.widget.itemCount, itemBuilder: itemBuilder, index: this._activeIndex, curve: this.widget.curve, duration: this.widget.duration, onIndexChanged: this._onIndexChanged, controller: this._controller, scrollDirection: this.widget.scrollDirection )); } else { return(new Container()); } }
public Swiper( IndexedWidgetBuilder itemBuilder = null, PageIndicatorLayout indicatorLayout = PageIndicatorLayout.none, PageTransformer transformer = null, int?itemCount = null, bool autoplay = false, SwiperLayout layout = SwiperLayout.normal, int autoplayDelay = SwiperUtils.kDefaultAutoplayDelayMs, bool autoplayDisableOnInteraction = true, int duration = SwiperUtils.kDefaultAutoplayTransactionDuration, ValueChanged <int> onIndexChanged = null, int?index = null, SwiperOnTap onTap = null, SwiperPlugin control = null, bool loop = true, Curve curve = null, Axis scrollDirection = Axis.horizontal, SwiperPlugin pagination = null, List <SwiperPlugin> plugins = null, ScrollPhysics physics = null, Key key = null, SwiperController controller = null, CustomLayoutOption customLayoutOption = null, float?containerHeight = null, float?containerWidth = null, float viewportFraction = 1.0f, float?itemHeight = null, float?itemWidth = null, bool?outer = false, float?scale = null, float?fade = null ) : base(key: key) { D.assert(itemBuilder != null || transformer != null, () => "itemBuilder and transformItemBuilder must not be both null"); D.assert(!loop || ((loop && layout == SwiperLayout.normal && (indicatorLayout == PageIndicatorLayout.scale || indicatorLayout == PageIndicatorLayout.color || indicatorLayout == PageIndicatorLayout.none)) || (loop && layout != SwiperLayout.normal)), () => "Only support `PageIndicatorLayout.SCALE` and `PageIndicatorLayout.COLOR`when layout==SwiperLayout.DEFAULT in loop mode" ); this.itemBuilder = itemBuilder; this.indicatorLayout = indicatorLayout; this.transformer = transformer; this.itemCount = itemCount; this.autoplay = autoplay; this.layout = layout; this.autoplayDelay = autoplayDelay; this.autoplayDisableOnInteraction = autoplayDisableOnInteraction; this.duration = duration; this.onIndexChanged = onIndexChanged; this.index = index; this.onTap = onTap; this.control = control; this.loop = loop; this.curve = curve ?? Curves.ease; this.scrollDirection = scrollDirection; this.pagination = pagination; this.plugins = plugins; this.physics = physics; this.controller = controller; this.customLayoutOption = customLayoutOption; this.containerHeight = containerHeight; this.containerWidth = containerWidth; this.viewportFraction = viewportFraction; this.itemHeight = itemHeight; this.itemWidth = itemWidth; this.outer = outer; this.scale = scale; this.fade = fade; }