| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798 |
- import 'package:flutter/material.dart';
- import 'package:chicken_farm/stores/dict_stroe.dart';
- import 'package:chicken_farm/modes/system/dict.dart';
- class VberDictLabel extends StatelessWidget {
- final String dictType;
- final String value;
- const VberDictLabel({super.key, required this.dictType, required this.value});
- @override
- Widget build(BuildContext context) {
- return FutureBuilder<DictDataModel?>(
- future: DictStore().getDictByTypeAndValue(dictType, value),
- builder: (context, snapshot) {
- if (snapshot.connectionState == ConnectionState.waiting) {
- return const SizedBox(
- width: 16,
- height: 16,
- child: CircularProgressIndicator(strokeWidth: 2),
- );
- }
- if (snapshot.hasData && snapshot.data != null) {
- DictDataModel dict = snapshot.data!;
- Color backgroundColor = _getColorByListClass(dict.listClass);
- Color textColor = _getTextColorByListClass(dict.listClass);
- return Container(
- padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
- decoration: BoxDecoration(
- color: backgroundColor,
- borderRadius: BorderRadius.circular(4),
- ),
- child: Text(
- dict.dictLabel,
- style: TextStyle(
- color: textColor,
- fontSize: 12,
- fontWeight: FontWeight.w400,
- ),
- ),
- );
- }
- return Container(
- padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 4),
- decoration: BoxDecoration(
- color: Colors.grey[200],
- borderRadius: BorderRadius.circular(4),
- ),
- child: Text(
- value,
- style: const TextStyle(
- color: Colors.grey,
- fontSize: 12,
- fontWeight: FontWeight.w400,
- ),
- ),
- );
- },
- );
- }
- Color _getColorByListClass(String? listClass) {
- switch (listClass) {
- case 'primary':
- return Colors.blue.withValues(alpha: 0.1);
- case 'success':
- return Colors.green.withValues(alpha: 0.1);
- case 'danger':
- return Colors.red.withValues(alpha: 0.1);
- case 'warning':
- return Colors.orange.withValues(alpha: 0.1);
- case 'info':
- return Colors.cyan.withValues(alpha: 0.1);
- default:
- return Colors.grey.withValues(alpha: 0.1);
- }
- }
- Color _getTextColorByListClass(String? listClass) {
- switch (listClass) {
- case 'primary':
- return Colors.blue;
- case 'success':
- return Colors.green;
- case 'danger':
- return Colors.red;
- case 'warning':
- return Colors.orange;
- case 'info':
- return Colors.cyan;
- default:
- return Colors.grey;
- }
- }
- }
|