简体   繁体   English

更改 AppBar 标题填充

[英]Change AppBar title padding

Due to unavailability of modifying app bar leading property width I'm forced to create my own leading trailing property by using AppBar title property.由于无法修改应用栏leading属性宽度,我不得不使用 AppBar title属性创建自己的前导尾随属性。 However I've noticed that title has some default horizontal padding there.但是我注意到标题那里有一些默认的水平填充。

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'))
        ],
      ),
    ),
      ),
    )

在此处输入图像描述

Is there any way to make it smaller?有没有办法让它变小?

Use action[] inside the appbar instead of using Row.在 appbar 中使用 action[] 而不是使用 Row。

  appBar: new AppBar(
      //title: new Text(Strings.app_name),
      actions: <Widget>[
        Padding(
          padding: const EdgeInsets.all(8.0),
          child: new RaisedButton(onPressed: (){

          },
            child: new Text('Cancel'),
          ),
        ),
        Padding(
          padding: const EdgeInsets.all(8.0),
          child: 
          new RaisedButton(onPressed: (){
            
          },child: new Text('done'),)
        ),
      ],
      //centerTitle:true,
    ),

You can use the titleSpacing property of the AppBar to control the horizontal spacing for the title.您可以使用 AppBar 的titleSpacing属性来控制标题的水平间距。

For example following snippet will remove all the leading spacing from title-例如,以下代码段将删除标题中的所有前导间距-

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

在此处输入图像描述

I hope this helps!我希望这有帮助!

Please use titleSpacing: 0.0请使用titleSpacing: 0.0

appBar: AppBar(
    titleSpacing: 0.0,
    title: Text('AppBar Example'),
  ),

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM