简体   繁体   English

如何在颤振中形成这样的圆形?

[英]How to have a circle shape like this in flutter?

I am trying to have a circle shape like this in my flutter project.我试图在我的颤振项目中使用这样的圆形。 I tried using border-radius in a container.我尝试在容器中使用 border-radius 。 But it didn't work as I expected.但它并没有像我预期的那样工作。

So, how can I have a shape like this given picture?那么,我怎么能有这样一张给定图片的形状呢?

图片

I tried using a container like this.我尝试使用这样的容器。

    Container(
            height: 72,
            width: 211,
            decoration: BoxDecoration(
              color: Colors.blue,
              borderRadius: BorderRadius.only(
                topRight: Radius.circular(50),
                topLeft: Radius.circular(30))
            ),
          )

You can draw almost anything using CustomPaint, take a look:您几乎可以使用 CustomPaint 绘制任何东西,看看:

https://api.flutter.dev/flutter/rendering/CustomPainter-class.html https://api.flutter.dev/flutter/rendering/CustomPainter-class.html

In the code below, I draw something like that circle:在下面的代码中,我画了类似那个圆圈的东西:

在此处输入图片说明

import "package:flutter/material.dart";

void main() {
  runApp(MaterialApp(title: "", home: Home()));
}

class Home extends StatefulWidget {
  @override
  _HomeState createState() => _HomeState();
}

class _HomeState extends State<Home> {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(),
        body: Container(
            width: double.infinity,
            height: double.infinity,
            child: CustomPaint(
              painter: CirclePainter(),
            )),
      ),
    );
  }
}

class CirclePainter extends CustomPainter {
  final Paint lightBluePaint = Paint()..color = Color(0xFFbde5fa);
  final Paint bluePaint = Paint()..color = Color(0xFF5abef2);
  final TextPainter textPainter = TextPainter(
    textDirection: TextDirection.ltr,
  );

  final TextStyle textStyle = TextStyle(
      color: Colors.white.withAlpha(240),
      fontSize: 18,
      letterSpacing: 1.2,
      fontWeight: FontWeight.w900);

  @override
  void paint(Canvas canvas, Size size) {
    var rect = Rect.fromLTRB(
        -100, size.height - 120, size.width * 0.7, size.height + 250);

    final Path circle = Path()..addOval(rect);
    final Path smallCircle = Path()..addOval(rect.inflate(50));

    canvas.drawPath(smallCircle, lightBluePaint);
    canvas.drawPath(circle, bluePaint);

    drawText(canvas, size, 'Write now');
  }

  void drawText(Canvas canvas, Size size, String text) {
    textPainter.text = TextSpan(style: textStyle, text: text);
    textPainter.layout();
    textPainter.paint(canvas, Offset(50, size.height - 60));
  }

  @override
  bool shouldRepaint(CustomPainter oldDelegate) {
    return true;
  }
}

to implement your image preview you need to use Stack Class with Positioned elements.要实现图像预览,您需要将Stack Class 与Positioned元素一起使用。 I made a widget as your picture shown.我做了一个小部件,如你的图片所示。 circles in corners can be made with container with border-radius.角落里的圆圈可以用带有边界半径的容器制作。

  Container(
    width: MediaQuery.of(context).size.width,
    height: 250,
    margin: EdgeInsets.all(20),
    decoration: BoxDecoration(
      color: Colors.white,
      boxShadow: <BoxShadow>[
        BoxShadow(
          color: Color(0x40000000),
          blurRadius: 5.0,
          spreadRadius: 0.0,
          offset: Offset(0.0, 2.0),
        ),
      ],
    ),
    child: Stack(
      children: <Widget>[
        Container(
          padding: EdgeInsets.all(15.0),
          child: Column(
            crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Text(
                'Step 3',
                style: TextStyle(
                  color: Colors.blue,
                ),
              ),
              SizedBox(height: 5),
              Text(
                'It is a long established fact that a reader will be '
                  'distracted by the readable content of a page when '
                  'looking at its layout.',
                style: TextStyle(
                  color: Colors.black54,
                ),
              )
            ],
          ),
        ),
        Positioned(
          top: 150,
          right: MediaQuery.of(context).size.width - 200,
          child: Container(
            width: 200,
            height: 200,
            decoration: BoxDecoration(
              color: Color(0xFFB5E1F9),
              borderRadius: BorderRadius.all(
                Radius.circular(200),
              ),
            ),
            child: Center(
              child: Container(
                width: 150,
                height: 150,
                decoration: BoxDecoration(
                  color: Color(0xFF4FB6F0),
                  borderRadius: BorderRadius.all(
                    Radius.circular(150),
                  ),
                ),
              ),
            ),
          ),
        ),
        Positioned(
          bottom: 30,
          left: 30,
          child: Text(
            'Write now',
            style: TextStyle(
              color: Colors.white,
            ),
          ),
        ),
      ],
    ),
  );

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在圆内动态创建圆(像甜甜圈) - How to create a circle inside a circle dynamically (like a donut) 想在 Flutter 中制作像按钮一样的圆形饼图形状 - want to make circular pie chart shape like buttons in Flutter android如何使内视图圆形状如图所示 - android how to make inner view circle shape as shown in Picture 如何绘制一个四分之三的圆作为颤振中的边框? - How to draw a 3 quarter circle for using as the border in the flutter? 如何在 flutter 中制作圆形标签指示器 - How to make a circle shaped tab indicator in flutter 如何在 flutter 中制作自定义按钮形状 - How to make a custom button shape in flutter 在 Flutter 中,如何创建一个像 Uber 这样的 UI 以在中间和 AppBar 中有 map 并导航到不同类型的视图 - In Flutter, how to create an UI like Uber to have map in middle and AppBar and navigate to different type of views Flutter 中的自定义形状 - Custom Shape in Flutter 请参阅随附的快照。 我在 flutter 中通过容器创建了这样的圆框。但我正在寻找小部件。 flutter 有它的小部件吗? - See attached snapshot. I have created such circle box through container in flutter. But I am seeking for widget. Do flutter have a widget for it? 如何在 Flutter 中创建如下 UI - How to create a UI like below in Flutter
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM