【问题标题】:Flutter PageView remove page IndicatorFlutter PageView 移除页面指示器
【发布时间】:2020-04-11 04:48:39
【问题描述】:

有谁知道是否有办法删除在我更改页面后显示几秒钟的 PageView 指示器?

    return Scaffold(
      bottomNavigationBar: CubertoBottomBar(
        tabStyle: CubertoTabStyle.STYLE_FADED_BACKGROUND,
        selectedTab: _selectedIndex, 
        tabs: [
          TabData(
            iconData: Icons.assignment,
            title: "Logbuch",
            tabColor: Colors.deepPurple,
          ),
         ....
        ],
        onTabChangedListener: (position, title, color) {
          setState(() {
            _selectedIndex = position;
          });
        },
      ),
      body: PageView(
        controller: _pageController,
        pageSnapping: true,
        onPageChanged: (index) {
          setState(() {
            _selectedIndex = index;
          });
        },
        // physics: NeverScrollableScrollPhysics(),
        children: <Widget>[
          LogBookView(),
         ...
        ],
      ),
    );

我在 PageView 小部件和 BottomNav 小部件的文档中找不到任何相关信息。

【问题讨论】:

    标签: flutter dart flutter-pageview


    【解决方案1】:

    我认为您需要为您的代码提供一些上下文,因为有很多方法可以实现 PageView 和指示器。我认为您使用 TabBarView 作为 PageView 的父级,因为默认情况下 PageView 本身没有指标,TabBarView 有。

    假设我是对的,除非您想使用不同的选项卡,并且每个选项卡都有不同的 PageView 或其他小部件,否则您确实不需要使用 TabBarView。判断您的 UI 我认为带控制器的 PageView 可以满足您的 UI 需求。

    Class XYZ extends StatefullWidget{
    .......
    }
    Class _XYZ extends State<XYZ>
        with SingleTickerProviderStateMixin{
    
    PageController _pageController;
    int pageNumber = 0;
    
    void initState() {
      super.initState();
    
        _pageController = PageController();
      }
    ..................
    //inside build PageView
    PageView(
      controller: _pageController,
      onPageChanged: (pageIndex) {
         setState(() {
           pageNumber = pageIndex;
         });
       },
       children: <Widget>[
             Notes(), // scaffold or widget or other class
             Wochenplan(), scaffold or widget or other class
             ETC(), // scaffold or widget or other class
       ],
    ),
    ..................
    //inside build bottom nav icons
    Row(
       children: <Widget>[
             buildTabButton(int currentIndex, int pageNumber, String image), 
             buildTabButton2...., 
             buildTabButton3...,
       ],
    )
    .......
    
    buildTabButton1........
    
    buildTabButton2(int currentIndex, int pageNumber, String image) {
        return AnimatedContainer(
          height: _height,
          width: currentIndex == pageNumber ? 100 : 30,
          padding: EdgeInsets.all(10),
          duration: Duration(milliseconds: 300),
          decoration: BoxDecoration(),// use currentIndex == pageNumber to decorate current widget and others
          child: ../*ClickableWidget*/, //onClckWochenplan() // and so on  
        );
    }
    
    buildTabButton3........
    
    
    ........................
    //onPressed or onTap functions which you can implement inside widgets as well.. 
    void ABC() {
        _pageController.animateToPage(0,
            duration: Duration(milliseconds: 500), curve: Curves.decelerate);
    }
    
    void onClckWochenplan() {
        _pageController.animateToPage(1,
            duration: Duration(milliseconds: 500), curve: Curves.decelerate);
    }
    
    void DEF() {
        _pageController.animateToPage(2,
            duration: Duration(milliseconds: 500), curve: Curves.decelerate);
    }
    
    

    我希望它有所帮助.. 否则提供一些代码来获得社区的帮助.. 干杯

    【讨论】:

    • 我用代码编辑了我的帖子,我是如何做到的。感谢伟大的遮阳篷,但我认为这不是我的问题的解决方案。
    【解决方案2】:

    我看到您正在使用库 CubertoBottomBar,它不是颤振提供的默认 TabBarView。于是我去图书馆看了看。问题是,它根本不应该显示指标。因此,我将在这里进行 2 个疯狂的猜测和 1 个建议。 1. 你可能有另一个父母用 TabBarView 包装了这个脚手架(可能来自之前包装这个脚手架的类/小部件)..

     Scaffold(
          bottomNavigationBar: CubertoBottomBar(
            tabStyle: CubertoTabStyle.STYLE_FADED_BACKGROUND,
            selectedTab: _selectedIndex, 
            tabs: [
    ..............
    
    
    1. 如果您在 IOS 上构建它,它可能无法正确呈现库小部件。 (这是因为我尝试以与您相同的方式构建此应用程序,而我的 3 台设备根本没有得到任何指标)。因此,如果您目前正在 IOS 上构建它,请尝试在 android 设备上构建它,那么您可能会知道真正发生了什么并向库所有者报告问题。

    2. 除了我无法帮助您之外,我建议您尝试将 PageView 替换为 TabBar 然后您可以控制指示器(虽然 PageView 也不应该给您指示器,而只是一个建议)..

    TabBar(
      indicatorWeight: 0.0, // then you can control height of indicator
      indicatorColor: Colors.transparent, // then you can control color with transparent value
      tabs: <Widget>[
           tab();
           tab2();
      ],            
    ),
    

    //**TODO ----------

    我的赌注是我的第一点。彻底检查您的小部件树...

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-03-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多