Skip to content

Instantly share code, notes, and snippets.

@stevenosse
Created July 5, 2020 22:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stevenosse/d245c66d4379ff392321c4d00a9114e8 to your computer and use it in GitHub Desktop.
Save stevenosse/d245c66d4379ff392321c4d00a9114e8 to your computer and use it in GitHub Desktop.
// Copyright (c) 2019, the Dart project authors. Please see the AUTHORS file
// for details. All rights reserved. Use of this source code is governed by a
// BSD-style license that can be found in the LICENSE file.
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: Center(
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Stack(children: <Widget>[
Container(
padding: EdgeInsets.symmetric(horizontal: 20, vertical: 20),
decoration: BoxDecoration(
border: Border.all(color: Color(0xFFFAD02E), width: 4),
// color: Colors.green,
borderRadius: BorderRadius.circular(20.0)),
child: Column(
children: <Widget>[
Text(
"\$2.97",
style:
TextStyle(fontSize: 30, fontWeight: FontWeight.w600),
),
SizedBox(
height: 5,
),
Text(
"2days",
style: TextStyle(fontSize: 18),
),
],
),
),
Positioned(
right: -0.5,
child: CustomPaint(
painter: TrianglePainter(
strokeColor: Color(0xFFFAD02E),
),
child: Container(
height: 28,
width: 35,
child: Padding(
padding: EdgeInsets.only(left: 12, bottom: 5),
child: Icon(Icons.check, size: 12, color: Colors.black),
),
),
),
),
])
],
),
),
);
}
}
class TrianglePainter extends CustomPainter {
final Color strokeColor;
TrianglePainter({this.strokeColor = Colors.black});
@override
void paint(Canvas canvas, Size size) {
Paint paint = Paint()
..color = strokeColor
..strokeWidth = 10
..style = PaintingStyle.fill;
canvas.drawPath(getTrianglePath(size.width, size.height), paint);
}
Path getTrianglePath(double x, double y) {
return Path()
..moveTo(y, 5)
..lineTo(0, 0)
..lineTo(y + 6, x - 6)
..lineTo(y, 6);
}
@override
bool shouldRepaint(TrianglePainter oldDelegate) {
return true;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment