繁体   English   中英

Flutter:如何在 SLIDE 上更改 Tab 图标的颜色,而不仅仅是点击?

[英]Flutter: How to change Tab's icon's color on SLIDE, not just on tap?

所以,我设置了一个 TabBarView,它的标签包含一个图标和文本。 当您通过滑动在选项卡之间切换时,文本似乎会线性改变颜色。 你如何为图标实现同样的效果? 我设法让它在 TAP 上切换颜色,但在滑动时它不遵守相同的规则。

我尝试过tabController.index == 0等。仍然无法正常工作。

使用TapSliding两者:

child: new TabBar(
                  indicatorColor: Colors.white,
                  unselectedLabelColor: Colors.grey, // for unselected
                  labelColor: Colors.white, // for selected
                  indicatorWeight: 5.0,
                  tabs: [
                    new Tab(
                      text: 'Unpaid'.toUpperCase(),
                    ),
                    new Tab(
                      text: 'Draft'.toUpperCase(),
                    ),
                    new Tab(
                      text: 'All'.toUpperCase(),
                    ),
                  ],
                ),
              ),
            ),
            body: new TabBarView(
              children: [
                new first.UnpaidInvoicePage(),
                new second.PaidInvoicePage(),
                new third.AllInvoicePage(),
              ],
            ),

请尝试以下代码:

  • labelColor: Colors.black, // 选中的标签颜色(icon,text)
  • unselectedLabelColor: Colors.amber, // 未选中的 Tab Color(icon,text)

================================================== ======================

import 'package:flutter/material.dart';

void main() {
  runApp(TabBarDemo());
}

class TabBarDemo extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: DefaultTabController(
        length: 3,
        child: Scaffold(
          appBar: AppBar(
            bottom: TabBar(
              unselectedLabelColor: Colors.amber, // UnSelected Tab Color
              labelColor: Colors.black, // Selected Tab Color
              tabs: [
                Tab(icon: Icon(Icons.directions_car)),
                Tab(icon: Icon(Icons.directions_transit)),
                Tab(icon: Icon(Icons.directions_bike)),
              ],
            ),
            title: Text('Tabs Demo'),
          ),
          body: TabBarView(
            children: [
              Icon(Icons.directions_car),
              Icon(Icons.directions_transit),
              Icon(Icons.directions_bike),
            ],
          ),
        ),
      ),
    );
  }
}

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM