【Flutter】shape 属性 ShapeBorder,形状
创始人
2024-02-11 05:45:44

文章目录

  • 前言
  • 一、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.@overrideWidget 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;@overrideState createState() => _MyHomePageState();
}class _MyHomePageState extends State {@overrideWidget 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),),)],)));}
}

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

相关内容

热门资讯

埃菲尔铁塔在哪 中国仿建埃菲尔... 2019年4月26日,广西南宁市,街头惊现一座巨型山寨版埃菲尔铁塔,高约20米,白色塔身,造型逼真,...
北京的名胜古迹 北京最著名的景... 北京从元代开始,逐渐走上帝国首都的道路,先是成为大辽朝五大首都之一的南京城,随着金灭辽,金代从海陵王...
苗族的传统节日 贵州苗族节日有... 【岜沙苗族芦笙节】岜沙,苗语叫“分送”,距从江县城7.5公里,是世界上最崇拜树木并以树为神的枪手部落...
应用未安装解决办法 平板应用未... ---IT小技术,每天Get一个小技能!一、前言描述苹果IPad2居然不能安装怎么办?与此IPad不...
脚上的穴位图 脚面经络图对应的... 人体穴位作用图解大全更清晰直观的标注了各个人体穴位的作用,包括头部穴位图、胸部穴位图、背部穴位图、胳...
长白山自助游攻略 吉林长白山游... 昨天介绍了西坡的景点详细请看链接:一个人的旅行,据说能看到长白山天池全凭运气,您的运气如何?今日介绍...
猫咪吃了塑料袋怎么办 猫咪误食... 你知道吗?塑料袋放久了会长猫哦!要说猫咪对塑料袋的喜爱程度完完全全可以媲美纸箱家里只要一有塑料袋的响...
demo什么意思 demo版本... 618快到了,各位的小金库大概也在准备开闸放水了吧。没有小金库的,也该向老婆撒娇卖萌服个软了,一切只...
世界上最漂亮的人 世界上最漂亮... 此前在某网上,选出了全球265万颜值姣好的女性。从这些数量庞大的女性群体中,人们投票选出了心目中最美...
苗族的传统节日 贵州苗族节日有... 【岜沙苗族芦笙节】岜沙,苗语叫“分送”,距从江县城7.5公里,是世界上最崇拜树木并以树为神的枪手部落...
北京的名胜古迹 北京最著名的景... 北京从元代开始,逐渐走上帝国首都的道路,先是成为大辽朝五大首都之一的南京城,随着金灭辽,金代从海陵王...
应用未安装解决办法 平板应用未... ---IT小技术,每天Get一个小技能!一、前言描述苹果IPad2居然不能安装怎么办?与此IPad不...
脚上的穴位图 脚面经络图对应的... 人体穴位作用图解大全更清晰直观的标注了各个人体穴位的作用,包括头部穴位图、胸部穴位图、背部穴位图、胳...