| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102 |
- 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<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.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;
- }
- }
- }
|