将窗口小部件放置在任何位置,而无需推动其他窗口小部件

时间:2020-04-27 20:03:19

标签: android ios flutter

我遵循了Flutter的YouTube教程,最后得到了这样的布局:

https://i.imgur.com/BGLQPma.png

如何将CircleAvatar小部件移至最右侧并调出其他小部件?看起来像这样(我用photoshop了):

enter image description here

这是我的一些代码的样子:

  Widget build(BuildContext context) {
    return Scaffold(
      backgroundColor: Colors.grey[900],
      appBar: AppBar(
        title: Text("User information"),
        centerTitle: true,
        backgroundColor: Colors.grey[850],
        elevation: 0.0,
      ),
      floatingActionButton: FloatingActionButton(
        onPressed: () {
          setState( () { 
            userLevel++;
          });
        },
        backgroundColor: Colors.red[400],
        child: Icon(Icons.add),
      ),
      body: Padding(
        padding: EdgeInsets.fromLTRB(30.0, 35.0, 30.0, 0.0),
        child: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: <Widget>[
            Center(
              child: CircleAvatar(
                backgroundImage: AssetImage("assets/vayneAvatar.jpg"),
                radius: 40.0,
              ),
            ),
            Divider(height: 60.0, color: Colors.grey[700]),
            Text(
              "USERNAME",
              style: TextStyle(
                color: Colors.grey,
                letterSpacing: 2.0,
              ),
            ),
            SizedBox(height: 8.0),
            Text(
              "user1",
              style: TextStyle(
                color: Colors.red[400],
                fontWeight: FontWeight.bold,
                fontSize: 22.0,
                letterSpacing: 2.0,
              ),
            ),

谢谢!

1 个答案:

答案 0 :(得分:0)

您需要使用Stack widget来获取子项列表,在这里您可以通过Positioned widget轻松地放置小部件。