Flutter - NavigationRail 的高度

问题描述 投票:0回答:1

如何缩小 Flutter 中的 NavigationRail?我有一个 140 像素高的容器,但带有 3 个选项卡的 NavRail 需要大约 225 像素。如果可能的话,我不想调整容器的大小。 我尝试了几种不同的方法(列、容器、IntrinsicHeight...)但没有任何效果。

class PATWidget extends StatefulWidget {
  const PATWidget({super.key});

  @override
  State<PATWidget> createState() => _PATWidgetState();
}

class _PATWidgetState extends State<PATWidget> {
  int index = 0;

  @override
  Widget build(BuildContext context) {
    return Column(children: [
      Row(
        //Headline
      ),
      Row(
        children: [
          Column(
            children: [
              Container(
                height: 140,
                width: 30,
                child: NavigationRail(
                  selectedIconTheme:
                      IconThemeData(color: Theme.of(context).primaryColor),
                  unselectedIconTheme: IconThemeData(color: fumigruen_accent),
                  backgroundColor: Theme.of(context).scaffoldBackgroundColor,
                  labelType: NavigationRailLabelType.none,
                  selectedIndex: index,
                  onDestinationSelected: (index) =>
                      setState(() => this.index = index),
                  destinations: [
                    NavigationRailDestination(
                      icon: Icon(Icons.abc),
                      selectedIcon: Icon(Icons.pin_drop),
                      label: Text(
                        "",
                      ),
                    ),
                    NavigationRailDestination(
                      icon: Container(height: 20, child: Icon(Icons.abc)),
                      selectedIcon:
                          Container(height: 20, child: Icon(Icons.abc)),
                      label: Text(""),
                    ),
                    NavigationRailDestination(
                      icon: Container(height: 20, child: Icon(Icons.abc)),
                      selectedIcon:
                          Container(height: 20, child: Icon(Icons.abc)),
                      label: Text(""),
                    ),
                  ],
                ),
              ),
            ],
          ),
          Expanded(
            child: buildPages(),
          ),
        ],
      )
    ]);
  }

flutter user-interface
1个回答
1
投票

您可以在

minWidth
上使用
NavigationRail

Container(
  height: 140,
  width: 30,
  child: NavigationRail(
    minWidth: 140 / 3 - 8, // your value. -8 it has extra padding i belive 
    unselectedIconTheme: IconThemeData(
© www.soinside.com 2019 - 2024. All rights reserved.