vb_dict_label.dart 2.8 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import 'package:flutter/material.dart';
  2. import 'package:chicken_farm/stores/dict_stroe.dart';
  3. import 'package:chicken_farm/modes/system/dict.dart';
  4. class VberDictLabel extends StatelessWidget {
  5. final String dictType;
  6. final String value;
  7. const VberDictLabel({super.key, required this.dictType, required this.value});
  8. @override
  9. Widget build(BuildContext context) {
  10. return FutureBuilder<DictDataModel?>(
  11. future: DictStore().getDictByTypeAndValue(dictType, value),
  12. builder: (context, snapshot) {
  13. if (snapshot.connectionState == ConnectionState.waiting) {
  14. return const SizedBox(
  15. width: 16,
  16. height: 16,
  17. child: CircularProgressIndicator(strokeWidth: 2),
  18. );
  19. }
  20. if (snapshot.hasData && snapshot.data != null) {
  21. DictDataModel dict = snapshot.data!;
  22. Color backgroundColor = _getColorByListClass(dict.listClass);
  23. Color textColor = _getTextColorByListClass(dict.listClass);
  24. return Container(
  25. padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
  26. decoration: BoxDecoration(
  27. color: backgroundColor,
  28. borderRadius: BorderRadius.circular(4),
  29. ),
  30. child: Text(
  31. dict.dictLabel,
  32. style: TextStyle(
  33. color: textColor,
  34. fontSize: 12,
  35. fontWeight: FontWeight.w400,
  36. ),
  37. ),
  38. );
  39. }
  40. return Container(
  41. padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
  42. decoration: BoxDecoration(
  43. color: Colors.grey[200],
  44. borderRadius: BorderRadius.circular(4),
  45. ),
  46. child: Text(
  47. value,
  48. style: const TextStyle(
  49. color: Colors.grey,
  50. fontSize: 12,
  51. fontWeight: FontWeight.w400,
  52. ),
  53. ),
  54. );
  55. },
  56. );
  57. }
  58. Color _getColorByListClass(String? listClass) {
  59. switch (listClass) {
  60. case 'primary':
  61. return Colors.blue.withValues(alpha: 0.1);
  62. case 'success':
  63. return Colors.green.withValues(alpha: 0.1);
  64. case 'danger':
  65. return Colors.red.withValues(alpha: 0.1);
  66. case 'warning':
  67. return Colors.orange.withValues(alpha: 0.1);
  68. case 'info':
  69. return Colors.cyan.withValues(alpha: 0.1);
  70. default:
  71. return Colors.grey.withValues(alpha: 0.1);
  72. }
  73. }
  74. Color _getTextColorByListClass(String? listClass) {
  75. switch (listClass) {
  76. case 'primary':
  77. return Colors.blue;
  78. case 'success':
  79. return Colors.green;
  80. case 'danger':
  81. return Colors.red;
  82. case 'warning':
  83. return Colors.orange;
  84. case 'info':
  85. return Colors.cyan;
  86. default:
  87. return Colors.grey;
  88. }
  89. }
  90. }