如何在Flutter中将AppBar标题放置在左侧

l3zydbqr  于 2023-04-07  发布在  Flutter
关注(0)|答案(8)|浏览(383)

下面是我的代码AppBar Tittle,但它不工作

Widget build(BuildContext context){
return new Scaffold(
  appBar: new AppBar(
    title: new Padding(
      padding: const EdgeInsets.only(left: 20.0),
      child: new Text("App Name"),
    ),
  ),
);}
uqdfh47h

uqdfh47h1#

appBar: AppBar(
  centerTitle: false,
  backgroundColor: Color(0xff98A8D0),
  title: Image.asset(
    'assets/covalent_dark_icon.png',
    height: 45,
    width: 120,
  ),
)

这是实际的方法。使用Transform会使你的UI响应速度变慢。

t9eec4r0

t9eec4r02#

对于我来说,指定automaticallyImplyLeading: false解决了这个问题。

d7v8vwbk

d7v8vwbk3#

centerTitle属性设置为false。

w6mmgewl

w6mmgewl4#

Transform是用于在x-y-z维度上强制转换小部件的小部件。

return Scaffold(
        appBar: AppBar(
          centerTitle: false,
          titleSpacing: 0.0,
          title:  Transform(
              // you can forcefully translate values left side using Transform
              transform:  Matrix4.translationValues(-20.0, 0.0, 0.0),
              child: Text(
                "HOLIDAYS",
                style: TextStyle(
                  color: dateBackgroundColor,
                ),
              ),
            ),
        ),
      );
5gfr0r5j

5gfr0r5j5#

在AppBar中将centerTile属性设置为false和leadingWidth: 0

qgelzfjb

qgelzfjb6#

只需在AppBar小部件中将centerTile属性设置为false

AppBar(
        ...
        centerTitle: false,
        title: Text("App Name"),
        ...
        )
0ejtzxu1

0ejtzxu17#

AppBar的标题默认是居中的。要让文本在左边,你应该设置属性centerTitle false,如下所示:

Widget build(BuildContext context){
  return new Scaffold(
    appBar: new AppBar(
      centerTitle: false
      title: new Padding(
        padding: const EdgeInsets.only(left: 20.0),
        child: new Text("App Name"),
      ),
    ),
  );
}
vmdwslir

vmdwslir8#

如果你想在appbar的最左边显示title

Widget build(BuildContext context){
  return new Scaffold(
    appBar: new AppBar(
      centerTitle: false,
      leadingWidth: 0, // this is also im
      title: new Padding(
        padding: const EdgeInsets.only(left: 25.0),
        child: new Text("App Name"),
      ),
    ),
  );
}

将强制文本到应用栏的最左边

相关问题