【Flutter】shape 属性 ShapeBorder,形状

news2024/9/20 15:05:27

文章目录

  • 前言
  • 一、shape 是什么?
  • 二、不同的形状
    • 1.BeveledRectangleBorder
    • 2.Border
    • 3.CircleBorder圆形
    • 4.ContinuousRectangleBorder连续圆角
    • 5.StadiumBorder 体育场边界 ,药丸形状
    • 6.OutlineInputBorder外边框可以定制圆角
    • 7.UnderlineInputBorder下划线
  • 总结


在这里插入图片描述

前言


一、shape 是什么?

控件的形状,我们可以通过该shape来定制widget 的形状,来达到自己想还要的形状效果

二、不同的形状

下面的例子以card来给一个card 设置不同的形状

1.BeveledRectangleBorder

矩形边框:
通过调节circular 圆角半径

    return Scaffold(
        backgroundColor: Colors.amber,
        appBar: AppBar(
          // Here we take the value from the MyHomePage object that was created by
          // the App.build method, and use it to set our appbar title.
          title: Text(widget.title),
        ),
        body: const Center(
            child: Card(
              // 矩形边框 side 设置边框的颜色和厚度
          shape: BeveledRectangleBorder(
              borderRadius: BorderRadius.all(Radius.circular(15)),
              side: BorderSide(color: Colors.green, width: 1)),
          child: ListTile(
            trailing: Icon(Icons.shield),
            leading: Icon(Icons.shield_sharp),
          ),
        )));

在这里插入图片描述

2.Border

代码如下(示例):
可以设置方向的边框颜色和厚度

shape: Border(
          top: BorderSide(color: Colors.red, width: 2),
          right: BorderSide(color: Colors.green, width: 5),
          bottom: BorderSide(color: Colors.indigo, width: 7),
          left: BorderSide(color: Colors.pink, width: 12)),

该处使用的url网络请求的数据。

3.CircleBorder圆形

  Card(
      // 圆形
      shape:
          CircleBorder(side: BorderSide(color: Colors.red, width: 10)),
      child: ListTile(
        trailing: Icon(Icons.shield),
        leading: Icon(Icons.shield_sharp),
      ),
    )

在这里插入图片描述

4.ContinuousRectangleBorder连续圆角

  Card(
     // 连续的圆角矩形
     shape: ContinuousRectangleBorder(
         borderRadius: BorderRadius.all(Radius.circular(15)),
         side: BorderSide(color: Colors.red, width: 10)),
     child: ListTile(
       trailing: Icon(Icons.shield),
       leading: Icon(Icons.shield_sharp),
     ),
   )

在这里插入图片描述

5.StadiumBorder 体育场边界 ,药丸形状

          Card(
              // 药丸形状
              shape: StadiumBorder(
                  side: BorderSide(color: Colors.redAccent, width: 10)),
              child: ListTile(
                trailing: Icon(Icons.shield),
                leading: Icon(Icons.shield_sharp),
              ),
            )

在这里插入图片描述

6.OutlineInputBorder外边框可以定制圆角

        Card(
          // 外边框可以定制圆角
          shape: OutlineInputBorder(
              borderRadius: BorderRadius.all(Radius.circular(15)),
              borderSide: BorderSide(color: Colors.redAccent, width: 10)),
          child: ListTile(
            trailing: Icon(Icons.shield),
            leading: Icon(Icons.shield_sharp),
          ),
        )

在这里插入图片描述

7.UnderlineInputBorder下划线

       Card(
              // 下划线
              shape: UnderlineInputBorder(
                  borderRadius: BorderRadius.all(Radius.circular(15)),
                  borderSide: BorderSide(color: Colors.redAccent, width: 10)),
              child: ListTile(
                trailing: Icon(Icons.shield),
                leading: Icon(Icons.shield_sharp),
              ),
            )

在这里插入图片描述


