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);
        }
示例#2
0
        public override void initState()
        {
            this._activeIndex = this.widget.index ?? 0;
            if (this._isPageViewLayout())
            {
                this._pageController = new TransformerPageController(
                    initialPage: this.widget.index,
                    loop: this.widget.loop,
                    itemCount: this.widget.itemCount,
                    reverse: this.widget.transformer == null ? false : this.widget.transformer.reverse,
                    viewportFraction: this.widget.viewportFraction);
            }

            base.initState();
        }
        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;
 }
示例#5
0
        public override void didUpdateWidget(StatefulWidget _oldWidget)
        {
            Swiper oldWidget = _oldWidget as Swiper;

            base.didUpdateWidget(oldWidget);
            if (this._isPageViewLayout())
            {
                if (this._pageController == null ||
                    (this.widget.index != oldWidget.index || this.widget.loop != oldWidget.loop ||
                     this.widget.itemCount != oldWidget.itemCount ||
                     this.widget.viewportFraction != oldWidget.viewportFraction ||
                     this._getReverse(this.widget) != this._getReverse(oldWidget)))
                {
                    this._pageController = new TransformerPageController(
                        initialPage: this.widget.index,
                        loop: this.widget.loop,
                        itemCount: this.widget.itemCount,
                        reverse: this._getReverse(this.widget),
                        viewportFraction: this.widget.viewportFraction);
                }
            }
            else
            {
                Window.instance.scheduleMicrotask(() => {
                    if (this._pageController != null)
                    {
                        this._pageController.dispose();
                        this._pageController = null;
                    }
                });
            }

            if (this.widget.index != null && this.widget.index != this._activeIndex)
            {
                this._activeIndex = this.widget.index.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
                ));
 }