device_card.dart 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:get/get.dart';
  4. import 'package:nomo/app/widgets/click_opacity.dart';
  5. import 'package:nomo/config/theme/theme_extensions/theme_extension.dart';
  6. import '../../../../config/translations/strings_enum.dart';
  7. import '../../../constants/iconfont/iconfont.dart';
  8. import '../../../widgets/infintte_rotate.dart';
  9. import '../controllers/deviceauth_controller.dart';
  10. /// 设备卡片组件
  11. class DeviceCard extends StatelessWidget {
  12. final DeviceInfo device;
  13. final VoidCallback? onRelieve;
  14. final bool showRelieveButton;
  15. const DeviceCard({
  16. super.key,
  17. required this.device,
  18. this.onRelieve,
  19. this.showRelieveButton = true,
  20. });
  21. @override
  22. Widget build(BuildContext context) {
  23. return Container(
  24. padding: EdgeInsets.all(14.w),
  25. decoration: BoxDecoration(
  26. border: Border(
  27. bottom: BorderSide(
  28. color: Get.reactiveTheme.dividerColor, // 颜色
  29. width: 1.w, // 宽度
  30. ),
  31. ),
  32. ),
  33. child: Row(
  34. children: [
  35. // 设备图标
  36. Container(
  37. width: 30.w,
  38. height: 30.w,
  39. decoration: BoxDecoration(
  40. color: _getDeviceIconBgColor(device.type),
  41. borderRadius: BorderRadius.circular(8.r),
  42. ),
  43. child: Icon(
  44. _getDeviceIcon(device.type),
  45. size: 20.w,
  46. color: Colors.white,
  47. ),
  48. ),
  49. 10.horizontalSpace,
  50. // 设备信息
  51. Expanded(
  52. child: Column(
  53. crossAxisAlignment: CrossAxisAlignment.start,
  54. children: [
  55. Text(
  56. device.name,
  57. style: TextStyle(
  58. fontSize: 14.sp,
  59. fontWeight: FontWeight.w500,
  60. color: Get.reactiveTheme.textTheme.bodyLarge!.color,
  61. height: 1.4,
  62. ),
  63. ),
  64. if (device.uid != null)
  65. Text(
  66. device.uid!,
  67. style: TextStyle(
  68. fontSize: 13.sp,
  69. color: Get.reactiveTheme.hintColor,
  70. height: 1.4,
  71. ),
  72. ),
  73. if (device.date != null)
  74. Text(
  75. device.date!,
  76. style: TextStyle(
  77. fontSize: 13.sp,
  78. color: Get.reactiveTheme.hintColor,
  79. height: 1.4,
  80. ),
  81. ),
  82. ],
  83. ),
  84. ),
  85. // Relieve按钮
  86. if (showRelieveButton)
  87. ClickOpacity(
  88. onTap: onRelieve,
  89. child: Container(
  90. padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 4.w),
  91. decoration: BoxDecoration(
  92. color: Get.reactiveTheme.primaryColor,
  93. borderRadius: BorderRadius.circular(12.r),
  94. ),
  95. child: Row(
  96. mainAxisSize: MainAxisSize.min,
  97. children: [
  98. Icon(IconFont.icon11, size: 20.w, color: Colors.white),
  99. SizedBox(width: 4.w),
  100. Text(
  101. Strings.relieve.tr,
  102. style: TextStyle(
  103. fontSize: 12.sp,
  104. height: 1.7,
  105. color: Colors.white,
  106. ),
  107. ),
  108. ],
  109. ),
  110. ),
  111. ),
  112. ],
  113. ),
  114. );
  115. }
  116. /// 获取设备图标
  117. IconData _getDeviceIcon(DeviceTypeEnum type) {
  118. switch (type) {
  119. case DeviceTypeEnum.ios:
  120. return IconFont.icon45;
  121. case DeviceTypeEnum.android:
  122. return IconFont.icon47;
  123. case DeviceTypeEnum.windows:
  124. return Icons.laptop_windows;
  125. case DeviceTypeEnum.mac:
  126. return Icons.laptop_mac;
  127. }
  128. }
  129. /// 获取设备图标背景色
  130. Color _getDeviceIconBgColor(DeviceTypeEnum type) {
  131. switch (type) {
  132. case DeviceTypeEnum.ios:
  133. return Get.reactiveTheme.shadowColor; // iOS蓝色
  134. case DeviceTypeEnum.android:
  135. return Get.reactiveTheme.shadowColor; // Android绿色
  136. case DeviceTypeEnum.windows:
  137. return const Color(0xFF0078D4); // Windows蓝色
  138. case DeviceTypeEnum.mac:
  139. return const Color(0xFF5E5CE6); // Mac紫色
  140. }
  141. }
  142. }
  143. /// 等待激活设备卡片
  144. class AwaitingActivationCard extends StatelessWidget {
  145. final bool showLoadingIcon;
  146. const AwaitingActivationCard({super.key, this.showLoadingIcon = false});
  147. @override
  148. Widget build(BuildContext context) {
  149. return Container(
  150. padding: EdgeInsets.all(14.w),
  151. child: Row(
  152. children: [
  153. // 设备图标 - 暗灰色
  154. Container(
  155. width: 30.w,
  156. height: 30.w,
  157. decoration: BoxDecoration(
  158. color: Get.reactiveTheme.cardColor,
  159. borderRadius: BorderRadius.circular(8.r),
  160. ),
  161. child: Icon(
  162. IconFont.icon31,
  163. size: 20.w,
  164. color: Get.reactiveTheme.hintColor,
  165. ),
  166. ),
  167. 10.horizontalSpace,
  168. // 等待激活文字
  169. Expanded(
  170. child: Text(
  171. showLoadingIcon
  172. ? Strings.configureAuthorizedDevices.tr
  173. : Strings.awaitingActivation.tr,
  174. style: TextStyle(
  175. fontSize: 13.sp,
  176. color: Get.reactiveTheme.hintColor,
  177. height: 1.4,
  178. ),
  179. ),
  180. ),
  181. if (showLoadingIcon) const InfiniteRotateIcon(),
  182. ],
  183. ),
  184. );
  185. }
  186. }