簡體   English   中英

如何將文本和圖標排成一行,使文本恰好位於中心,而圖標位於 flutter 的右端

[英]How can I wrap text and an icon in a row such that text is exactly at the center and icon is at the right end in flutter

我想在一行中換行文本和一個圖標,使文本正好位於中心,而圖標位於 flutter 的右端

Row(
        children: [
          Center(
            child: Text(
              "Add Child",
              style: TextStyle(
                fontWeight: FontWeight.bold,
                fontSize: 20,
                color: Colors.indigo[900],
              ),
            ),
          ),
          Padding(
            padding: const EdgeInsets.only(top: 1),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.end,
              children: [
                IconButton(
            icon: Icon(Icons.close),
            iconSize: 18,
            color: Colors.black,
            onPressed: () {
              Navigator.pop(context);
            },
        ),
              ],
            ),
          ),
        ],
      ),

嘗試這個

Widget _iconButton() {
    return Container(
      height: 40,
      width: MediaQuery.of(context).size.width - 80,
      decoration: BoxDecoration(
        color: Color(0xff303030),
        borderRadius: BorderRadius.circular(5),
      ),
      child: Stack(
        alignment: Alignment.center,
        children: [
          Text(
            'Add',
            style: TextStyle(color: Colors.white, fontSize: 18),
          ),
          Positioned(
            right: 8,
            child: Container(
                height: 30,
                width: 30,
                padding: EdgeInsets.all(6),
                child: Icon(Icons.add),
              ),
          ),
        ],
      ),
    );
  }

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM