Flutter:CupertinoNavigationBar,带有领先的图标和标题

时间:2019-09-24 14:24:45

标签: flutter flutter-layout

如何在Flutter中创建导航栏的前导项目,并带有后退图标和前一个支架的标题。看看图片:

enter image description here

我尝试将Text小部件放在Row内,但出现溢出。

CupertinoNavigationBar(
    middle: Text('New report'),
    leading: Align(
      alignment: Alignment(-1.5, -1),
      child: IconButton(
        onPressed: () {
          Navigator.pop(context);
        },
        icon: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            Icon(
              CupertinoIcons.left_chevron,
              color: CupertinoColors.destructiveRed,
            ),
          ],
        ),
      ),
    ),
  ),

谢谢!

2 个答案:

答案 0 :(得分:0)

您的开头可能是包含图标和文本的行:诸如此类:

CupertinoNavigationBar(
    middle: Text('New report'),
    leading: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            Icon(
              CupertinoIcons.left_chevron,
              color: CupertinoColors.destructiveRed,
            ),
             Text('Reports')
             ],
        ),
    ),
  ),

答案 1 :(得分:0)

最简单的解决方法是用Row包装您的主要小部件,然后再次点击点击将其退回,将其包装到GestureDetector

  CupertinoNavigationBar(
      leading: GestureDetector(
        onTap: () => Navigator.pop(context),
        child: Row(
          mainAxisAlignment: MainAxisAlignment.start,
          children: <Widget>[
            Icon(
              CupertinoIcons.left_chevron,
              color: CupertinoColors.destructiveRed,
            ),
            Text('Reports', style: TextStyle(color: CupertinoColors.destructiveRed),)
          ],
        ),
      ),
      middle: Text('Time report'),
    );

enter image description here