This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BikeButton extends StatelessWidget { | |
@override | |
Widget build(BuildContext context) { | |
return Container( | |
height: 50.0, | |
child: CustomPaint( | |
painter: BikeButtonPainter(), | |
child: Center( | |
child: Text('Buy Tough Bike'.toUpperCase()), | |
), |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BikeButtonPainter extends CustomPainter { | |
final fillPaint = Paint()..color = Colors.grey; | |
@override | |
void paint(Canvas canvas, Size size) { | |
// This [Rect] will fill the whole canvas we got | |
var fillRect = Rect.fromPoints(Offset.zero, size.bottomRight(Offset.zero)); | |
canvas.drawRect( | |
fillRect, |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// In BikeList.build > Column.children | |
Container( | |
decoration: BoxDecoration( | |
boxShadow: const [ | |
BoxShadow(spreadRadius: 0.0, blurRadius: 20.0), | |
], | |
color: Colors.grey.shade800, | |
), | |
child: Row( | |
children: <Widget>[ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In BikeButtonPainter | |
// ... | |
static final rnd = Random(); | |
static Offset randomOffset(Size size) { | |
return Offset( | |
rnd.nextDouble() * size.width, | |
rnd.nextDouble() * size.height | |
); | |
} | |
// ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// In BikeButtonPainter | |
// ... | |
final linePaint = Paint()..color = Colors.white24; | |
// ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@override | |
void paint(Canvas canvas, Size size) { | |
// This [Rect] will fill the whole canvas we got | |
var fillRect = Rect.fromPoints(Offset.zero, size.bottomRight(Offset.zero)); | |
var count = 100; | |
// Background for our texture | |
canvas.drawRect(fillRect, fillPaint); | |
for (var i = 0; i < count; i++) { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in BikeButtonPainter.paint | |
// ... | |
var count = 1000; | |
// ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in BikeButtonPainter.paint | |
// ... | |
var count = 10000; | |
// ... |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// in BikeButtonPainter | |
// ... | |
/// Defines how many lines per unit of area we want | |
final double density; | |
/// Expose to outside, allowing to override default value | |
BikeButtonPainter({ | |
this.density = .1, | |
}); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var start = Offset(1, 1); | |
var displacement = Offset(-2, -2); | |
var end = start + displacement; | |
print(end); // Offset(-1, -1); |