gpt4 book ai didi

flutter - 更改AppBar标题填充

转载 作者:行者123 更新时间:2023-12-03 04:13:44 24 4
gpt4 key购买 nike

由于无法修改应用栏leading属性的宽度,我不得不使用AppBar title属性来创建自己的前导尾随属性。但是我注意到标题在那里有一些默认的水平填充。

Scaffold(
appBar: AppBar(
centerTitle: true,
title: Container(
height: 36,
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
Container(width: 80, child: Text('Cancel')),
Text('Profile'),
Container(width: 80, child: Text('Done'))
],
),
),
),
)
enter image description here
有什么办法可以缩小尺寸?

最佳答案

您可以使用AppBar的titleSpacing属性来控制标题的水平间距。
例如,以下代码段将删除标题中的所有前导空格-

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: MyStatelessWidget(),
);
}
}

/// This is the stateless widget that the main application instantiates.
class MyStatelessWidget extends StatelessWidget {
MyStatelessWidget({Key key}) : super(key: key);

@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
titleSpacing: 0.0,
title: const Text('AppBar Demo'),
),
body: const Center(
child: Text(
'This is the home page',
style: TextStyle(fontSize: 24),
),
),
);
}
}
enter image description here
我希望这有帮助!

关于flutter - 更改AppBar标题填充,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62529620/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com