Skip to content

Instantly share code, notes, and snippets.

@fladago
Last active August 26, 2021 11:04
Show Gist options
  • Save fladago/8d301baf9c9c0577a25cdd5c8939ba8b to your computer and use it in GitHub Desktop.
Save fladago/8d301baf9c9c0577a25cdd5c8939ba8b to your computer and use it in GitHub Desktop.
#1 Shape of the day
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: Scaffold(
body: Center(
child: Material(
elevation: 10,
child: Container(
width: 230,
height: 230,
decoration: const ShapeDecoration(
shape: MessageBorder(),
// color: Colors.teal,
gradient: RadialGradient(colors: [
Colors.red,
Colors.green,
Colors.blue,
]),
shadows: [
BoxShadow(
color: Colors.black,
offset: Offset(3, 5),
blurRadius: 5,
spreadRadius: 0),
BoxShadow(
color: Colors.blue,
offset: Offset(-3, -5),
blurRadius: 5,
),
],
),
),
),
),
));
}
}
class MessageBorder extends ShapeBorder {
final bool usePadding;
const MessageBorder({this.usePadding = true});
@override
EdgeInsetsGeometry get dimensions => const EdgeInsets.only(bottom: 0);
@override
Path getInnerPath(Rect rect, {TextDirection? textDirection}) =>
getOuterPath(rect, textDirection: textDirection);
@override
Path getOuterPath(Rect rect, {TextDirection? textDirection}) {
rect = Rect.fromPoints(rect.topLeft - const Offset(-10, -10),
rect.bottomRight - const Offset(0, 0));
return Path()
..moveTo(143.58 + rect.left, 0 + rect.top)
..cubicTo(148.42 + rect.left, -7.37 + rect.top, 159.88 + rect.left,
-2.62 + rect.top, 158.1 + rect.left, 6.01 + rect.top)
..lineTo(147.28 + rect.left, 58.34 + rect.top)
..cubicTo(146.12 + rect.left, 63.97 + rect.top, 151.1 + rect.left,
68.96 + rect.top, 156.74 + rect.left, 67.79 + rect.top)
..lineTo(209.06 + rect.left, 56.98 + rect.top)
..cubicTo(217.7 + rect.left, 55.2 + rect.top, 222.45 + rect.left,
66.65 + rect.top, 215.08 + rect.left, 71.5 + rect.top)
..lineTo(170.43 + rect.left, 100.85 + rect.top)
..cubicTo(165.62 + rect.left, 104.01 + rect.top, 165.62 + rect.left,
111.06 + rect.top, 170.43 + rect.left, 114.22 + rect.top)
..lineTo(215.08 + rect.left, 143.58 + rect.top)
..cubicTo(222.45 + rect.left, 148.42 + rect.top, 217.7 + rect.left,
159.88 + rect.top, 209.06 + rect.left, 158.1 + rect.top)
..lineTo(156.74 + rect.left, 147.28 + rect.top)
..cubicTo(151.1 + rect.left, 146.12 + rect.top, 146.12 + rect.left,
151.1 + rect.top, 147.28 + rect.left, 156.74 + rect.top)
..lineTo(158.1 + rect.left, 209.06 + rect.top)
..cubicTo(159.88 + rect.left, 217.7 + rect.top, 148.42 + rect.left,
222.45 + rect.top, 143.58 + rect.left, 215.08 + rect.top)
..lineTo(114.22 + rect.left, 170.43 + rect.top)
..cubicTo(111.06 + rect.left, 165.62 + rect.top, 104.01 + rect.left,
165.62 + rect.top, 100.85 + rect.left, 170.43 + rect.top)
..lineTo(71.5 + rect.left, 215.08 + rect.top)
..cubicTo(66.65 + rect.left, 222.45 + rect.top, 55.2 + rect.left,
217.7 + rect.top, 56.98 + rect.left, 209.06 + rect.top)
..lineTo(67.79 + rect.left, 156.74 + rect.top)
..cubicTo(68.96 + rect.left, 151.1 + rect.top, 63.97 + rect.left,
146.12 + rect.top, 58.34 + rect.left, 147.28 + rect.top)
..lineTo(6.01 + rect.left, 158.1 + rect.top)
..cubicTo(-2.62 + rect.left, 159.88 + rect.top, -7.37 + rect.left,
148.42 + rect.top, 0 + rect.left, 143.58 + rect.top)
..lineTo(44.65 + rect.left, 114.22 + rect.top)
..cubicTo(49.45 + rect.left, 111.06 + rect.top, 49.45 + rect.left,
104.01 + rect.top, 44.65 + rect.left, 100.85 + rect.top)
..lineTo(0 + rect.left, 71.5 + rect.top)
..cubicTo(-7.37 + rect.left, 66.65 + rect.top, -2.62 + rect.left,
55.2 + rect.top, 6.01 + rect.left, 56.98 + rect.top)
..lineTo(58.34 + rect.left, 67.79 + rect.top)
..cubicTo(63.97 + rect.left, 68.96 + rect.top, 68.96 + rect.left,
63.97 + rect.top, 67.79 + rect.left, 58.34 + rect.top)
..lineTo(56.98 + rect.left, 6.01 + rect.top)
..cubicTo(55.2 + rect.left, -2.62 + rect.top, 66.65 + rect.left,
-7.37 + rect.top, 71.5 + rect.left, 0 + rect.top)
..lineTo(100.85 + rect.left, 44.65 + rect.top)
..cubicTo(104.01 + rect.left, 49.45 + rect.top, 111.06 + rect.left,
49.45 + rect.top, 114.22 + rect.left, 44.65 + rect.top)
..lineTo(143.58 + rect.left, 0 + rect.top)
..close();
}
@override
void paint(Canvas canvas, Rect rect, {TextDirection? textDirection}) {}
@override
ShapeBorder scale(double t) => this;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment