Skip to content

Instantly share code, notes, and snippets.

@CoderNamedHendrick
Created October 31, 2022 17:27
Show Gist options
  • Save CoderNamedHendrick/92e06aa51e3b1d8e0de950ecd8997354 to your computer and use it in GitHub Desktop.
Save CoderNamedHendrick/92e06aa51e3b1d8e0de950ecd8997354 to your computer and use it in GitHub Desktop.
Arc Cliper
import 'package:flutter/material.dart';
const Color darkBlue = Color.fromARGB(255, 18, 32, 47);
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({super.key});
@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 ClipPath(
clipper: ArcClipper(),
child: Container(
height: 150,
width: 200,
color: Colors.pink,
),
);
}
}
class ArcClipper extends CustomClipper<Path> {
@override
Path getClip(Size size) {
const radius = 20.0;
final path = Path()
..moveTo(0, 0)
..lineTo(0, size.height)
..lineTo((size.width / 2) - radius * 2, size.height)
..arcToPoint(Offset((size.width / 2) + radius * 2, size.height),
radius: const Radius.circular(radius * 2))
..lineTo(size.width, size.height)
..lineTo(size.width, 0)
..close();
return path;
}
@override
bool shouldReclip(covariant CustomClipper oldClipper) => true;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment