Skip to content

Instantly share code, notes, and snippets.

@manthri-mohan-sai
Last active October 5, 2022 16:02
Show Gist options
  • Save manthri-mohan-sai/0cc9f5ad27e13bc76b8cee125dabfd71 to your computer and use it in GitHub Desktop.
Save manthri-mohan-sai/0cc9f5ad27e13bc76b8cee125dabfd71 to your computer and use it in GitHub Desktop.
How to draw Arc?
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
theme: ThemeData.dark().copyWith(
scaffoldBackgroundColor: darkBlue,
),
debugShowCheckedModeBanner: false,
home: Scaffold(
body: Center(
child: MyWidget(),
),
),
);
}
}
class MyWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Stack(
alignment: Alignment.bottomRight,
children: [
const CircleAvatar(
radius: 128,
backgroundColor: Colors.blue,
),
SizedBox(
height: 256,
width: 256,
child: CustomPaint(
painter: ArcPainter(),
child: Container(),
),
),
],
);
}
}
class ArcPainter extends CustomPainter {
@override
void paint(Canvas canvas, Size size) {
var paint = Paint()
..color = Colors.yellow
..strokeWidth = 3
..style = PaintingStyle.fill;
final path = Path();
path
..moveTo((size.width / 2.8), size.height * .15)
..arcToPoint(
Offset(size.width / 4, size.height * .85),
clockwise: true,
largeArc: false,
radius: const Radius.circular(20),
)
..arcToPoint(
Offset(size.width / 4.8, size.height * .15),
clockwise: false,
largeArc: false,
radius: const Radius.circular(20),
);
canvas.drawPath(path, paint);
}
@override
bool shouldRepaint(covariant CustomPainter oldDelegate) {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment