Skip to content

Instantly share code, notes, and snippets.

@stargazing-dino
Last active July 4, 2019 16:10
Show Gist options
  • Save stargazing-dino/bf76387534cf83753c0c9c80d2a33a6b to your computer and use it in GitHub Desktop.
Save stargazing-dino/bf76387534cf83753c0c9c80d2a33a6b to your computer and use it in GitHub Desktop.
MoneyRow
import 'package:flutter/material.dart';
class MoneyRow extends StatelessWidget {
const MoneyRow({
Key key,
@required this.name,
@required this.amount,
}) : super(key: key);
final name; // String or Widget
final amount; // String or Widget or TextSpan
@override
Widget build(BuildContext context) {
return IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.baseline,
textBaseline: TextBaseline.alphabetic,
children: <Widget>[
name is String
? Text(
name,
// style: Theme.of(context).textTheme.title,
)
: name is Text
? name
: throw ('Name must be of type String or Text'),
Expanded(
flex: 1,
child: Align(
alignment: Alignment.bottomCenter,
child: Container(
margin: const EdgeInsets.only(bottom: 13, left: 8, right: 8),
width: double.infinity,
child:
CustomPaint(painter: LineDashedPainter(context: context)),
),
),
),
amount is Text
? amount
: amount is String
? RichText(
text: TextSpan(
children: <TextSpan>[
TextSpan(
text: '\$',
style: Theme.of(context).textTheme.body1,
),
TextSpan(
text: '$amount',
style: Theme.of(context).textTheme.display1,
),
],
),
)
: amount is TextSpan
? RichText(
text: TextSpan(
children: <TextSpan>[
TextSpan(
text: '\$',
style: Theme.of(context).textTheme.body1,
),
amount,
],
),
)
: throw ('Amount must be of type String | Widget or TextSpan'),
],
),
);
}
}
class LineDashedPainter extends CustomPainter {
const LineDashedPainter({
@required this.context,
});
final BuildContext context;
@override
void paint(Canvas canvas, Size size) {
canvas.translate(0, size.height);
var paint = Paint()
..strokeWidth = 2
..color = Theme.of(context).textTheme.body1.color;
var max = size.width;
var dashWidth = 2;
var dashSpace = 5;
double startX = 0;
while (max >= 0) {
canvas.drawLine(Offset(startX, 0), Offset(startX + dashWidth, 0), paint);
final space = (dashSpace + dashWidth);
startX += space;
max -= space;
}
}
@override
bool shouldRepaint(CustomPainter oldDelegate) => false;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment