繁体   English   中英

Flutter 标签栏指示器:如何更改指示器的垂直 position?

[英]Flutter Tab Bar Indicator: How to change the vertical position of the indicator?

我在这个标签栏上工作了一段时间,它现在看起来像这样:

正确的应用栏 ,这是我现在的代码:

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      theme: ThemeData(
        highlightColor: Colors.transparent,
        splashColor: Colors.transparent,
        hoverColor: Colors.transparent,
      ),
      title: 'Flutter Demo',
      home: DefaultTabController(
        length: 2,
        child: Scaffold(
          appBar: AppBar(
            leading: Icon(
              Icons.menu,
              color: Colors.black,
            ),
            actions: [
              Icon(
                Icons.settings,
                color: Colors.black,
              ),
            ],
            automaticallyImplyLeading: false,
            backgroundColor: Colors.white,
            title: Padding(
              padding: EdgeInsets.only(left: 50, right: 50),
              child:TabBar(
              indicatorColor: Colors.pink[100],
              indicatorSize: TabBarIndicatorSize.label,  
              tabs: [
                Tab(text: 'Dogs'),
                Tab(text: 'Cats'),
              ],
              labelColor: Colors.black,
            ),),
          ), //appbar
          body: TabBarView(
            children: [
              Center(child: Text('DOGS')),
              Center(child: Text('CATS')),
            ],
          ),
        ),
      ),
    );
  }
}

可以清楚的看到指标的position不太对。 理想情况下,我希望指示器垂直向上移动,靠近(和下方)文本(“Dogs”&&“Cats”),或者垂直向下移动,保持在应用栏的底部。 我怎么能做到这一点? 任何帮助表示赞赏。

您可以使用TabBar小部件的更多参数来控制这些东西。

我添加了这个,

indicatorWeight: 4,
indicatorPadding: EdgeInsets.symmetric(vertical: 8),

我得到了这个,

在此处输入图像描述

如果您希望它更接近,请使用indicatorPaddingvertical值。
如果您想要它更厚或更薄,请使用indicatorWeight

暂无
暂无

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

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