color_and_size.dart 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091
  1. import 'package:flutter/material.dart';
  2. import 'package:fooddeliveryapp/constants.dart';
  3. import 'package:fooddeliveryapp/model/product.dart';
  4. class ColorAndSize extends StatelessWidget {
  5. const ColorAndSize({
  6. Key key,
  7. @required this.product,
  8. }) : super(key: key);
  9. final Product product;
  10. @override
  11. Widget build(BuildContext context) {
  12. return Row(
  13. children: [
  14. Expanded(
  15. child: Column(
  16. crossAxisAlignment: CrossAxisAlignment.start,
  17. children: [
  18. Text("Color"),
  19. Row(
  20. children: [
  21. ColorDot(
  22. color: Color(0xFF356C95),
  23. isSelected: true,
  24. ),
  25. ColorDot(color: Color(0xFFF8C078)),
  26. ColorDot(color: Color(0xFFA29B9B)),
  27. ],
  28. ),
  29. ],
  30. ),
  31. ),
  32. Expanded(
  33. child: RichText(
  34. text: TextSpan(
  35. style: TextStyle(color: kTextColor),
  36. children: [
  37. TextSpan(text: "Size\n"),
  38. TextSpan(
  39. text: "${product.size} cm",
  40. style: Theme.of(context)
  41. .textTheme
  42. .headline5
  43. .copyWith(fontWeight: FontWeight.bold),
  44. )
  45. ],
  46. ),
  47. ),
  48. ),
  49. ],
  50. );
  51. }
  52. }
  53. class ColorDot extends StatelessWidget {
  54. final Color color;
  55. final bool isSelected;
  56. const ColorDot({
  57. Key key,
  58. this.color,
  59. // by default isSelected is false
  60. this.isSelected = false,
  61. }) : super(key: key);
  62. @override
  63. Widget build(BuildContext context) {
  64. return Container(
  65. margin: EdgeInsets.only(
  66. top: kDefaultPaddin / 4,
  67. right: kDefaultPaddin / 2,
  68. ),
  69. padding: EdgeInsets.all(2.5),
  70. height: 24,
  71. width: 24,
  72. decoration: BoxDecoration(
  73. shape: BoxShape.circle,
  74. border: Border.all(
  75. color: isSelected ? color : Colors.transparent,
  76. ),
  77. ),
  78. child: DecoratedBox(
  79. decoration: BoxDecoration(
  80. color: color,
  81. shape: BoxShape.circle,
  82. ),
  83. ),
  84. );
  85. }
  86. }