简体   繁体   中英

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

I can't figure out how to change the icon that I already highlighted to the top-right. I already use spceBetween , but still doesn't affect the changes.

示例我要更改位置的图标

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,
            ),
          )
        ],
      ),
    );
  }
}

To show an icon on the left and right, you should use the AppBar widget on your Scaffold() . To place a widget at the start (left) use the leading property, and to place a widget at the end (right) use the actions property:

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

Result:

在此处输入图像描述

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM