cubo.dart 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171
  1. import 'package:flutter/material.dart';
  2. import 'package:google_fonts/google_fonts.dart';
  3. import 'dart:math' as math;
  4. class Cubo extends StatefulWidget {
  5. final double largo;
  6. final double ancho;
  7. final double alto;
  8. final String unidad;
  9. const Cubo({
  10. Key? key,
  11. required this.largo,
  12. required this.ancho,
  13. required this.alto,
  14. required this.unidad,
  15. }) : super(key: key);
  16. @override
  17. State<Cubo> createState() => _CuboState();
  18. }
  19. class _CuboState extends State<Cubo> {
  20. @override
  21. Widget build(BuildContext context) {
  22. return Stack(
  23. children: [
  24. SizedBox(
  25. width: 256.0,
  26. height: 192.0,
  27. child: CustomPaint(
  28. painter: _Cubo(),
  29. ),
  30. ),
  31. Positioned(
  32. child: Transform.rotate(
  33. child: Container(
  34. width: 256.0 / 2,
  35. padding: const EdgeInsets.all(4.0),
  36. child: Text(
  37. "l: ${widget.largo} ${widget.unidad}",
  38. textAlign: TextAlign.center,
  39. maxLines: 1,
  40. overflow: TextOverflow.ellipsis,
  41. style: GoogleFonts.roboto(
  42. color: Colors.white,
  43. fontWeight: FontWeight.bold,
  44. fontSize: 18.0,
  45. ),
  46. ),
  47. ),
  48. angle: _degreeToRadian(14),
  49. ),
  50. left: 0.0,
  51. bottom: 18.0,
  52. ),
  53. Positioned(
  54. child: Transform.rotate(
  55. child: Container(
  56. width: 256.0 / 2,
  57. padding: const EdgeInsets.all(4.0),
  58. child: Text(
  59. "a: ${widget.ancho} ${widget.unidad}",
  60. textAlign: TextAlign.center,
  61. maxLines: 1,
  62. overflow: TextOverflow.ellipsis,
  63. style: GoogleFonts.roboto(
  64. color: Colors.white,
  65. fontWeight: FontWeight.bold,
  66. fontSize: 18.0,
  67. ),
  68. ),
  69. ),
  70. angle: _degreeToRadian(-14),
  71. ),
  72. right: 0.0,
  73. bottom: 18.0,
  74. ),
  75. Positioned(
  76. child: Transform.rotate(
  77. child: Container(
  78. width: 192.0 - 64.0,
  79. padding: const EdgeInsets.all(4.0),
  80. child: Text(
  81. "h: ${widget.alto} ${widget.unidad}",
  82. textAlign: TextAlign.center,
  83. maxLines: 1,
  84. overflow: TextOverflow.ellipsis,
  85. style: GoogleFonts.roboto(
  86. color: Colors.white,
  87. fontWeight: FontWeight.bold,
  88. fontSize: 18.0,
  89. ),
  90. ),
  91. ),
  92. angle: _degreeToRadian(-90),
  93. ),
  94. left: 46.0,
  95. bottom: 64.0,
  96. )
  97. ],
  98. );
  99. }
  100. double _degreeToRadian(double degree){
  101. return degree * math.pi / 180;
  102. }
  103. }
  104. class _Cubo extends CustomPainter{
  105. @override
  106. void paint(Canvas canvas, Size size) {
  107. final borderPaint = Paint();
  108. borderPaint.color = Colors.black;
  109. borderPaint.style = PaintingStyle.stroke;
  110. borderPaint.strokeWidth = 2.5;
  111. final borderPath = Path();
  112. final fillPath = Path();
  113. final x = size.width;
  114. final y = size.height;
  115. final fillPaint = Paint();
  116. fillPaint.shader = const RadialGradient(
  117. colors: [
  118. Color(0xFFE57373),
  119. Color(0xFFB40404),
  120. ],
  121. ).createShader(Rect.fromCircle(
  122. center: Offset(x / 2, 64.0),
  123. radius: 256.0,
  124. ));
  125. fillPaint.style = PaintingStyle.fill;
  126. borderPath.moveTo(x / 2, y);
  127. borderPath.lineTo(0, y - 32.0);
  128. borderPath.lineTo(0, 32.0);
  129. borderPath.lineTo(x / 2, 64.0);
  130. borderPath.lineTo(x / 2, y);
  131. fillPath.moveTo(x / 2, y);
  132. fillPath.lineTo(0, y - 32.0);
  133. fillPath.lineTo(0, 32.0);
  134. fillPath.lineTo(x / 2, 64.0);
  135. fillPath.lineTo(x / 2, y);
  136. borderPath.lineTo(x, y - 32.0);
  137. borderPath.lineTo(x, 32.0);
  138. borderPath.lineTo(x / 2, 64.0);
  139. fillPath.lineTo(x, y - 32.0);
  140. fillPath.lineTo(x, 32.0);
  141. fillPath.lineTo(x / 2, 64.0);
  142. borderPath.moveTo(0, 32.0);
  143. borderPath.lineTo(x / 2, 0);
  144. borderPath.lineTo(x, 32.0);
  145. fillPath.moveTo(0, 32.0);
  146. fillPath.lineTo(x / 2, 0);
  147. fillPath.lineTo(x, 32.0);
  148. fillPath.lineTo(x / 2, 64.0);
  149. canvas.drawPath(fillPath, fillPaint);
  150. canvas.drawPath(borderPath, borderPaint);
  151. }
  152. @override
  153. bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
  154. }