public override void initState() { _transformer = widget.transformer; // int index = widget.index ?? 0; _pageController = widget.pageController; if (_pageController == null) { _pageController = new TransformerPageController( initialPage: widget.index, itemCount: widget.itemCount, loop: widget.loop, reverse: widget.transformer == null ? false : widget.transformer.reverse); } // int initPage = _getRealIndexFromRenderIndex(index); // _pageController = new PageController(initialPage: initPage,viewportFraction: widget.viewportFraction); _fromIndex = _activeIndex = _pageController.initialPage; _controller = getNotifier(); if (_controller != null) { _controller.addListener(onChangeNotifier); } base.initState(); }
public override void didUpdateWidget(StatefulWidget oldWidget) { _transformer = widget.transformer; int index = widget.index; bool created = false; if (_pageController != widget.pageController) { if (widget.pageController != null) { _pageController = widget.pageController; } else { created = true; _pageController = new TransformerPageController( initialPage: widget.index, itemCount: widget.itemCount, loop: widget.loop, reverse: widget.transformer == null ? false : widget.transformer.reverse); } } if (_pageController.getRenderIndexFromRealIndex(_activeIndex) != index) { _fromIndex = _activeIndex = _pageController.initialPage; if (!created) { int initPage = _pageController.getRealIndexFromRenderIndex(index); _pageController.animateToPage(initPage, duration: widget.duration, curve: widget.curve); } } if (_transformer != null) { WidgetsBinding.instance.addPostFrameCallback(_onGetSize); } if (_controller != getNotifier()) { if (_controller != null) { _controller.removeListener(onChangeNotifier); } _controller = getNotifier(); if (_controller != null) { _controller.addListener(onChangeNotifier); } } base.didUpdateWidget(oldWidget); }
public static TransformerPageView children( int index, TimeSpan?duration = null, Curve curve = null, Key key = null, ScrollPhysics physics = null, ValueChanged <int> onPageChanged = null, IndexController controller = null, TransformerPageController pageController = null, PageTransformer transformer = null, List <Widget> children = null, float viewportFraction = 1, bool pageSnapping = true, bool loop = false, Axis scrollDirection = Axis.horizontal ) { return(new TransformerPageView( itemCount: children.Count, itemBuilder: (BuildContext context, int ind) => { return children[ind]; }, pageController: pageController, transformer: transformer, pageSnapping: pageSnapping, key: key, index: index, duration: duration, curve: curve ?? Curves.ease, viewportFraction: viewportFraction, scrollDirection: scrollDirection, physics: physics, onPageChanged: onPageChanged, controller: controller )); }
/// Creates a scrollable list that works page by page using widgets that are /// created on demand. /// /// This constructor is appropriate for page views with a large (or infinite) /// number of children because the builder is called only for those children /// that are actually visible. /// /// Providing a non-null [itemCount] lets the [PageView] compute the maximum /// scroll extent. /// /// [itemBuilder] will be called only with indices greater than or equal to /// zero and less than [itemCount]. public TransformerPageView( int index, Curve curve, ScrollPhysics physics, ValueChanged <int> onPageChanged, IndexController controller, PageTransformer transformer, IndexedWidgetBuilder itemBuilder, TransformerPageController pageController, int itemCount, TimeSpan?duration = null, Key key = null, float viewportFraction = 1, Axis scrollDirection = Axis.horizontal, bool loop = false, bool pageSnapping = true ) : base(key: key) { this.index = index; this.curve = curve == null ? Curves.ease : curve; this.loop = loop; this.scrollDirection = scrollDirection; this.physics = physics; this.onPageChanged = onPageChanged; this.controller = controller; this.transformer = transformer; this.itemBuilder = itemBuilder; this.pageController = pageController; this.itemCount = itemCount; this.viewportFraction = viewportFraction; this.scrollDirection = scrollDirection; this.loop = loop; this.pageSnapping = pageSnapping; this.duration = duration ?? TimeSpan.FromMilliseconds(kDefaultTransactionDuration); }
Widget _buildSwiper() { IndexedWidgetBuilder itemBuilder; if (widget.onTap != null) { itemBuilder = _wrapTap; } else { itemBuilder = widget.itemBuilder; } if (widget.layout == SwiperLayout.STACK) { return(new _StackSwiper( loop: widget.loop, itemWidth: widget.itemWidth, itemHeight: widget.itemHeight, itemCount: widget.itemCount, itemBuilder: itemBuilder, index: _activeIndex, curve: widget.curve, duration: widget.duration, onIndexChanged: _onIndexChanged, controller: _controller, scrollDirection: widget.scrollDirection )); } else if (_isPageViewLayout()) { PageTransformer transformer = widget.transformer; if (widget.scale != 0 || widget.fade != 0) { transformer = new ScaleAndFadeTransformer(scale: widget.scale, fade: widget.fade); } Widget child = new TransformerPageView( pageController: _pageController, loop: widget.loop, itemCount: widget.itemCount, itemBuilder: itemBuilder, transformer: transformer, viewportFraction: widget.viewportFraction, index: _activeIndex, duration: TimeSpan.FromMilliseconds(widget.duration), scrollDirection: widget.scrollDirection, onPageChanged: _onIndexChanged, curve: widget.curve, physics: widget.physics, controller: _controller ); if (widget.autoplayDisableOnInteraction && widget.autoplay) { return(new NotificationListener <ScrollNotification>( child: child, onNotification: (ScrollNotification notification) => { ScrollStartNotification ssno = notification as ScrollStartNotification; if (ssno != null) { if (ssno.dragDetails != null) { //by human if (_timer != null) { _stopAutoplay(); } } } else if (notification is ScrollEndNotification) { if (_timer == null) { _startAutoplay(); } } return false; } )); } return(child); } else if (widget.layout == SwiperLayout.TINDER) { return(new _TinderSwiper( loop: widget.loop, itemWidth: widget.itemWidth, itemHeight: widget.itemHeight, itemCount: widget.itemCount, itemBuilder: itemBuilder, index: _activeIndex, curve: widget.curve, duration: widget.duration, onIndexChanged: _onIndexChanged, controller: _controller, scrollDirection: widget.scrollDirection )); } else if (widget.layout == SwiperLayout.CUSTOM) { return(new _CustomLayoutSwiper( loop: widget.loop, option: widget.customLayoutOption, itemWidth: widget.itemWidth, itemHeight: widget.itemHeight, itemCount: widget.itemCount, itemBuilder: itemBuilder, index: _activeIndex, curve: widget.curve, duration: widget.duration, onIndexChanged: _onIndexChanged, controller: _controller, scrollDirection: widget.scrollDirection )); } else { return(new Container()); } }
public static Swiper List( PageTransformer transformer, IList list, float containerHeight, float containerWidth, float itemHeight, float itemWidth, CustomLayoutOption customLayoutOption, SwiperDataBuilder builder, ValueChanged <int> onIndexChanged, Key key, int index, SwiperOnTap onTap, ScrollPhysics physics, Curve curve, float fade, SwiperPlugin pagination, SwiperPlugin control, List <SwiperPlugin> plugins, SwiperController controller, float viewportFraction = 1.0f, bool loop = true, int duration = kDefaultAutoplayTransactionDuration, Axis scrollDirection = Axis.horizontal, bool autoplay = false, int autoplayDelay = kDefaultAutoplayDelayMs, bool reverse = false, bool autoplayDisableOnInteraction = true, bool outer = false, float scale = 1.0f ) { return(new Swiper( transformer: transformer, customLayoutOption: customLayoutOption, containerHeight: containerHeight, containerWidth: containerWidth, viewportFraction: viewportFraction, itemHeight: itemHeight, itemWidth: itemWidth, outer: outer, scale: scale, autoplay: autoplay, autoplayDelay: autoplayDelay, autoplayDisableOnInteraction: autoplayDisableOnInteraction, duration: duration, onIndexChanged: onIndexChanged, index: index, onTap: onTap, curve: curve ?? Curves.ease, key: key, scrollDirection: scrollDirection, pagination: pagination, control: control, controller: controller, loop: loop, plugins: plugins, physics: physics, fade: fade, itemBuilder: (BuildContext context, int ind) => { return builder(context, list[ind], ind); }, itemCount: list.Count)); }
public static Swiper Children( Key key, IndexedWidgetBuilder itemBuilder, PageTransformer transformer, int itemCount, ValueChanged <int> onIndexChanged, int index, SwiperOnTap onTap, List <SwiperPlugin> plugins, SwiperPlugin control, ScrollPhysics physics, SwiperController controller, SwiperPlugin pagination, CustomLayoutOption customLayoutOption, List <Widget> children, /// since v1.0.0 float containerHeight, float containerWidth, float itemHeight, float itemWidth, float scale, float fade, /// Curve curve, float viewportFraction = 1.0f, bool autoplay = false, bool loop = true, Axis scrollDirection = Axis.horizontal, SwiperLayout layout = SwiperLayout.DEFAULT, int autoplayDelay = kDefaultAutoplayDelayMs, bool autoplayDisableOnInteraction = true, int duration = kDefaultAutoplayTransactionDuration, bool outer = false, PageIndicatorLayout indicatorLayout = PageIndicatorLayout.NONE, bool reverse = false ) { D.assert(children != null, () => "children must not be null"); return(new Swiper( transformer: transformer, customLayoutOption: customLayoutOption, containerHeight: containerHeight, containerWidth: containerWidth, viewportFraction: viewportFraction, itemHeight: itemHeight, itemWidth: itemWidth, outer: outer, scale: scale, fade: fade, autoplay: autoplay, autoplayDelay: autoplayDelay, autoplayDisableOnInteraction: autoplayDisableOnInteraction, duration: duration, onIndexChanged: onIndexChanged, index: index, onTap: onTap, curve: curve ?? Curves.ease, scrollDirection: scrollDirection, pagination: pagination, control: control, controller: controller, loop: loop, plugins: plugins, physics: physics, key: key, itemBuilder: (BuildContext context, int ind) => { return children[ind]; }, itemCount: children.Count)); }
public Swiper( IndexedWidgetBuilder itemBuilder, int itemCount, SwiperPlugin pagination, SwiperPlugin control, /// since v1.0.0 float containerHeight, float containerWidth, float itemHeight, float itemWidth, float scale = 1, float fade = 1, CustomLayoutOption customLayoutOption = null, SwiperController controller = null, PageTransformer transformer = null, int index = 0, List <SwiperPlugin> plugins = null, ValueChanged <int> onIndexChanged = null, ScrollPhysics physics = null, /// SwiperOnTap onTap = null, Curve curve = null, Key key = null, float viewportFraction = 1.0f, bool autoplay = false, bool loop = true, Axis scrollDirection = Axis.horizontal, SwiperLayout layout = SwiperLayout.DEFAULT, int autoplayDelay = kDefaultAutoplayDelayMs, bool autoplayDisableOnInteraction = true, int duration = kDefaultAutoplayTransactionDuration, bool outer = false, PageIndicatorLayout indicatorLayout = PageIndicatorLayout.NONE ) : base(key: key) { D.assert(itemBuilder != null || transformer != null, () => { return("itemBuilder and transformItemBuilder must not be both null"); }); D.assert( !loop || ((loop && layout == SwiperLayout.DEFAULT && (indicatorLayout == PageIndicatorLayout.SCALE || indicatorLayout == PageIndicatorLayout.COLOR || indicatorLayout == PageIndicatorLayout.NONE)) || (loop && layout != SwiperLayout.DEFAULT)), () => "Only support `PageIndicatorLayout.SCALE` and `PageIndicatorLayout.COLOR`when layout==SwiperLayout.DEFAULT in loop mode"); this.itemBuilder = itemBuilder; this.indicatorLayout = indicatorLayout; this.transformer = transformer; this.onIndexChanged = onIndexChanged; this.itemCount = itemCount; this.index = index; this.onTap = onTap; this.plugins = plugins; this.control = control; this.physics = physics; this.controller = controller; this.pagination = pagination; this.customLayoutOption = customLayoutOption; this.containerHeight = containerHeight; this.containerWidth = containerWidth; this.viewportFraction = viewportFraction; this.itemHeight = itemHeight; this.itemWidth = itemWidth; this.scale = scale; this.fade = fade; this.curve = curve ?? Curves.ease; this.autoplay = autoplay; this.loop = loop; this.scrollDirection = scrollDirection; this.layout = layout; this.autoplayDelay = autoplayDelay; this.autoplayDisableOnInteraction = autoplayDisableOnInteraction; this.duration = duration; this.outer = outer; }