import 'package:flutter/material.dart'; import 'package:chicken_farm/stores/dict_stroe.dart'; import 'package:chicken_farm/modes/system/dict.dart'; class DictLabel extends StatelessWidget { final String dictType; final String value; const DictLabel({ Key? key, required this.dictType, required this.value, }) : super(key: key); @override Widget build(BuildContext context) { return FutureBuilder( 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.withOpacity(0.1); case 'success': return Colors.green.withOpacity(0.1); case 'danger': return Colors.red.withOpacity(0.1); case 'warning': return Colors.orange.withOpacity(0.1); case 'info': return Colors.cyan.withOpacity(0.1); default: return Colors.grey.withOpacity(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; } } }