美文网首页
Flutter #03 各种形状布局清单

Flutter #03 各种形状布局清单

作者: 喜欢书的女孩 | 来源:发表于2020-11-13 09:22 被阅读0次
image

目录:

  1. 正方形
  2. 圆形
  3. 椭圆
  4. 三角形
  5. 五角星
  6. 总结

1. 正方形

(1)普通正方形

    @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('shape: 正方形')),
      body: Center(
        child: Container(
          height: 200,
          width: 200,
          decoration: BoxDecoration(color: Colors.pinkAccent),
        ),
      ),
    );
  }

image

(2)立体正方形

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('shape: 立体正方形')),
      body: Center(
        child: Container(
          height: 200,
          width: 200,
          decoration: BoxDecoration(
            color: Colors.red,
            boxShadow: const [
              BoxShadow(blurRadius: 10),
            ],
          ),
        ),
      ),
    );
  }

image

(3) 线性渐变正方形

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('shape: 线性渐变正方形')),
      body: Center(
        child: Container(
          height: 200,
          width: 200,
          decoration: BoxDecoration(
            gradient: LinearGradient(
              colors: const [
                Colors.red,
                Colors.blue,
              ],
            ),
          ),
        ),
      ),
    );
  }

image

(4)渲染正方形

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('shape: 渲染正方形')),
      body: Center(
        child: Container(
          height: 200,
          width: 200,
          decoration: BoxDecoration(
            gradient: RadialGradient(
              colors: const [Colors.yellow, Colors.blue],
              stops: const [0.4, 1.0],
            ),
          ),
        ),
      ),
    );
  }

image

(5)五彩正方形

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('shape: 五彩正方形')),
      body: Center(
        child: Container(
          height: 200,
          width: 200,
          decoration: BoxDecoration(
            gradient: SweepGradient(
              colors: const [
                Colors.blue,
                Colors.green,
                Colors.yellow,
                Colors.red,
                Colors.blue,
              ],
              stops: const [0.0, 0.25, 0.5, 0.75, 1.0],
            ),
          ),
        ),
      ),
    );
  }

image

(6)图片阴影正方形

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('shape:图片背景正方形')),
      body: Center(
        child: Container(
          height: 200,
          width: 200,
          foregroundDecoration: BoxDecoration(
            backgroundBlendMode: BlendMode.exclusion,
            gradient: LinearGradient(
              colors: const [
                Colors.red,
                Colors.blue,
              ],
            ),
          ),
          child: Image.network(
            'https://flutter.io/images/catalog-widget-placeholder.png',
          ),
        ),
      ),
    );
  }

image

2. 圆形

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('shape: 圆形')),
      body: Center(
        child: Container(
          height: 200,
          width: 200,
          decoration: BoxDecoration(
            color: Colors.purpleAccent,
            shape: BoxShape.circle,
          ),
        ),
      ),
    );
  }

image

3. 椭圆

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('shape: 椭圆')),
      body: Center(
        child: Container(
          height: 200,
          width: 200,
          decoration: BoxDecoration(
            color: Colors.yellow,
            border: Border.all(color: Colors.yellowAccent, width: 2),
            borderRadius: BorderRadius.all(Radius.circular(18)),
          ),
        ),
      ),
    );
  }

image

4. 三角形

 @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('shape: 三角形')),
      body: Center(
        child: Container(
          height: 400,
          width: 400,
          transform: Matrix4.rotationZ(pi /4),
          decoration: BoxDecoration(color: Colors.green),
        ),
      ),
    );
  }

image

5. 五角星

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('shape: 五角星')),
      body:Row /*or Column*/(
        mainAxisAlignment: MainAxisAlignment.center,
        children: <Widget>[
          Icon(Icons.star, size: 50),
          Icon(Icons.star, size: 50),
          Icon(Icons.star_half, size: 50),
        ],
      ),
    );
  }

image

6. 总结


文章是 Android 面向需求开发系列中的一文,更多相关文章请关注。如若有什么问题,也可以通过扫描二维码发消息给我。转载请注明出处,谢谢!

image

相关文章

  • Flutter #03 各种形状布局清单

    目录:正方形圆形椭圆三角形五角星总结 1. 正方形 (1)普通正方形 (2)立体正方形 (3) 线性渐变正方形 (...

  • Flutter #03 各种形状布局清单

    目录:正方形圆形椭圆三角形五角星总结 1. 正方形 (1)普通正方形 (2)立体正方形 (3) 线性渐变正方形 (...

  • Flutter 布局

    Flutter 布局详解 Flutter 布局(一)- Container详解 Flutter 布局(二)- Pa...

  • Flutter-布局

    一、介绍 flutter布局需要先了解flutter所有布局的widget,首先flutter布局分为Contai...

  • Flutter-汇总

    Flutter(一)--Flutter安装遇到的问题汇总 Flutter(二)--布局机制、布局步骤、水平和垂直布...

  • Flutter旋转位移等操作

    flutter布局-5-Matrix4矩阵变换Flutter 布局(六)- SizedOverflowBox、Tr...

  • flutter布局-3-center

    Center 居中的布局 连载:flutter布局-1-column连载:flutter布局-2-row 只能有一...

  • Flutter及Dart入门

    目录 Dart语言下的Flutter Flutter Widget Flutter 布局 Flutter 页面 路...

  • flutter(六,页面布局篇)

    Tags: flutter Flutter页面布局篇 [TOC] 1. 布局及装饰组件说明 2. 基础布局处理 2...

  • 从零开始学Flutter--布局widget

    Flutter里面的布局都是由各种widget组成的,所以有必要熟悉一下各种widget 基础 Widgets 名...

网友评论

      本文标题:Flutter #03 各种形状布局清单

      本文链接:https://www.haomeiwen.com/subject/dcwpbktx.html