总结

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  // This widget is the root of your application.
  
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        // This is the theme of your application.
        //
        // Try running your application with "flutter run". You'll see the
        // application has a blue toolbar. Then, without quitting the app, try
        // changing the primarySwatch below to Colors.green and then invoke
        // "hot reload" (press "r" in the console where you ran "flutter run",
        // or simply save your changes to "hot reload" in a Flutter IDE).
        // Notice that the counter didn't reset back to zero; the application
        // is not restarted.
        primarySwatch: Colors.blue,
      ),
      home: const MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  const MyHomePage({super.key, required this.title});

  // This widget is the home page of your application. It is stateful, meaning
  // that it has a State object (defined below) that contains fields that affect
  // how it looks.

  // This class is the configuration for the state. It holds the values (in this
  // case the title) provided by the parent (in this case the App widget) and
  // used by the build method of the State. Fields in a Widget subclass are
  // always marked "final".

  final String title;

  
  State<MyHomePage> createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  
  Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Colors.amber,
        appBar: AppBar(
          // Here we take the value from the MyHomePage object that was created by
          // the App.build method, and use it to set our appbar title.
          title: Text(widget.title),
        ),
        body: Center(
            child: Column(
          children: const [
            Card(
              // 矩形边框 side 设置边框的颜色和厚度
              shape: BeveledRectangleBorder(
                  borderRadius: BorderRadius.all(Radius.circular(15)),
                  side: BorderSide(color: Colors.green, width: 1)),
              child: ListTile(
                trailing: Icon(Icons.shield),
                leading: Icon(Icons.shield_sharp),
              ),
            ),
            Card(
              // 矩形边框 side 设置边框的颜色和厚度
              shape: Border(
                  top: BorderSide(color: Colors.red, width: 2),
                  right: BorderSide(color: Colors.green, width: 5),
                  bottom: BorderSide(color: Colors.indigo, width: 7),
                  left: BorderSide(color: Colors.pink, width: 12)),
              child: ListTile(
                trailing: Icon(Icons.shield),
                leading: Icon(Icons.shield_sharp),
              ),
            ),
            Card(
              // 圆形
              shape:
                  CircleBorder(side: BorderSide(color: Colors.red, width: 10)),
              child: ListTile(
                trailing: Icon(Icons.shield),
                leading: Icon(Icons.shield_sharp),
              ),
            ),
            Card(
              // 连续的圆角矩形
              shape: ContinuousRectangleBorder(
                  borderRadius: BorderRadius.all(Radius.circular(15)),
                  side: BorderSide(color: Colors.red, width: 10)),
              child: ListTile(
                trailing: Icon(Icons.shield),
                leading: Icon(Icons.shield_sharp),
              ),
            ),
            Card(
              // 药丸形状
              shape: StadiumBorder(
                  side: BorderSide(color: Colors.redAccent, width: 10)),
              child: ListTile(
                trailing: Icon(Icons.shield),
                leading: Icon(Icons.shield_sharp),
              ),
            ),
            Card(
              // 外边框可以定制圆角
              shape: OutlineInputBorder(
                  borderRadius: BorderRadius.all(Radius.circular(15)),
                  borderSide: BorderSide(color: Colors.redAccent, width: 10)),
              child: ListTile(
                trailing: Icon(Icons.shield),
                leading: Icon(Icons.shield_sharp),
              ),
            ),
            Card(
              // 下划线
              shape: UnderlineInputBorder(
                  borderRadius: BorderRadius.all(Radius.circular(15)),
                  borderSide: BorderSide(color: Colors.redAccent, width: 10)),
              child: ListTile(
                trailing: Icon(Icons.shield),
                leading: Icon(Icons.shield_sharp),
              ),
            )
          ],
        )));
  }
}

欢迎关注,留言,咨询,交流!
在这里插入图片描述

本文来自互联网用户投稿,该文观点仅代表作者本人,不代表本站立场。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如若转载,请注明出处:http://www.coloradmin.cn/o/31201.html

如若内容造成侵权/违法违规/事实不符,请联系多彩编程网进行投诉反馈,一经查实,立即删除!

相关文章

卡特兰数、真二叉树、出栈序列、n对括号合法表达式

一、本文主要介绍一下几个问题 什么是卡特兰数n对括号组成的合法表达式个数与卡特兰数的关系真二叉树的形态总数与卡特兰数的关系n个互异元素出栈序列数与卡特兰数的关系 1、什么是卡特兰数 卡特兰数是指满足以下递推关系的数&#xff1a; 这个数跟斐波拉契数列一样是一个递归…

腾格尔刚刚参加线上演唱会,又传《巴林塔娜》合作主题曲身价倍增

俗话说&#xff1a;人逢喜事精神爽。没有想到音乐老前辈腾格尔&#xff0c;因为一场线上演唱会&#xff0c;又枯木逢春老树发新芽了。说起音乐人腾格尔&#xff0c;这位来自草原上的歌神&#xff0c;曾经有很多部草原歌曲&#xff0c;都给大家留下了非常深刻的印象。 在腾格尔老…

顶象首届业务安全保卫战完美落幕,快来看看TOP10里有没有你!

今年双十一&#xff0c;顶象特别发起了首届业务安全保卫战&#xff0c;旨在召集白帽子们为业务安全贡献自己的一份力量。历经一个月&#xff0c;顶象首届业务安全保卫战已于20日正式落下帷幕。 截止11月20 日&#xff0c;顶象业务安全保卫战通过审核的业务安全情报&业务安…

会议信息管理系统SSM记录(五)

目录&#xff1a; &#xff08;1&#xff09;搜索员工 &#xff08;2&#xff09;查看会议室 &#xff08;3&#xff09;会议室详情 &#xff08;4&#xff09;添加会议室 &#xff08;1&#xff09;搜索员工 创建EmployeeController&#xff1a; public static final Inte…

11.23二叉树

目录 一.笔试强训习题订正 1.选择题 2.编程题-组队竞赛 3.删除公共字符 解法1 哈希映射思想 解法2 暴力解法 解法3 substring解法replaceAll() 二.二叉树相关Oj题 1.二叉树的遍历 2.二叉树分层遍历 三.二叉树的最近公共祖先 1.思路一 2.思路2 四.将二叉搜索树转化…

力扣(LeetCode)795. 区间子数组个数(C++)

模拟 有一种构想&#xff0c;只考虑上边界&#xff0c;在小边界和大边界之间的连续子数组个数 小于等于大边界的连续子数组个数 −-− 小于小边界的连续子数组个数。 连续子数组个数计算公式 sumn(n1)2sum \dfrac{n\times (n1)}{2}sum2n(n1)​ 长度为 nnn 的小于某上界的区间…

UML建模

UML定义了行为图&#xff08;动态&#xff09;和状态图&#xff08;静态&#xff09;两大类。&#xff08;分类依据&#xff1a;对象是否根据时间变化&#xff09; 下面简介一下用例图、类图、时序图和状态图的概念。 “41”视图模型 逻辑视图&#xff1a;逻辑试图主要是用来…

CV攻城狮入门VIT(vision transformer)之旅——近年超火的Transformer你再不了解就晚了!

&#x1f34a;作者简介&#xff1a;秃头小苏&#xff0c;致力于用最通俗的语言描述问题 &#x1f34a;专栏推荐&#xff1a;深度学习网络原理与实战 &#x1f34a;近期目标&#xff1a;写好专栏的每一篇文章 &#x1f34a;支持小苏&#xff1a;点赞&#x1f44d;&#x1f3fc;、…

PowerJob 定时从SFTP下载文件踩的坑

一. 业务需求 SFTP上有多个目录, 每小时要下载一次文件, 每个目录的下载任务都是一个独立的工作流任务. 二.问题描述 手动执行每个任务可以正常执行, 但是当所有任务都开启定定时任务执行时(每小时执行一次),任务实例就会报错. 三.问题分析 查看服务端和worker端的日志, …

【ML特征工程】第 2 章 :简单数字的花式技巧

&#x1f50e;大家好&#xff0c;我是Sonhhxg_柒&#xff0c;希望你看完之后&#xff0c;能对你有所帮助&#xff0c;不足请指正&#xff01;共同学习交流&#x1f50e; &#x1f4dd;个人主页&#xff0d;Sonhhxg_柒的博客_CSDN博客 &#x1f4c3; &#x1f381;欢迎各位→点赞…

PDF怎么转换成Word?给大家分享三种简单的转换方法

