node_view.dart 3.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import '../../../component/sys_app_bar.dart';
  4. import '../controllers/node_controller.dart';
  5. class NodeView extends GetView<NodeController> {
  6. const NodeView({Key? key}) : super(key: key);
  7. @override
  8. Widget build(BuildContext context) {
  9. final _refreshIndicatorKey = GlobalKey<RefreshIndicatorState>();
  10. return Container(
  11. decoration: const BoxDecoration(
  12. image: DecorationImage(
  13. image: AssetImage("images/node/nodebg.png"),
  14. fit: BoxFit.fill,
  15. ),
  16. ),
  17. child: Scaffold(
  18. backgroundColor: Colors.transparent,
  19. appBar: const SysAppBar(
  20. title: Text("节点列表"), toolbarHeight: kToolbarHeight + 40,),
  21. body: Container(
  22. width: 376,
  23. height: 600,
  24. decoration: const BoxDecoration(
  25. image: DecorationImage(
  26. image: AssetImage("images/node/nodetablebg.png"),
  27. fit: BoxFit.fill,
  28. ),
  29. ),
  30. child: Padding(
  31. padding: EdgeInsets.all(30.0),
  32. child: Column(
  33. children: [
  34. // 错误消息展示
  35. Obx(() {
  36. if (controller.errorMsg.value.isNotEmpty) {
  37. return Text(controller.errorMsg.value,
  38. style: TextStyle(color: Colors.red));
  39. }
  40. return const SizedBox.shrink(); // 返回一个不占空间的widget
  41. }),
  42. // 加载指示器
  43. Obx(() {
  44. if (controller.isLoading.value) {
  45. return const CircularProgressIndicator();
  46. }
  47. return const SizedBox.shrink();
  48. }),
  49. Expanded(
  50. child: Obx(() {
  51. return RefreshIndicator(
  52. key: _refreshIndicatorKey,
  53. onRefresh: controller.fetchNodes,
  54. child: ListView.builder(
  55. itemCount: controller.nodeModes.length,
  56. itemBuilder: (BuildContext context, int index) {
  57. final node = controller.nodeModes[index];
  58. return InkWell(
  59. onTap: () {
  60. print("Item at index $index was tapped.");
  61. controller.selectedIndex.value = index;
  62. },
  63. child: Obx(() {
  64. final color = controller.selectedIndex.value == index
  65. ? Colors.blueAccent
  66. : null;
  67. return Container(
  68. color: color,
  69. child: ListTile(
  70. title: Text(node.name.toString()),
  71. ),
  72. );
  73. })
  74. );
  75. },
  76. ),
  77. );
  78. }),
  79. ),
  80. ],
  81. ),
  82. ),
  83. )
  84. ),
  85. );
  86. }
  87. }