簡體   English   中英

如何使用 Flutter/Dart 在卡片的左右創建圖標

[英]How I can create icon at left and right in a card using Flutter/Dart

我不知道如何更改已在右上角突出顯示的圖標。 我已經使用spceBetween ,但仍然不影響更改。

示例我要更改位置的圖標

class _SidebarState extends State<Sidebar> {
  @override
  Widget build(BuildContext context) {
    return Container(
      decoration: BoxDecoration(
          color: Color.fromARGB(255, 44, 41, 56),
          boxShadow: [
            BoxShadow(
              color: Colors.grey.withOpacity(0.5),
              spreadRadius: 5,
              blurRadius: 7,
              offset: Offset(0, 3), // changes position of shadow
            ),
          ],
          borderRadius: BorderRadius.only(topRight: const Radius.circular(20))),
      child: Column(
        children: [
          Row(
            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
            children: <Widget>[
              ClipRRect(
                  borderRadius: BorderRadius.all(Radius.circular(32.0)),
                  child: Row(
                    mainAxisAlignment: MainAxisAlignment.spaceBetween,
                    children: [
                      Container(
                        child: Material(
                          shadowColor: Colors.transparent,
                          color: Colors.transparent,
                          child: IconButton(
                            icon: Icon(Icons.menu,
                                color: Color.fromARGB(255, 247, 243, 243)),
                            onPressed: widget.onSideBarPressed,
                          ),
                        ),
                      ),
                      Container(
                        color: Colors.amber,
                        child: Material(
                          shadowColor: Colors.transparent,
                          color: Colors.transparent,
                          child: IconButton(
                            icon: Icon(Icons.access_time,
                                color: Color.fromARGB(255, 247, 243, 243)),
                            onPressed: widget.onSideBarPressed,
                          ),
                        ),
                      )
                    ],
                  )),
              Expanded(
                flex: 2,
                child: Text(
                  widget.title,
                  textAlign: TextAlign.center,
                  style: const TextStyle(
                      color: Colors.white,
                      fontWeight: FontWeight.bold,
                      fontSize: 18,
                      decoration: TextDecoration.none),
                ),
              )
            ],
          ),
          Divider(
            height: 0,
          ),
          Expanded(
            flex: 2,
            child: Container(
              child: widget.body,
            ),
          )
        ],
      ),
    );
  }
}

要在左側和右側顯示圖標,您應該使用Scaffold()上的AppBar小部件。 要將小部件放置在開頭(左)使用leading屬性,並將小部件放置在末尾(右)使用actions屬性:

return Scaffold(
      appBar: AppBar(
        leading: Icon(Icons.menu),
        actions: [Icon(Icons.search)],
      ),);
      

結果:

在此處輸入圖像描述

暫無
暫無

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

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