carrito_screen.dart 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import 'package:flutter/material.dart';
  2. const List<Map<String, dynamic>> items = [
  3. {
  4. 'nombre': 'Hamburguesa de res',
  5. 'descripcion': 'Hamburguesa de res con queso cheddar',
  6. 'precio': '\$ 120.00',
  7. 'imageUrl':
  8. 'https://cdn.pixabay.com/photo/2016/03/05/19/02/hamburger-1238246_960_720.jpg',
  9. },
  10. {
  11. 'nombre': 'Hamburguesa de pollo',
  12. 'descripcion': 'Hamburguesa de pollo con queso cheddar',
  13. 'precio': '\$ 100.00',
  14. 'imageUrl':
  15. 'https://cdn.pixabay.com/photo/2016/03/05/19/02/hamburger-1238246_960_720.jpg',
  16. },
  17. ];
  18. class CarritoScreen extends StatefulWidget {
  19. const CarritoScreen({super.key});
  20. @override
  21. State<CarritoScreen> createState() => _CarritoScreenState();
  22. }
  23. class _CarritoScreenState extends State<CarritoScreen> {
  24. int value = 1;
  25. void increment(){
  26. setState(() {
  27. value++;
  28. });
  29. }
  30. void decrement(){
  31. setState(() {
  32. if(value > 1){
  33. value--;
  34. }
  35. });
  36. }
  37. @override
  38. Widget build(BuildContext context) {
  39. return Scaffold(
  40. backgroundColor: Colors.white,
  41. appBar: AppBar(
  42. title: const Row(
  43. mainAxisAlignment: MainAxisAlignment.spaceBetween,
  44. children: [
  45. Text('Atrás'),
  46. Column(
  47. crossAxisAlignment: CrossAxisAlignment.start,
  48. children: [
  49. Text(
  50. 'Su carrito',
  51. style: TextStyle(
  52. fontStyle: FontStyle.italic,
  53. fontSize: 16,
  54. color: Colors.black54),
  55. ),
  56. Text(
  57. 'Total: \$0.00',
  58. style: TextStyle(
  59. fontWeight: FontWeight.bold,
  60. fontSize: 20,
  61. ),
  62. ),
  63. ],
  64. ),
  65. ],
  66. ),
  67. ),
  68. body: ListView.builder(
  69. itemBuilder: (context, index) {
  70. final item = items[index];
  71. return _buildInfoItem(item['nombre'], item['descripcion'],
  72. item['precio'], item['imageUrl']);
  73. },
  74. itemCount: items.length),
  75. );
  76. }
  77. }
  78. _buildInfoItem(String title, String subtitle, String precio, String imageUrl) {
  79. return Container(
  80. height: 90,
  81. width: double.infinity,
  82. color: Colors.white,
  83. padding: EdgeInsets.symmetric(horizontal: 16, vertical: 8),
  84. child: Row(
  85. children: [
  86. // Leading image
  87. Container(
  88. width: 80,
  89. height: 80,
  90. child: ClipRRect(
  91. borderRadius: BorderRadius.circular(4),
  92. child: Image.network(
  93. imageUrl,
  94. fit: BoxFit.cover,
  95. ),
  96. ),
  97. ),
  98. SizedBox(width: 16),
  99. // Title and subtitle
  100. Expanded(
  101. child: Column(
  102. crossAxisAlignment: CrossAxisAlignment.start,
  103. mainAxisAlignment: MainAxisAlignment.center,
  104. children: [
  105. Text(
  106. title,
  107. style: TextStyle(
  108. color: Colors.black,
  109. fontSize: 16,
  110. fontWeight: FontWeight.bold,
  111. ),
  112. ),
  113. SizedBox(height: 4),
  114. Text(
  115. 'MXN $precio',
  116. style: TextStyle(
  117. color: Colors.black,
  118. fontSize: 18,
  119. fontWeight: FontWeight.bold,
  120. ),
  121. ),
  122. ],
  123. ),
  124. ),
  125. // Quantity controls
  126. Row(
  127. children: [
  128. Container(
  129. width: 40,
  130. height: 40,
  131. alignment: Alignment.center,
  132. child: Icon(
  133. Icons.remove,
  134. color: Colors.black,
  135. size: 24,
  136. ),
  137. ),
  138. Container(
  139. width: 40,
  140. alignment: Alignment.center,
  141. child: Text(
  142. subtitle,
  143. style: TextStyle(
  144. color: Colors.black,
  145. fontSize: 20,
  146. fontWeight: FontWeight.bold,
  147. ),
  148. ),
  149. ),
  150. Container(
  151. width: 40,
  152. height: 40,
  153. alignment: Alignment.center,
  154. child: Icon(
  155. Icons.add,
  156. color: Colors.red,
  157. size: 24,
  158. ),
  159. ),
  160. ],
  161. ),
  162. ],
  163. ),
  164. );
  165. }