我们怎么把拿到手的PDF文件转换成Word文档格式呢&#xff1f;众所周知&#xff0c;PDF文件虽然没有办法能够直接在文件上进行编辑&#xff0c;但是我们可以借助一些编辑软件来实现这一操作&#xff0c;尽管这样还是会有很多小伙伴习惯在Word中来编辑文件内容&#xff0c;因此怎…

EasyRecovery2023重新找回丢失的文件数据恢复软件

Ontrack EasyRecovery2023易恢复一款数据文件恢复软件&#xff0c;号称最好的数据恢复软件&#xff01;可以全面恢复删除丢失数据&#xff0c;能对电脑误删文件恢复&#xff0c;格式化硬盘数据恢复&#xff0c;手机U盘数据恢复等等&#xff0c;威力非常的强大&#xff01;支持恢…

运动耳机怎么选,盘点目前适合运动的几款耳机

​相对于传统耳机而言&#xff0c;现如今越来越多的人喜欢使用骨传导耳机&#xff0c;毕竟无需入耳不管是在运动还是日常&#xff0c;防丢能力会更加好&#xff0c;耳挂式的佩戴更加不用担心在剧烈运动的情况下脱落&#xff0c;但在骨传导耳机中已经有了很多个品牌入驻&#xf…

先聊聊「堆栈」,再聊聊「逃逸分析」。Let’s Go!

要搞清楚GO的逃逸分析一定要先搞清楚内存分配和堆栈&#xff1a; 内存分配既可以分配到堆中&#xff0c;也可以分配到栈中。 什么样的数据会被分配到栈中&#xff0c;什么样的数据又会被分配到堆中呢&#xff1f; GO语言是如何进行内存分配的呢&#xff1f;其设计初衷和实现原…

云原生丨5大Datadog集成,快速提高团队效率!

Datadog是DevOps、开发人员和 SRE 团队的必备好物&#xff0c;它适用于各种规模的云应用程序。 然而&#xff0c;尽管 Datadog 功能十分强大&#xff0c;但大多数企业并没有充分发挥 Datadog 全部价值。 什么是 Datadog Datadog 是一个可观察性平台&#xff0c;提供监控、安…

3.1、数据链路层概述

3.1、数据链路层概述 3.1.1、数据链路层在网络体系结构中所处的地位 如下所示&#xff0c;主机 H1 给主机 H2 发送数据&#xff0c;中间要经过三个路由器和电话网、局域网以及广域网等多种网络 从五层协议原理体系结构的角度来看&#xff1a; 主机应具有体系结构中的各个层…

使用HTML制作静态网站:传统文化戏剧锡剧带psd设计图(2个页面)

&#x1f389;精彩专栏推荐 &#x1f4ad;文末获取联系 ✍️ 作者简介: 一个热爱把逻辑思维转变为代码的技术博主 &#x1f482; 作者主页: 【主页——&#x1f680;获取更多优质源码】 &#x1f393; web前端期末大作业&#xff1a; 【&#x1f4da;毕设项目精品实战案例 (10…

【项目_01】搭建项目基本框架、底部tabbar、头部banner | 旅途拾景 | 基于Vue3全家桶

&#x1f4ad;&#x1f4ad; ✨&#xff1a;搭建项目基本框架、底部tabbar、头部banner| 路途拾景 | 基于Vue3全家桶   &#x1f49f;&#xff1a;东非不开森的主页   &#x1f49c;: 因为很多东西来不及去做去看可是时间很快总是赶不上&#xff0c;所以要去成长呀&#x1f4…

作业-11.23

1、广播 接收端 #include <stdio.h> #include <sys/types.h> #include <sys/socket.h> #include <stdlib.h> #include <netinet/in.h> #include <netinet/ip.h> #include <arpa/inet.h> #include <unistd.h> #include <str…

Diffusion Autoencoders: Toward a Meaningful and Decodable Representation

​ Diffusion Autoencoders: Toward a Meaningful and Decodable Representation 扩散自编码器:面向有意义和可解码的表示 code&#xff1a;https://github.com/phizaz/diffae A CVPR 2022 (ORAL) paper (paper, site, 5-min video) Diffusion probabilistic models (DPMs) hav…