Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

将代码运用到自己项目上时出错 #437

Closed
kadoyatsukasa opened this issue Jun 5, 2019 · 4 comments
Closed

将代码运用到自己项目上时出错 #437

kadoyatsukasa opened this issue Jun 5, 2019 · 4 comments

Comments

@kadoyatsukasa
Copy link

我在自己的项目上引用了你的tabbar,这一部分我去掉了floating button,
主要代码


  @override
  Widget build(BuildContext context) {
    if (this._type == DCDTabBarWidget.TOP) {
      //顶部tab bar
      return new Scaffold(
        resizeToAvoidBottomPadding: widget.resizeToAvoidBottomPadding,
        persistentFooterButtons:
            _tarWidgetControl == null ? null : _tarWidgetControl.footerButton,
        appBar: new AppBar(
          backgroundColor: Theme.of(context).primaryColor,
          title: _title,
          bottom: new TabBar(
            controller: _tabController,
            tabs: widget.tabItems,
            indicatorColor: _indicatorColor,
            onTap: (index) {
              _onPageChanged?.call(index);
              _pageController.jumpTo(MediaQuery.of(context).size.width * index);
            },
          ),
        ),
        body: new PageView(
          controller: _pageController,
          children: _tabView,
          onPageChanged: (index) {
            _tabController.animateTo(index);
            _onPageChanged?.call(index);
          },
        ),
        bottomNavigationBar: widget.bottomBar,
      );
    }

    //底部tab bar
    return new Scaffold(
      appBar: new AppBar(
        backgroundColor: Theme.of(context).primaryColor,
        title: _title,
      ),
      body: new PageView(
        controller: _pageController,
        children: _tabView,
        onPageChanged: (index) {
          _tabController.animateTo(index);
          _onPageChanged?.call(index);
        },
      ),
      bottomNavigationBar: new Material(
        color: Theme.of(context).primaryColor,
        child: new SafeArea(
          child: new TabBar(
            tabs: widget.tabItems,
            indicatorColor: _indicatorColor,
            onTap: (index) {
              _onPageChanged?.call(index);
              _pageController.jumpTo(MediaQuery.of(context).size.width * index);
            },
          ),
        ),
      ),
    );
  }

然后我的主页代码是

 @override
  Widget build(BuildContext context) {
    List<Widget> tabs=[
      _renderTab(Icons.home, '主页'),
      _renderTab(Icons.category, '动态'),
      _renderTab(Icons.person, '我的'),
    ];

    return new WillPopScope(
        child: new DCDTabBarWidget(
          type: DCDTabBarWidget.BOTTOM,
          tabItems: tabs,
          tabViews: <Widget>[
            new HomePage(),
            new Categories(),
            new MinePage()
          ],
          backgroundColor: Theme.of(context).primaryColor,
          indicatorColor: Color(0xFFFFFFFF),
        ),
        onWillPop: null);
  }

然而报错 No TabController for TabBar.
我检查了我的代码,已经添加了controller了,为什么还是提示没有TabController??

@CarGuo
Copy link
Owner

CarGuo commented Jun 5, 2019

image

说的这里没有吧

@kadoyatsukasa
Copy link
Author

找到问题了,就是那里少了个controller

@kadoyatsukasa
Copy link
Author

WX20190605-172346
又出问题了,使用顶部模式的时候,出现双重appbar.......
这是代码

    return Scaffold(
      body: new DCDTabBarWidget(
        type: DCDTabBarWidget.TOP,
        tabItems: tags,
        tabViews: <Widget>[
          new ShortVideoListPage(),
          new FilmListPage(),
        ],
      ),
    );
  }

@CarGuo
Copy link
Owner

CarGuo commented Jun 5, 2019

类似问题你参考demo或者自己找吧,这不属于项目问题了哦!

@CarGuo CarGuo closed this as completed Jun 5, 2019
@jayVRIY jayVRIY mentioned this issue Dec 8, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants