view.dart 1.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import 'index.dart';
  4. import 'widgets/wait_card_reader_view.dart';
  5. class BluetoothCardReaderDialog extends GetView<BluetoothCardReaderController> {
  6. const BluetoothCardReaderDialog({Key? key}) : super(key: key);
  7. // 主视图
  8. Widget _buildView() {
  9. const designWidth = 1280.0; // 设计尺寸宽度:1280
  10. final width = Get.width;
  11. final scale = width / designWidth; // 计算缩放比例
  12. final Widget readerView;
  13. if (controller.isCardReaderConnecting) {
  14. readerView = const BluetoothWaitCardReaderView();
  15. } else {
  16. if (controller.isCardReaderConnected) {
  17. readerView = const BluetoothCardReaderView();
  18. } else {
  19. readerView = const BluetoothNoCardReaderView();
  20. }
  21. }
  22. return Container(
  23. width: Get.width * 0.6 / scale,
  24. height: Get.height * 0.6 / scale,
  25. decoration: BoxDecoration(
  26. color: Colors.white,
  27. borderRadius: BorderRadius.circular(10),
  28. ),
  29. child: Column(
  30. children: [
  31. _buildHead(),
  32. // const Expanded(child: NoCardReaderView()),
  33. Expanded(child: readerView),
  34. ],
  35. ),
  36. );
  37. }
  38. @override
  39. Widget build(BuildContext context) {
  40. return GetBuilder<BluetoothCardReaderController>(
  41. init: BluetoothCardReaderController(),
  42. id: "bluetooth_card_reader",
  43. builder: (_) {
  44. return Dialog(
  45. child: _buildView(),
  46. );
  47. },
  48. );
  49. }
  50. /// 构建弹窗顶部,右侧显示关闭按钮
  51. Widget _buildHead() {
  52. return SizedBox(
  53. height: 50,
  54. child: Row(
  55. mainAxisAlignment: MainAxisAlignment.end,
  56. children: [
  57. IconButton(
  58. onPressed: () => Get.back(),
  59. icon: const Icon(
  60. Icons.close,
  61. size: 30,
  62. ),
  63. ),
  64. ],
  65. ),
  66. );
  67. }
  68. }