Esempio n. 1
0
        public override Widget build(BuildContext context)
        {
            Color         fixColor           = this.color ?? Colors.transparent;
            Color         fixSelectedColor   = this.selectedColor ?? Theme.of(context).accentColor;
            ColorTween    selectedColorTween = new ColorTween(begin: fixColor, end: fixSelectedColor);
            ColorTween    previousColorTween = new ColorTween(begin: fixSelectedColor, end: fixColor);
            TabController tabController      = this.controller ?? DefaultTabController.of(context);

            D.assert(() => {
                if (tabController == null)
                {
                    throw new UIWidgetsError(
                        "No TabController for " + this.GetType() + ".\n" +
                        "When creating a " + this.GetType() + ", you must either provide an explicit TabController " +
                        "using the \"controller\" property, or you must ensure that there is a " +
                        "DefaultTabController above the " + this.GetType() + ".\n" +
                        "In this case, there was neither an explicit controller nor a default controller."
                        );
                }

                return(true);
            });

            Animation <float> animation = new CurvedAnimation(
                parent: tabController.animation,
                curve: Curves.fastOutSlowIn
                );

            return(new AnimatedBuilder(
                       animation: animation,
                       builder: (BuildContext subContext, Widget child) => {
                List <Widget> children = new List <Widget>();

                for (int tabIndex = 0; tabIndex < tabController.length; tabIndex++)
                {
                    children.Add(this._buildTabIndicator(
                                     tabIndex,
                                     tabController,
                                     selectedColorTween,
                                     previousColorTween)
                                 );
                }

                return new Row(
                    mainAxisSize: MainAxisSize.min,
                    children: children
                    );
            }
                       ));
        }
Esempio n. 2
0
        void _updateTabController()
        {
            TabController newController = this.widget.controller ?? DefaultTabController.of(this.context);

            D.assert(() => {
                if (newController == null)
                {
                    throw new UIWidgetsError(
                        "No TabController for " + this.widget.GetType() + ".\n" +
                        "When creating a " + this.widget.GetType() + ", you must either provide an explicit " +
                        "TabController using the \"controller\" property, or you must ensure that there " +
                        "is a DefaultTabController above the " + this.widget.GetType() + ".\n" +
                        "In this case, there was neither an explicit controller nor a default controller."
                        );
                }

                return(true);
            });
            if (newController == this._controller)
            {
                return;
            }

            if (this._controller != null)
            {
                this._controller.animation.removeListener(this._handleTabControllerAnimationTick);
                this._controller.removeListener(this._handleTabControllerTick);
            }

            this._controller = newController;
            if (this._controller != null)
            {
                this._controller.animation.addListener(this._handleTabControllerAnimationTick);
                this._controller.addListener(this._handleTabControllerTick);
                this._currentIndex = this._controller.index;
            }
        }