Beispiel #1
0
        public override Widget build(BuildContext context)
        {
            SyntaxHighlighterStyle style = Theme.of(context).brightness == Brightness.dark
                ? SyntaxHighlighterStyle.darkThemeStyle()
                : SyntaxHighlighterStyle.lightThemeStyle();

            Widget body;

            if (this._exampleCode == null)
            {
                body = new Center(
                    child: new CircularProgressIndicator()
                    );
            }
            else
            {
                body = new SingleChildScrollView(
                    child: new Padding(
                        padding: EdgeInsets.all(16.0f),
                        child: new RichText(
                            text: new TextSpan(
                                style: new TextStyle(fontFamily: "monospace", fontSize: 10.0f),
                                children: new List <TextSpan> {
                    new DartSyntaxHighlighter(style).format(this._exampleCode)
                }
                                )
                            )
                        )
                    );
            }

            return(new Scaffold(
                       appBar: new AppBar(
                           leading: new IconButton(
                               icon: new Icon(
                                   Icons.clear
                                   ),
                               onPressed: () => { Navigator.pop(context); }
                               ),
                           title: new Text("Example code")
                           ),
                       body: body
                       ));
        }
Beispiel #2
0
        public override Widget build(BuildContext context)
        {
            D.assert(MaterialD.debugCheckHasMaterialLocalizations(context));

            if (this._controller.length == 0)
            {
                return(new Container(
                           height: TabsUtils._kTabHeight + this.widget.indicatorWeight
                           ));
            }

            List <Widget> wrappedTabs = new List <Widget>();

            for (int i = 0; i < this.widget.tabs.Count; i++)
            {
                wrappedTabs.Add(new Center(
                                    heightFactor: 1.0f,
                                    child: new Padding(
                                        padding: this.widget.labelPadding ?? Constants.kTabLabelPadding,
                                        child: new KeyedSubtree(
                                            key: this._tabKeys[i],
                                            child: this.widget.tabs[i]
                                            )
                                        )
                                    )
                                );
            }

            if (this._controller != null)
            {
                int previousIndex = this._controller.previousIndex;

                if (this._controller.indexIsChanging)
                {
                    D.assert(this._currentIndex != previousIndex);
                    Animation <float> animation = new _ChangeAnimation(this._controller);
                    wrappedTabs[this._currentIndex] =
                        this._buildStyledTab(wrappedTabs[this._currentIndex], true, animation);
                    wrappedTabs[previousIndex] = this._buildStyledTab(wrappedTabs[previousIndex], false, animation);
                }
                else
                {
                    int tabIndex = this._currentIndex;
                    Animation <float> centerAnimation = new _DragAnimation(this._controller, tabIndex);
                    wrappedTabs[tabIndex] = this._buildStyledTab(wrappedTabs[tabIndex], true, centerAnimation);
                    if (this._currentIndex > 0)
                    {
                        int previousTabIndex = this._currentIndex - 1;
                        Animation <float> previousAnimation =
                            new ReverseAnimation(new _DragAnimation(this._controller, previousTabIndex));
                        wrappedTabs[previousTabIndex] =
                            this._buildStyledTab(wrappedTabs[previousTabIndex], false, previousAnimation);
                    }

                    if (this._currentIndex < this.widget.tabs.Count - 1)
                    {
                        int nextTabIndex = this._currentIndex + 1;
                        Animation <float> nextAnimation =
                            new ReverseAnimation(new _DragAnimation(this._controller, nextTabIndex));
                        wrappedTabs[nextTabIndex] =
                            this._buildStyledTab(wrappedTabs[nextTabIndex], false, nextAnimation);
                    }
                }
            }

            int tabCount = this.widget.tabs.Count;

            for (int index = 0; index < tabCount; index++)
            {
                int tabIndex = index;
                wrappedTabs[index] = new InkWell(
                    onTap: () => { this._handleTap(tabIndex); },
                    child: new Padding(
                        padding: EdgeInsets.only(bottom: this.widget.indicatorWeight),
                        child: wrappedTabs[index]
                        )
                    );
                if (!this.widget.isScrollable)
                {
                    wrappedTabs[index] = new Expanded(
                        child: wrappedTabs[index]);
                }
            }

            Widget tabBar = new CustomPaint(
                painter: this._indicatorPainter,
                child: new _TabStyle(
                    animation: Animations.kAlwaysDismissedAnimation,
                    selected: false,
                    labelColor: this.widget.labelColor,
                    unselectedLabelColor: this.widget.unselectedLabelColor,
                    labelStyle: this.widget.labelStyle,
                    unselectedLabelStyle: this.widget.unselectedLabelStyle,
                    child: new _TabLabelBar(
                        onPerformLayout: this._saveTabOffsets,
                        children: wrappedTabs
                        )
                    )
                );

            if (this.widget.isScrollable)
            {
                this._scrollController = this._scrollController ?? new _TabBarScrollController(this);
                tabBar = new SingleChildScrollView(
                    scrollDirection: Axis.horizontal,
                    controller: this._scrollController,
                    child: tabBar);
            }

            return(tabBar);
        }