flutter Container容器实现圆角边框

作者:早起的年轻人 时间:2021-06-17 23:16:23 

本文实例为大家分享了flutter Container容器实现圆角边框的具体代码,供大家参考,具体内容如下

在这里使用 Container 容器来实现圆角矩形边框效果

1 圆角矩形边框

flutter Container容器实现圆角边框


Container(
margin: EdgeInsets.only(left: 40, top: 40),
//设置 child 居中
alignment: Alignment(0, 0),
height: 50,
width: 300,
//边框设置
decoration: new BoxDecoration(
//背景
color: Colors.white,
//设置四周圆角 角度
borderRadius: BorderRadius.all(Radius.circular(4.0)),
//设置四周边框
border: new Border.all(width: 1, color: Colors.red),
),
child: Text("Container 的圆角边框"),
),

2 圆角矩形边框

flutter Container容器实现圆角边框


Container(
margin: EdgeInsets.only(left: 40, top: 40),
//设置 child 居中
alignment: Alignment(0, 0),
height: 50,
width: 300,
//边框设置
decoration: new BoxDecoration(
//背景
color: Colors.white,
//设置四周圆角 角度 这里的角度应该为 父Container height 的一半
borderRadius: BorderRadius.all(Radius.circular(25.0)),
//设置四周边框
border: new Border.all(width: 1, color: Colors.red),
),
child: Text("Container 的圆角边框"),
),

3 可点击的圆角矩形边框

flutter Container容器实现圆角边框

使用 InkWell 来实现 ,更多关于 InkWell 可查看 flutter InkWell 设置水波纹点击效果详述


Container(
margin: EdgeInsets.only(left: 40, top: 40),
  child: new Material(
  //INK可以实现装饰容器
  child: new Ink(
   //用ink圆角矩形
   // color: Colors.red,
   decoration: new BoxDecoration(
   //背景
   color: Colors.white,
   //设置四周圆角 角度
   borderRadius: BorderRadius.all(Radius.circular(25.0)),
   //设置四周边框
   border: new Border.all(width: 1, color: Colors.red),
   ),
   child: new InkWell(
    //圆角设置,给水波纹也设置同样的圆角
    //如果这里不设置就会出现矩形的水波纹效果
    borderRadius: new BorderRadius.circular(25.0),
    //设置点击事件回调
    onTap: () {},
    child: Container(
    //设置 child 居中
    alignment: Alignment(0, 0),
    height: 50,
    width: 300,
    child: Text("点击 Container 圆角边框"),
    )),
  ),
  ),
 ),

4 可点击的圆角矩形边框

flutter Container容器实现圆角边框


Container(
 margin: EdgeInsets.only(left: 40, top: 40),
  child: new Material(
  child: new Ink(
   //设置背景
   decoration: new BoxDecoration(
   //背景
   color: Colors.white,
   //设置四周圆角 角度
   borderRadius: BorderRadius.all(Radius.circular(25.0)),
   //设置四周边框
   border: new Border.all(width: 1, color: Colors.red),
   ),
   child: new InkResponse(
   borderRadius: new BorderRadius.all(new Radius.circular(25.0)),
   //点击或者toch控件高亮时显示的控件在控件上层,水波纹下层
//    highlightColor: Colors.deepPurple,
   //点击或者toch控件高亮的shape形状
   highlightShape: BoxShape.rectangle,
   //.InkResponse内部的radius这个需要注意的是,我们需要半径大于控件的宽,如果radius过小,显示的水波纹就是一个很小的圆,
   //水波纹的半径
   radius: 300.0,
   //水波纹的颜色
   splashColor: Colors.yellow,
   //true表示要剪裁水波纹响应的界面 false不剪裁 如果控件是圆角不剪裁的话水波纹是矩形
   containedInkWell: true,
   //点击事件
   onTap: () {
    print("click");
   },
   child: Container(
    //设置 child 居中
    alignment: Alignment(0, 0),
    height: 50,
    width: 300,
    child: Text("点击 Container 圆角边框"),
   ),
   ),
  ),
  ),
 ),

来源:https://blog.csdn.net/zl18603543572/article/details/95641481

标签:flutter,Container,圆角边框
0
投稿

猜你喜欢

  • 基于springboot搭建的web系统架构的方法步骤

    2023-11-21 13:33:51
  • JAVA基本概念详解

    2022-06-09 11:54:53
  • Java继承的问题引导和测试代码

    2023-03-13 18:50:34
  • Java实现的微信图片处理工具类【裁剪,合并,等比例缩放等】

    2022-03-26 11:32:59
  • JAVA中的基本数据类型

    2023-07-29 07:38:34
  • ElasticSearch学习之ES Mapping实战示例

    2023-11-25 06:12:25
  • springboot搭建访客管理系统的实现示例

    2023-09-02 13:10:41
  • Springboot内置tomcat配置虚拟路径过程解析

    2021-12-21 06:06:03
  • 基于hibernate框架在eclipse下的配置方法(必看篇)

    2022-11-09 20:30:26
  • Java的锁机制:synchronized和CAS详解

    2023-03-18 16:04:00
  • Java进程cpu占用过高问题解决

    2021-08-09 00:16:59
  • 利用java实现中奖概率详情

    2021-08-10 06:56:58
  • java实现MD5加密的方法小结

    2022-02-26 20:01:47
  • JavaMailSender实现邮箱验证功能

    2022-05-11 12:32:59
  • Java中常见的5种WEB服务器介绍

    2022-08-02 08:45:50
  • Java二维数组实战案例

    2022-08-13 08:59:25
  • springMVC利用FastJson接口返回json数据相关配置详解

    2023-02-24 10:51:58
  • 详解Android的网络数据存储

    2022-08-22 01:39:39
  • C#使用iTextSharp添加PDF水印

    2021-10-09 08:59:27
  • java结合keytool如何实现非对称签名和验证详解

    2021-12-21 21:49:35
  • asp之家 软件编程 m.aspxhome.com