home_view.dart 5.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163
  1. import 'dart:io';
  2. import 'package:flutter/foundation.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:get/get.dart';
  5. import 'package:naiyouwl/app/component/sys_app_bar.dart';
  6. import 'package:window_manager/window_manager.dart';
  7. import '../../../component/connection_status.dart';
  8. import '../../../component/connection_widget.dart';
  9. import '../controllers/home_controller.dart';
  10. class HomeView extends GetView<HomeController> {
  11. const HomeView({Key? key}) : super(key: key);
  12. @override
  13. Widget build(BuildContext context) {
  14. return Container(
  15. decoration: const BoxDecoration(
  16. image: DecorationImage(
  17. image: AssetImage("images/main/main.png"),
  18. fit: BoxFit.fill,
  19. ),
  20. ),
  21. child: Scaffold(
  22. backgroundColor: Colors.transparent,
  23. appBar: const SysAppBar(title: Text("首页"),),
  24. body: Obx(() {
  25. return Column(
  26. children: [
  27. UserStatusWidget(isActive: true,isLoading: controller.isLoading.value,username:"",expiryDate: "",userTraffic:"",onRefresh: () async {
  28. // 这里插入刷新操作代码
  29. //await Future.delayed(Duration(seconds: 2));
  30. },),
  31. Padding(
  32. padding: const EdgeInsets.fromLTRB(20, 20, 0, 0),
  33. child: Row(
  34. children: controller.imageMap.entries.expand((entry) {
  35. return [
  36. GestureDetector(
  37. onTap: () => controller.onImageTap(entry.key),
  38. child: Image(
  39. image: AssetImage(entry.value),
  40. width: 60,
  41. height: 60,
  42. ),
  43. ),
  44. //Spacer(), // 平均分配间隔
  45. const SizedBox(width: 30),
  46. ];
  47. }).toList()
  48. ..removeLast(), // 删除最后一个Spacer
  49. )
  50. ),
  51. const SizedBox(height: 35,),
  52. const Padding(
  53. padding: EdgeInsets.fromLTRB(30, 0, 30, 0),
  54. child: Row(
  55. children: [
  56. Text("http://127.0.0.1:5336"),
  57. Spacer(),
  58. Text("socks://127.0.0.1:5337"),
  59. ],
  60. ),
  61. ),
  62. ConnectionWidget(
  63. status: ConnectionStatus.disconnected, onStatusChange: (con) {
  64. },)
  65. ],
  66. );
  67. })
  68. ),
  69. );
  70. }
  71. }
  72. class UserStatusWidget extends StatefulWidget {
  73. final Future<void> Function() onRefresh; // 新增的回调
  74. final bool isActive;
  75. final bool isLoading; // 新增的变量
  76. final String username;
  77. final String userTraffic;
  78. final String expiryDate;
  79. const UserStatusWidget({Key? key, required this.isActive, required this.isLoading,required this.username, required this.userTraffic, required this.expiryDate, required this.onRefresh}) : super(key: key);
  80. @override
  81. _UserStatusWidgetState createState() => _UserStatusWidgetState();
  82. }
  83. class _UserStatusWidgetState extends State<UserStatusWidget> {
  84. @override
  85. Widget build(BuildContext context) {
  86. String imagePath = widget.isActive
  87. ? "images/main/userstatus.png"
  88. : "images/main/userstatusoff.png";
  89. return Align(
  90. alignment: Alignment.topCenter,
  91. child: Padding(
  92. padding: const EdgeInsets.fromLTRB(10.0, 0, 10.0, 10.0),
  93. child:
  94. Row(
  95. children: [
  96. const SizedBox(
  97. width: 80,
  98. height: 20,
  99. ),
  100. Column(
  101. crossAxisAlignment: CrossAxisAlignment.start, // 这将使子组件从左边开始对齐
  102. children: [
  103. Row(
  104. children: [
  105. Text(widget.username),
  106. const SizedBox(width: 10,),
  107. Image(
  108. image: AssetImage(imagePath),
  109. width: 100,
  110. height: 30,
  111. ),
  112. const SizedBox(width: 10,),
  113. IconButton(
  114. icon: widget.isLoading ? const CircularProgressIndicator() : Image.asset("images/main/refresh.png"),
  115. onPressed: () {
  116. // 刷新操作
  117. if(!widget.isLoading){
  118. widget.onRefresh();
  119. }
  120. },
  121. )
  122. ],
  123. ),
  124. Text(
  125. widget.expiryDate,
  126. style: const TextStyle(
  127. fontSize: 8.0, // 设置字体大小为20像素
  128. ),
  129. ),
  130. Text(
  131. widget.userTraffic,
  132. style: const TextStyle(
  133. fontSize: 8.0, // 设置字体大小为20像素
  134. ),
  135. )
  136. ],
  137. ),
  138. ],
  139. ),
  140. // const SizedBox(height: 10,), // 可调整间隔
  141. ),
  142. );
  143. }
  144. }