栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 面试经验 > 面试问答

Flutter中的弧形渐变?

面试问答 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

Flutter中的弧形渐变?

您所需的矩形实际上是一个正方形,您要绘制的圆将适合该正方形。圆弧只是那圆弧中扫过许多弧度的一片馅饼。使用

Rect.fromCircle
,使用中心和半径创建此正方形。然后在创建渐变和绘制圆弧时使用此正方形。

这是一个例子

import 'dart:math';import 'package:flutter/material.dart';class X1Painter extends CustomPainter {  @override  void paint(Canvas canvas, Size size) {    // create a bounding square, based on the centre and radius of the arc    Rect rect = new Rect.fromCircle(      center: new Offset(165.0, 55.0),      radius: 180.0,    );    // a fancy rainbow gradient    final Gradient gradient = new RadialGradient(      colors: <Color>[        Colors.green.withOpacity(1.0),        Colors.green.withOpacity(0.3),        Colors.yellow.withOpacity(0.2),        Colors.red.withOpacity(0.1),        Colors.red.withOpacity(0.0),      ],      stops: [        0.0,        0.5,        0.7,        0.9,        1.0,      ],    );    // create the Shader from the gradient and the bounding square    final Paint paint = new Paint()..shader = gradient.createShader(rect);    // and draw an arc    canvas.drawArc(rect, pi / 4, pi * 3 / 4, true, paint);  }  @override  bool shouldRepaint(X1Painter oldDelegate) {    return true;  }}class X1Demo extends StatelessWidget {  @override  Widget build(BuildContext context) {    return new Scaffold(      appBar: new AppBar(title: const Text('Arcs etc')),      body: new CustomPaint(        painter: new X1Painter(),      ),    );  }}void main() {  runApp(    new MaterialApp(      theme: new ThemeData.dark(),      home: new X1Demo(),    ),  );}


转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/401836.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号