有没有办法减少Flutter中NavigationRail中每个元素的高度?

路易斯菲利普

假设我有以下NavigationRail:

我知道这个小部件是相当新的,因此,其功能可能受到限制。但是,我想知道是否有任何方法可以减小NavigationRail中每个元素的高度,例如我在上图所示的元素,因为NavigationRail小部件中的参数似乎不允许这样到现在为止。

编辑:我做了chunhhanhan所说的,即使这样,问题仍然存在。即使使用容器,每个元素的宽度和高度也保持不变。我的代码:

class _HomePageState extends ModularState<HomePage, HomeController> {

  int selectedIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Row(
        children: [
          NavigationRail(
            onDestinationSelected: (index) {
              selectedIndex = index;
            },
            backgroundColor: navigationRailColor,
            selectedIndex: selectedIndex,
            destinations: [
              NavigationRailDestination(
                icon:
                Container(height: 200, child: Icon(Icons.favorite_border)),
                selectedIcon:
                Container(height: 200, child: Icon(Icons.favorite)),
                label: Text(''),
              ),
              NavigationRailDestination(
                icon: Icon(Icons.bookmark_border),
                selectedIcon: Icon(Icons.book),
                label: Text(''),
              ),
              NavigationRailDestination(
                icon: Icon(Icons.star_border),
                selectedIcon: Icon(Icons.star),
                label: Text(''),
              ),
            ],
          )
        ],
      ),
    );
  }
}

外观:

chunhunghan

You can copy paste run full code below
You can use Container wrap icon and provide height
I use a large value 200 for demo purpose

 NavigationRailDestination(
                icon:
                    Container(height: 200, child: Icon(Icons.favorite_border)),
                selectedIcon:
                    Container(height: 200, child: Icon(Icons.favorite)),
                label: Text(''),
              ),

working demo

enter image description here

full code

import 'package:flutter/material.dart';

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

/// This Widget is the main application widget.
class MyApp extends StatelessWidget {
  static const String _title = 'Flutter Code Sample';

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: _title,
      home: MyStatefulWidget(),
    );
  }
}

class MyStatefulWidget extends StatefulWidget {
  MyStatefulWidget({Key key}) : super(key: key);

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

class _MyStatefulWidgetState extends State<MyStatefulWidget> {
  int _selectedIndex = 0;

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("demo"),
      ),
      body: Row(
        children: <Widget>[
          NavigationRail(
            selectedIndex: _selectedIndex,
            onDestinationSelected: (int index) {
              setState(() {
                _selectedIndex = index;
              });
            },
            labelType: NavigationRailLabelType.selected,
            destinations: [
              NavigationRailDestination(
                icon:
                    Container(height: 200, child: Icon(Icons.favorite_border)),
                selectedIcon:
                    Container(height: 200, child: Icon(Icons.favorite)),
                label: Text(''),
              ),
              NavigationRailDestination(
                icon: Icon(Icons.bookmark_border),
                selectedIcon: Icon(Icons.book),
                label: Text(''),
              ),
              NavigationRailDestination(
                icon: Icon(Icons.star_border),
                selectedIcon: Icon(Icons.star),
                label: Text(''),
              ),
            ],
          ),
          VerticalDivider(thickness: 1, width: 1),
          // This is the main content.
          Expanded(
            child: Center(
              child: Text('selectedIndex: $_selectedIndex'),
            ),
          )
        ],
      ),
    );
  }
}

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章

有没有办法减少代号中的手风琴的高度?

有没有办法在Firebase中减少请求?

有没有办法从每个元素中获取所有特定段落?

有没有办法选择cheerio中的每个元素?

有没有办法使用单个循环比较数组中的每个元素?

有没有办法缩小设置高度的元素?

有没有办法提高div元素的高度?

有没有办法在JS中做到这一点?不必添加每个单独的html元素

有没有办法在嵌套 for 循环中访问生成器中每个元素的属性?

有没有办法获取存储为数据框中行的列表中每个元素的计数?

Flutter:-有没有办法自定义列表构建器中每个扩展图块的输出?

有没有办法在这个设置中减少 Spreadsheet.makeCopy() 的计算时间?

JavaScript中有没有办法减少递归函数调用中的调用栈大小?

有没有办法减少在数据帧中循环的条件

有没有办法在python中减少n次嵌套的for循环

有没有办法使用css在html中隐藏没有id或class的元素?

有没有办法显示HTML中python数组中的所有元素?

有没有办法更快地找到列表中的每个元素与该列表中的每个其他元素之间的差异?

有没有办法显示 HTML 元素中的元素数量?

有没有办法打印列表中某个类的所有元素?

有没有办法获取JList中的所有元素?

有没有办法从网站的检查菜单中获取有关元素的信息?

有没有办法在android studio中访问数组的所有元素?

有没有办法在 C++ 中并行循环遍历向量的所有元素?

有没有办法在现有的 HTML 元素中编写对象

有没有办法处理JAXB中多个.xsd文件中重复的元素定义?

有没有办法从颤振中的列表中随机播放随机元素?

有没有办法从模型中获取并显示用户发布的每个广告的图像数量

有没有办法找到二维数组中输入值的每个索引?