如何使按钮具有与appbar相同的宽度?

时间:2019-05-16 19:48:24

标签: flutter

摘要:
目前,我有以下结果:
enter image description here

我的目标是得到这个结果(所有元素都对齐):
enter image description here


说明:
我定义了一个标准的appBar,FlatButton和textField。我希望所有元素都具有相同的宽度并垂直对齐。 默认的appBar和TextField具有相同的宽度,但没有我的按钮。那么,如何使按钮具有与其他元素相同的宽度?

代码:

    import 'package:flutter/material.dart';

/// Styles
class Homepage extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text("Test", style: TextStyle(color: Colors.white)),
        centerTitle: true,
        backgroundColor: Colors.black,
      ),

      body: Stack(children: <Widget>[
        new Container(
          height: MediaQuery.of(context).size.height,
          width: MediaQuery.of(context).size.width,

          child: SingleChildScrollView(
            child: Container(
              child: Center(
                child: Column(
                  children: <Widget>[
                    SizedBox(
                      height: 50,
                    ),

                     new ButtonTheme(
                      //minWidth: 300,
                      child: FlatButton(
                      color: Colors.black,
                      child: Text('Play', style: TextStyle(fontSize: 18, color: Colors.white)),
                      onPressed: () {
                        // Perform some action
                      },
                    ),

                ),
                    SizedBox(
                      height: 50,
                    ),
                    new ListTile(
                      leading: const Icon(Icons.person),
                      title: new TextField(
                        decoration: new InputDecoration(
                          hintText: "Name Player 1",
                        ),
                      ),
                    ),                    
                  ],
                ),
              ),
            ),
          ),
        ),
      ]),
    );
  }
}

1 个答案:

答案 0 :(得分:0)

使用具有无限宽度的local boostPart = script.Parent local jump = leaderstats.gold.Value local boostedJumpPower = jump.Value local function onPartTouch(otherPart) local partParent = otherPart.Parent local humanoid = partParent:FindFirstChildWhichIsA("Humanoid") if ( humanoid ) then boostPart.CanCollide = false local currentJumpPower = humanoid.JumpPower if ( currentJumpPower < boostedJumpPower ) then humanoid.JumpPower = boostedJumpPower wait(5) humanoid.JumpPower = currentJumpPower end end end boostPart.Touched:Connect(onPartTouch) 来使SizedBox填充水平空间,然后将其包裹在FlatButton中(Padding的填充为16):

AppBar