可水平滚动的选项卡聚焦在中心,颤动迅速

时间:2019-01-17 06:23:27

标签: flutter flutter-layout

在这里我想问一个问题,或者我可以制作一个像tabs这样的教程,以焦点为中心,但是像这样的左右标签是30%透明的,谢谢!

enter image description here

3 个答案:

答案 0 :(得分:2)

在TabBar内添加isScrollable: true,

TabBar(
       isScrollable: true,
.
.
.

)

答案 1 :(得分:1)

可以使用unselectedLabelColor:小部件的-indicatorColor:TabBar实现相同的功能。

示例代码:

@override
  Widget build(BuildContext context) {
    return DefaultTabController(
      length: 6,
      child: Scaffold(
          appBar: AppBar(
            centerTitle: true,
            leading: Icon(Icons.person_outline),
            title: Text('DASHBOARD',style: TextStyle(fontSize: 16.0),),
            bottom: PreferredSize(
                child: TabBar(
                    isScrollable: true,
                    unselectedLabelColor: Colors.white.withOpacity(0.3),
                    indicatorColor: Colors.white,
                    tabs: [
                      Tab(
                        child: Text('Tab 1'),
                      ),
                      Tab(
                        child: Text('Investment'),
                      ),
                      Tab(
                        child: Text('Your Earning'),
                      ),
                      Tab(
                        child: Text('Current Balance'),
                      ),
                      Tab(
                        child: Text('Tab 5'),
                      ),
                      Tab(
                        child: Text('Tab 6'),
                      )
                    ]),
                preferredSize: Size.fromHeight(30.0)),
            actions: <Widget>[
              Padding(
                padding: const EdgeInsets.only(right: 16.0),
                child: Icon(Icons.add_alert),
              ),
            ],
          ),
          body: TabBarView(
            children: <Widget>[
              Container(
                child: Center(
                  child: Text('Tab 1'),
                ),
              ),
              Container(
                child: Center(
                  child: Text('Tab 2'),
                ),
              ),
              Container(
                child: Center(
                  child: Text('Tab 3'),
                ),
              ),
              Container(
                child: Center(
                  child: Text('Tab 4'),
                ),
              ),
              Container(
                child: Center(
                  child: Text('Tab 5'),
                ),
              ),
              Container(
                child: Center(
                  child: Text('Tab 6'),
                ),
              ),
            ],
          )),
    );
  }

输出:

enter image description here

答案 2 :(得分:1)

放置isScrollable:是的,在TabBar中对我有用。

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  int _counter = 0;

  void _incrementCounter() {
    setState(() {

  _counter++;
 });
}

@override
Widget build(BuildContext context) {

 final _kTabPages = <Widget>[
   Center(child: Icon(Icons.cloud, size: 64.0, color: Colors.teal)),
   Center(child: Icon(Icons.alarm, size: 64.0, color: Colors.cyan)),
   Center(child: Icon(Icons.forum, size: 64.0, color: Colors.blue)),
   Center(child: Icon(Icons.forum, size: 64.0, color: Colors.blue)),
   Center(child: Icon(Icons.forum, size: 64.0, color: Colors.blue)),
   Center(child: Icon(Icons.forum, size: 64.0, color: Colors.blue)),
   Center(child: Icon(Icons.forum, size: 64.0, color: Colors.blue)),
   Center(child: Icon(Icons.forum, size: 64.0, color: Colors.blue)),
 ];
 final _kTabs = <Tab>[
   Tab(text: 'NK'),
   Tab(text:'ActiveTools'),
   Tab(text:'Coxmate'),
   Tab(text:'Concept2'),
   Tab(text:'Croker'),
   Tab(text:'Hudson'),
   Tab(text:'Swift'),
   Tab(text:'Rowshop'),
 ];
 return DefaultTabController(
   length: _kTabs.length,
   child: Scaffold(
     appBar: AppBar(
     leading:Image.asset("assets/Macarbi Logo.jpg"),//TODO image or icon here
     title: Text(widget.title),
     actions: <Widget>[
       IconButton(
         icon: Icon(Icons.search),
         onPressed: () {},//TODO  do something
       ),
       IconButton(
         icon: Icon(Icons.account_circle),
         onPressed: () {},//TODO do something
       ),
     ],
      bottom: TabBar(
        isScrollable: true,
         tabs: _kTabs,
       ),
   ),
     body: TabBarView(
       children: _kTabPages,
     ),
   ),
 );
}