Flutter中卡片效果的使用

2022年7月25日 1117点热度 0人点赞 0条评论

效果图:
Flutter中卡片效果的使用插图

<code>import &#039;package:flutter/material.dart&#039;;

main(){
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      debugShowCheckedModeBanner: false,
      home: Scaffold(
        appBar: AppBar(
          title: const Text(&quot;222&quot;),
          centerTitle: true,
        ),
        body: Container(
          color: Colors.white,
          child: Card(
            child: FlatButton(
              onPressed: (){debugPrint(&quot;点击了哦&quot;);},
              child: Padding(
                padding: const EdgeInsets.only(left: 0,top: 10,right: 10,bottom: 10),
                child: Column(
                  mainAxisSize: MainAxisSize.min,
                  children: [
                    Container(
                        margin: const EdgeInsets.only(top: 6,bottom: 2),
                        alignment: Alignment.topLeft,
                        child: const Text(&quot;这是一点描述&quot;, style: TextStyle(color: Colors.grey,fontSize: 14), maxLines: 1,
                                         overflow: TextOverflow.ellipsis),
                    ),
                    const Padding(padding: EdgeInsets.all(10)),
                    Row(
                      crossAxisAlignment: CrossAxisAlignment.center,
                      children: [
                        _getButtonItem(Icons.star, &quot;1000&quot;),
                        _getButtonItem(Icons.link, &quot;1000&quot;),
                        _getButtonItem(Icons.subject, &quot;1000&quot;),
                      ],
                    )
                  ],
                ),
              ),
            ),
          ),
        )
      ),
    );
  }
}

_getButtonItem(IconData icon,String text){
  return Expanded(
      flex: 1,
      child: Center(
        child: Row(
          mainAxisAlignment: MainAxisAlignment.center,
          crossAxisAlignment: CrossAxisAlignment.center,
          mainAxisSize: MainAxisSize.max,
          children: [
            Icon(icon,size: 16,color: Colors.pink),
            const Padding(padding: EdgeInsets.only(left: 5)),
            Text(
                text,
                style: const TextStyle(fontSize: 14, color: Colors.grey),
                maxLines: 1,//最长一行
                overflow: TextOverflow.ellipsis,//超过的字数,省略为 ...
            )
          ],
        ),
      )
  );
}</code>

小小调酒师

此刻打盹,你将做梦; 此刻学习,你将圆梦。 个人邮箱:shellways@foxmail.com

文章评论