Метод addRRect
Метод addRRect класса Path копирует форму RRect в Path.
В путь копируются края и радиусы углов из RRect.
Синтаксис
Path.addRRect()
Пример
Давайте построим контур через addRRect:
import 'package:flutter/material.dart';
void main()
{
runApp(
MaterialApp(
home: Scaffold(
body: Center(
child: CustomPaint(
size: const Size(220, 100),
painter: _PathAddrrectPainter(),
),
),
),
),
);
}
class _PathAddrrectPainter extends CustomPainter
{
@override
void paint(Canvas canvas, Size size)
{
final path = Path();
path.addRRect(RRect.fromRectAndRadius(
Rect.fromLTWH(40, 20, 140, 60), Radius.circular(12)));
final paint = Paint()
..color = Colors.deepPurple
..strokeWidth = 3
..style = PaintingStyle.stroke;
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
}
На экране линия или контур, построенный через Path.
Пример
Давайте утолщим линию:
import 'package:flutter/material.dart';
void main()
{
runApp(
MaterialApp(
home: Scaffold(
body: Center(
child: CustomPaint(
size: const Size(220, 100),
painter: _PathAddrrectPainter2(),
),
),
),
),
);
}
class _PathAddrrectPainter2 extends CustomPainter
{
@override
void paint(Canvas canvas, Size size)
{
final path = Path();
path.addRRect(RRect.fromRectAndRadius(
Rect.fromLTWH(40, 20, 140, 60), Radius.circular(12)));
paint.strokeWidth = 6;
final paint = Paint()
..color = Colors.deepPurple
..strokeWidth = 3
..style = PaintingStyle.stroke;
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) => false;
}
На экране тот же контур с более толстой линией.
Смотрите также
-
класс
Paint,
кисть холста -
класс
Canvas,
холст внутриCustomPainter -
перечисление
BoxShape,
прямоугольник или круг -
перечисление
BorderStyle,
есть линия или нет