device_card.dart 5.5 KB

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