Flutter-如何将appBar上的按钮向左对齐?

时间:2020-06-05 11:25:01

标签: flutter flatbutton

默认情况下,Flutter中appBar上的操作按钮默认对齐到右侧,我想将FlatButton对齐到标题/徽标旁边的左侧。

有人可以建议吗?

下面是我的代码:

@override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          backgroundColor: Colors.white,
          title: const Text('Logo'),
          elevation: 0.0,
           actions: <Widget>[

            FlatButton(
                onPressed: () {
                  _select(choices[0]);
                },
                child: Text(
                  'Portfolio',
                  style: TextStyle(
                      fontFamily: 'Futura',
                      fontSize: 12,
                      color: Color.fromRGBO(80, 86, 89, 100)),
                )),

干杯, 卡伦

3 个答案:

答案 0 :(得分:1)

import 'package:flutter/material.dart';

class TestPage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Row(
          children: <Widget>[
            Text(
              'Actions Align Left',
            ),
            FlatButton(
              child: Text('FlatButton'),
            )
          ],
        )
      ),
    );
  }
}

我使用Row作为标题,然后将FlatButton放在此处。

答案 1 :(得分:0)

在操作中添加诸如Container之类的默认小部件,并将其包装在Expanded小部件中

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
            backgroundColor: Colors.white,
            title: const Text('Logo'),
            elevation: 0.0,
            actions: <Widget>[
              FlatButton(
                  onPressed: () {},
                  child: Text(
                    'Portfolio',
                    style: TextStyle(
                        fontFamily: 'Futura',
                        fontSize: 12,
                        color: Color.fromRGBO(80, 86, 89, 100)),
                  )),
              Expanded(
                child: Container(),
              ),
            ]),
      ),
    );
  }

答案 2 :(得分:0)

您还可以使用leading的{​​{1}}属性,该属性将小部件放置在标题之前。如果在那里需要多个小部件,则可以将它们嵌套在AppBar中。