Skip to content

Instantly share code, notes, and snippets.

@fladago
Created September 4, 2021 10:19
Show Gist options
  • Save fladago/d2d31a41a392c05feec4926255b546f7 to your computer and use it in GitHub Desktop.
Save fladago/d2d31a41a392c05feec4926255b546f7 to your computer and use it in GitHub Desktop.
Triangle
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(0, 0),
blurRadius: 0,
spreadRadius: 30),
BoxShadow(
color: Colors.blue,
offset: Offset(0, 0),
blurRadius: 0,
),
],
),
),
),
),
));
}
}
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}) {
return Path()
..moveTo(rect.left + 66.5, rect.top)
..lineTo(rect.left + 133, rect.top + 110)
..lineTo(rect.left, rect.top + 110)
..lineTo(rect.left + 66.5, 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