示例#1
0
 public override void initState()
 {
     base.initState();
     StatusBarManager.statusBarStyle(false);
     this._selectedIndex          = 1;
     this._tabController          = new CustomTabController(2, this, initialIndex: this._selectedIndex);
     this._navBarHeight           = CustomAppBarUtil.appBarHeight;
     this._isRefresh              = false;
     this._recommendArticlePixels = 0;
     this._followArticlePixels    = 0;
     this._loginSubId             = EventBus.subscribe(sName: EventBusConstant.login_success, args => {
         if (this._selectedIndex != 1)
         {
             this._selectedIndex = 1;
             this._tabController.animateTo(value: this._selectedIndex);
         }
     });
     this._logoutSubId = EventBus.subscribe(sName: EventBusConstant.logout_success, args => {
         if (this._selectedIndex != 1)
         {
             this._selectedIndex = 1;
             this._tabController.animateTo(value: this._selectedIndex);
         }
     });
 }
示例#2
0
 public override void initState()
 {
     base.initState();
     this._emojiTabController = new CustomTabController(
         (emojiList.Count - 1) / emojiBoardPageSize + 1,
         this
         );
 }
示例#3
0
        Widget _buildTabIndicator(
            int tabIndex,
            CustomTabController tabController,
            ColorTween selectedColorTween,
            ColorTween previousColorTween)
        {
            Color background;

            if (tabController.indexIsChanging)
            {
                float t = 1.0f - CustomTabsUtils._indexChangeProgress(controller: tabController);
                if (tabController.index == tabIndex)
                {
                    background = selectedColorTween.lerp(t: t);
                }
                else if (tabController.previousIndex == tabIndex)
                {
                    background = previousColorTween.lerp(t: t);
                }
                else
                {
                    background = selectedColorTween.begin;
                }
            }
            else
            {
                float offset = tabController.offset;
                if (tabController.index == tabIndex)
                {
                    background = selectedColorTween.lerp(1.0f - offset.abs());
                }
                else if (tabController.index == tabIndex - 1 && offset > 0.0)
                {
                    background = selectedColorTween.lerp(t: offset);
                }
                else if (tabController.index == tabIndex + 1 && offset < 0.0)
                {
                    background = selectedColorTween.lerp(t: -offset);
                }
                else
                {
                    background = selectedColorTween.begin;
                }
            }

            return(new CustomTabPageSelectorIndicator(
                       backgroundColor: background,
                       borderColor: background,
                       size: this.indicatorSize
                       ));
        }
示例#4
0
        public override Widget build(BuildContext context)
        {
            Color               fixColor           = this.color ?? CColors.Transparent;
            Color               fixSelectedColor   = this.selectedColor ?? CColors.PrimaryBlue;
            ColorTween          selectedColorTween = new ColorTween(begin: fixColor, end: fixSelectedColor);
            ColorTween          previousColorTween = new ColorTween(begin: fixSelectedColor, end: fixColor);
            CustomTabController tabController      = this.controller;

            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: (subContext, child) => {
                List <Widget> children = new List <Widget>();

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

                return new Row(
                    mainAxisSize: MainAxisSize.min,
                    children: children
                    );
            }
                       ));
        }
示例#5
0
 public CustomTabPageSelector(
     Key key = null,
     CustomTabController controller = null,
     float indicatorSize            = 12.0f,
     Color color         = null,
     Color selectedColor = null
     ) : base(key: key)
 {
     D.assert(indicatorSize > 0.0f);
     this.controller    = controller;
     this.indicatorSize = indicatorSize;
     this.color         = color;
     this.selectedColor = selectedColor;
 }
示例#6
0
 public override void initState()
 {
     base.initState();
     this._currentIndex = this.widget.currentIndex;
     this._controller   = this.widget.controller
                          ?? new CustomTabController(length: this.widget.children.Count, this);
     this._controller.addListener(() => {
         if (this._controller.index != this._currentIndex)
         {
             this._currentIndex = this._controller.index;
             this.widget.onValueChanged?.Invoke(value: this._currentIndex);
         }
     });
     this._controller.index = this.widget.currentIndex;
 }
示例#7
0
 public override void initState()
 {
     base.initState();
     StatusBarManager.statusBarStyle(true);
     this._selectedIndex = this.widget.viewModel.initIndex;
     this._tabController = new CustomTabController(
         length: this.tabTitles.Count,
         this,
         initialIndex: this._selectedIndex
         );
     this._scrollController = new ScrollController();
     this._isHaveTitle      = true;
     this._tabController.addListener(() => {
         if (this._tabController.index != this._selectedIndex)
         {
             this.setState(() => this._selectedIndex = this._tabController.index);
         }
     });
     LocalDataManager.markLeaderBoardUpdatedTime();
 }
示例#8
0
 public override void initState()
 {
     base.initState();
     StatusBarManager.statusBarStyle(false);
     this._selectedIndex = 1;
     this._tabController = new CustomTabController(2, this, initialIndex: this._selectedIndex);
     this._titleFontSize = _maxTitleFontSize;
     this._navBarHeight  = _maxNavBarHeight;
     this._loginSubId    = EventBus.subscribe(sName: EventBusConstant.login_success, args => {
         if (this._selectedIndex != 1)
         {
             this._selectedIndex = 1;
             this._tabController.animateTo(value: this._selectedIndex);
         }
     });
     this._logoutSubId = EventBus.subscribe(sName: EventBusConstant.logout_success, args => {
         if (this._selectedIndex != 1)
         {
             this._selectedIndex = 1;
             this._tabController.animateTo(value: this._selectedIndex);
         }
     });
 }
示例#9
0
 public CustomSegmentedControl(
     List <object> items,
     List <Widget> children,
     ValueChanged <int> onValueChanged = null,
     int currentIndex               = 0,
     float headerHeight             = 44,
     Widget trailing                = null,
     Decoration headerDecoration    = null,
     Decoration indicator           = null,
     EdgeInsets headerPadding       = null,
     EdgeInsets labelPadding        = null,
     float?indicatorWidth           = null,
     Color unselectedColor          = null,
     Color selectedColor            = null,
     TextStyle unselectedTextStyle  = null,
     TextStyle selectedTextStyle    = null,
     CustomTabController controller = null,
     ScrollPhysics physics          = null,
     ValueChanged <int> onTap       = null,
     Key key = null
     ) : base(key: key)
 {
     D.assert(items != null);
     D.assert(items.Count >= 2);
     D.assert(children != null);
     D.assert(children.Count >= 2);
     D.assert(children.Count == items.Count);
     D.assert(currentIndex < children.Count);
     this.items            = items;
     this.children         = children;
     this.onValueChanged   = onValueChanged;
     this.unselectedColor  = unselectedColor ?? CColors.TextTitle;
     this.selectedColor    = selectedColor ?? CColors.PrimaryBlue;
     this.currentIndex     = currentIndex;
     this.headerHeight     = headerHeight;
     this.trailing         = trailing;
     this.headerDecoration = headerDecoration ?? new BoxDecoration(
         color: CColors.White,
         border: new Border(bottom: new BorderSide(color: CColors.Separator2))
         );
     this.indicator = indicator ?? new CustomUnderlineTabIndicator(
         insets: EdgeInsets.zero,
         borderSide: new BorderSide(width: 2, color: CColors.PrimaryBlue)
         );
     this.headerPadding       = headerPadding ?? EdgeInsets.zero;
     this.labelPadding        = labelPadding ?? EdgeInsets.symmetric(horizontal: 16, vertical: 10);
     this.indicatorWidth      = indicatorWidth;
     this.unselectedTextStyle = unselectedTextStyle ?? new TextStyle(
         fontSize: 16,
         fontFamily: "Roboto-Regular",
         color: this.unselectedColor
         );
     this.selectedTextStyle = selectedTextStyle ?? new TextStyle(
         fontSize: 16,
         fontFamily: "Roboto-Medium",
         color: this.unselectedColor
         );
     this.controller = controller;
     this.physics    = physics;
     this.onTap      = onTap;
 }