home_view.dart 6.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187
  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: controller.GetEnable(),isLoading: controller.isLoading.value,username:controller.GetUserName(),expiryDate: controller.GetExpiredAt(),userTraffic:controller.GetTraffic(),onRefresh: () async {
  28. // 这里插入刷新操作代码
  29. //await Future.delayed(Duration(seconds: 2));
  30. if(controller.isLoading.value != true){
  31. controller.fetchUserinfo();
  32. }
  33. },),
  34. Padding(
  35. padding: const EdgeInsets.fromLTRB(20, 20, 0, 0),
  36. child: Row(
  37. children: controller.imageMap.entries.expand((entry) {
  38. return [
  39. GestureDetector(
  40. onTap: () => controller.onImageTap(entry.key),
  41. child: Image(
  42. image: AssetImage(entry.value),
  43. width: 60,
  44. height: 60,
  45. ),
  46. ),
  47. //Spacer(), // 平均分配间隔
  48. const SizedBox(width: 30),
  49. ];
  50. }).toList()
  51. ..removeLast(), // 删除最后一个Spacer
  52. )
  53. ),
  54. const SizedBox(height: 35,),
  55. const Padding(
  56. padding: EdgeInsets.fromLTRB(30, 0, 30, 0),
  57. child: Row(
  58. children: [
  59. Text("http://127.0.0.1:5336"),
  60. Spacer(),
  61. Text("socks://127.0.0.1:5337"),
  62. ],
  63. ),
  64. ),
  65. ConnectionWidget(
  66. status: ConnectionStatus.disconnected, onStatusChange: (con) {
  67. },),
  68. Padding(
  69. padding: const EdgeInsets.fromLTRB(20, 0, 20, 0),
  70. child: SizedBox(
  71. width: 200,
  72. height: 40,
  73. child: ElevatedButton(
  74. onPressed: () {
  75. controller.RouteNode();
  76. },
  77. style: ElevatedButton.styleFrom(
  78. primary: Colors.white, // 设置背景颜色为白色
  79. onPrimary: Colors.black, // 设置文字颜色为黑色,确保在白色背景上可见
  80. shape: RoundedRectangleBorder(
  81. borderRadius: BorderRadius.circular(20), // 设置圆角
  82. ),
  83. ),
  84. child: Text(controller.GetNode()),
  85. ),
  86. ),
  87. ),
  88. ],
  89. );
  90. })
  91. ),
  92. );
  93. }
  94. }
  95. class UserStatusWidget extends StatefulWidget {
  96. final Future<void> Function() onRefresh; // 新增的回调
  97. final bool isActive;
  98. final bool isLoading; // 新增的变量
  99. final String username;
  100. final String userTraffic;
  101. final String expiryDate;
  102. 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);
  103. @override
  104. _UserStatusWidgetState createState() => _UserStatusWidgetState();
  105. }
  106. class _UserStatusWidgetState extends State<UserStatusWidget> {
  107. @override
  108. Widget build(BuildContext context) {
  109. String imagePath = widget.isActive
  110. ? "images/main/userstatus.png"
  111. : "images/main/userstatusoff.png";
  112. return Align(
  113. alignment: Alignment.topCenter,
  114. child: Padding(
  115. padding: const EdgeInsets.fromLTRB(10.0, 0, 10.0, 10.0),
  116. child:
  117. Row(
  118. children: [
  119. const SizedBox(
  120. width: 80,
  121. height: 20,
  122. ),
  123. Column(
  124. crossAxisAlignment: CrossAxisAlignment.start, // 这将使子组件从左边开始对齐
  125. children: [
  126. Row(
  127. children: [
  128. Text(widget.username),
  129. const SizedBox(width: 10,),
  130. Image(
  131. image: AssetImage(imagePath),
  132. width: 80,
  133. height: 30,
  134. ),
  135. const SizedBox(width: 10,),
  136. IconButton(
  137. icon: widget.isLoading ? const CircularProgressIndicator() : Image.asset("images/main/refresh.png"),
  138. onPressed: () {
  139. // 刷新操作
  140. if(!widget.isLoading){
  141. widget.onRefresh();
  142. }
  143. },
  144. )
  145. ],
  146. ),
  147. Text(
  148. widget.expiryDate,
  149. style: const TextStyle(
  150. fontSize: 8.0, // 设置字体大小为20像素
  151. ),
  152. ),
  153. Text(
  154. widget.userTraffic,
  155. style: const TextStyle(
  156. fontSize: 8.0, // 设置字体大小为20像素
  157. ),
  158. )
  159. ],
  160. ),
  161. ],
  162. ),
  163. // const SizedBox(height: 10,), // 可调整间隔
  164. ),
  165. );
  166. }
  167. }