如何在Flutter中设置layoutToLeft或toRight?

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

我是flutter的新手,如何将图像搜索设置为图像菜单的layoutToRight? 现在在这个部分有困难。

enter image description here

我的代码如下。

  return MaterialApp(
  theme: ThemeData(
    primarySwatch: Colors.red,
    visualDensity: VisualDensity.adaptivePlatformDensity,
  ),
  home:Scaffold(
    appBar: PreferredSize(
      preferredSize: Size.fromHeight(45.0),
      child: AppBar(
        leading: Container(
          child: GestureDetector(
              onTap: (){/* open left menu */},
              child: Image.asset("assets/images/ic_title_menu.png")),
          padding: EdgeInsets.fromLTRB(14.0, 14.0, 14.0, 14.0),
        ),
        actions: <Widget>[
          Container(
            child: GestureDetector(
              onTap: (){/* open search */},
              child: Image.asset("assets/images/ic_title_search.png"),
            ),
            padding: EdgeInsets.fromLTRB(14.0, 14.0, 14.0, 14.0),
          )
        ],
    ),
  ),
flutter flutter-layout
1个回答
1
投票

你可以使用title属性,来实现想要的输出。

Scaffold(
  appBar: PreferredSize(
    preferredSize: Size.fromHeight(45.0),
    child: AppBar(
      leading: Row(
        children: [
          Container(
            child: GestureDetector(
                onTap: () {/* open left menu */},
                child: Image.asset("assets/images/ic_title_menu.png")),
            padding: EdgeInsets.fromLTRB(14.0, 14.0, 14.0, 14.0),
          ),
        ],
      ),
      titleSpacing: 0.0, // added update
      title: Container(
        child: GestureDetector(
          onTap: () {/* open search */},
          child: Image.asset("assets/images/ic_title_search.png"),
        ),
        padding: EdgeInsets.fromLTRB(14.0, 14.0, 14.0, 14.0),
      ),
    ),
  ),
)
© www.soinside.com 2019 - 2024. All rights reserved.