如何在Appbar上制作一些具有不同对齐方式的图标?

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

我遇到了一些问题。我想在AppBar制作一个图像,一个文本和两个图标,但我无法按照我的意愿使它工作。

我尝试在图像和文本之后连续制作一些字体。图像和文本成功显示在我的AppBar中,但其余2种字体(手推车和通知)显示出一些错误。

Widget build(BuildContext context) {
    return new Scaffold(
      backgroundColor: Colors.amber,  
      appBar: new AppBar
        (
        title: new Row
          (
          mainAxisAlignment: MainAxisAlignment.start,
            children:
            [
              Image.asset('images/logoapp.png',fit: BoxFit.contain,height: 32,), 
              Container(padding: const EdgeInsets.all(8.0), child: Text('Solid Shop'))
            ],
          )

        ),

....

flutter android-appbarlayout flutter-appbar
3个回答
1
投票

使用leading在appBar title之前设置一个小部件,并使用actions指定appBar中显示在appBar标题右侧的小部件列表。

AppBar(
    leading: Image.asset('yourImage'), // you can put Icon as well, it accepts any widget.
    title: Text ("Your Title"),
    actions: [
        Icon(Icons.add),
        Icon(Icons.add),
    ],
);

阅读更多关于它here


1
投票

你需要使用actions而不是title

actions: <Widget>[
          Image.asset('images/logoapp.png',fit: BoxFit.contain,height: 32,), 
              Container(padding: const EdgeInsets.all(8.0), child: Text('Solid Shop')),

          Image.asset('images/logoapp.png',fit: BoxFit.contain,height: 32,), // here add notification icon
              Container(padding: const EdgeInsets.all(8.0), child: Text('Solid Shop')) // here add other icon
        ],

1
投票
@override
Widget build(BuildContext context) {
  return Scaffold(
    appBar: AppBar(
      title: Text("Solid Shop"),
      leading: Image.asset("your_image_asset"),
      actions: <Widget>[
        IconButton(icon: Icon(Icons.shopping_cart), onPressed: () {}),
        IconButton(icon: Icon(Icons.message), onPressed: () {}),
      ],
    ),
  );
}
© www.soinside.com 2019 - 2024. All rights reserved.