【问题标题】:How I can fill space between 2 circle in flutter?如何在颤动中填充 2 个圆圈之间的空间?
【发布时间】:2021-09-23 00:36:25
【问题描述】:

我的圈画师:

    CircleWavePainter(this.animationValue) {
//add some property to paint
  wavePaint = Paint()
    ..color = Colors.black.withAlpha(100)
    ..style = PaintingStyle.stroke
    ..strokeWidth = 1
    ..isAntiAlias = true;
}

我的油漆要画 2 个圆圈,需要一些帮助来填充空间:

void paint(Canvas canvas, Size size) {
//circle 1
canvas.drawCircle(Offset(size.height / 2, size.width / 2),
80 * (1.4 - animationValue / 2), wavePaint);
//circle 2    
canvas.drawCircle(Offset(size.height / 2, size.width / 2),
80 * (1.8 - animationValue / 2), wavePaint);
}

【问题讨论】:

  • 你在大圆圈上填充颜色,然后用白色在大圆圈上的小圆圈上再次绘制如何?
  • 我需要可用空间来在圆的中心显示一个小部件。所以你说的方式很好,但在这种情况下不是:(
  • 正如 Abdallah 所说,在圆心使用 Stack 绘制大小和小部件。
  • link 如你所见,当“WaveCircles”的不透明度发生变化时,圆心的图标是模糊的。
  • 请再次查看我发布的内容。

标签: flutter dart flutter-layout flutter-animation flutter-design


【解决方案1】:

使用“Stack”小部件而不是“Paint”,实现了您的设计。

import 'package:flutter/material.dart';

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

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',
      theme: ThemeData(
        primarySwatch: Colors.blue,
        visualDensity: VisualDensity.adaptivePlatformDensity,
      ),
      home: MyHomePage(title: 'Flutter Demo Home Page'),
    );
  }
}

class MyHomePage extends StatefulWidget {
  MyHomePage({Key key, this.title}) : super(key: key);

  final String title;

  @override
  _MyHomePageState createState() => _MyHomePageState();
}

class _MyHomePageState extends State<MyHomePage> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: Text(widget.title),
      ),
      body: _buildBody(),
    );
  }

  Widget _buildBody() {
    return Container(
      height: 400,
      width: 400,
      child: Stack(
        alignment: AlignmentDirectional.center,
        children: [
          Container(
            width: 280,
            height: 280,
            decoration: BoxDecoration(
              shape: BoxShape.circle,
              color: Color(0xFF4C4D4F),
            ),
          ),
          Container(
            width: 200,
            height: 200,
            decoration: BoxDecoration(
              shape: BoxShape.circle,
              color: Colors.white,
            ),
          ),
          Container(
            width: 140,
            height: 140,
            child: Icon(
              Icons.access_alarm,
              color: Colors.white,
              size: 30,
            ),
            decoration: BoxDecoration(
              shape: BoxShape.circle,
              color: Color(0xFF5EA2EB),
            ),
          )
        ],
      ),
    );
  }
}

【讨论】:

  • 谢谢你,我已经完成了我想做的事情
【解决方案2】:

你可以使用 stack Widget 我在我的课程中没有达到动画,但我可以给你一个提示

Stack(
        alignment: AlignmentDirectional.bottomEnd,
        children: [
          CircleAvatar(
            radius: 30,
            backgroundImage: NetworkImage(
              'https://thispersondoesnotexist.com/image',
            ),
          ), //photo
          CircleAvatar(
            radius: 7,
            backgroundColor: Colors.white,
          ), // active or not
          CircleAvatar(
            radius: 6,
            backgroundColor: Colors.green,
          ), // active circle space
        ],
      )

【讨论】: