diff --git a/lib/main.dart b/lib/main.dart index 78e3024..325455d 100644 --- a/lib/main.dart +++ b/lib/main.dart @@ -13,6 +13,7 @@ Future main() async { // 初始化应用信息 await AppInfoUtil.init(); await windowManager.ensureInitialized(); + // 获取pid // 设置窗口属性 await setupWindow(); await AppConfig.init(); diff --git a/lib/screens/front.dart b/lib/screens/front.dart index eefe61c..6f8b589 100644 --- a/lib/screens/front.dart +++ b/lib/screens/front.dart @@ -1,6 +1,7 @@ // 导入必要的包 import 'dart:convert'; - +import 'dart:io'; +import 'dart:math'; import 'package:astral/config/app_config.dart'; import 'package:astral/src/rust/api/simple.dart'; import 'package:astral/src/rust/frb_generated.dart'; @@ -127,6 +128,7 @@ class _HomePageState extends ConsumerState { _buildServerListCard, _buildVersionInfoCard, ]; + // 启动内存监控 } // 添加焦点变化监听方法 @@ -464,10 +466,7 @@ class _HomePageState extends ConsumerState { childCount: _cardBuilders.length, itemBuilder: (context, index) { // 直接从列表中获取构建函数并调用 - return ConstrainedBox( - constraints: const BoxConstraints(minHeight: 100), - child: _cardBuilders[index](colorScheme), - ); + return _cardBuilders[index](colorScheme); }, ), ), diff --git a/lib/screens/settings.dart b/lib/screens/settings.dart index 0de7f9a..b442985 100644 --- a/lib/screens/settings.dart +++ b/lib/screens/settings.dart @@ -176,179 +176,151 @@ class _SettingsPageState extends ConsumerState { } } - // 显示公共服务器列表 // 显示公共服务器列表 void _showPublicServerList(BuildContext context) { - showModalBottomSheet( + showDialog( context: context, - isScrollControlled: true, - shape: const RoundedRectangleBorder( - borderRadius: BorderRadius.vertical(top: Radius.circular(16)), - ), builder: (context) { - return DraggableScrollableSheet( - initialChildSize: 0.7, - minChildSize: 0.5, - maxChildSize: 0.9, - expand: false, - builder: (context, scrollController) { - return Consumer( + return AlertDialog( + title: Row( + children: [ + const Icon(Icons.public), + const SizedBox(width: 8), + const Text('公共服务器列表'), + const Spacer(), + IconButton( + icon: const Icon(Icons.refresh), + onPressed: () { + _fetchEasyTierStatus(); + }, + tooltip: '刷新服务器列表', + ), + ], + ), + content: SizedBox( + width: double.maxFinite, + // 调整高度,使其不会过高 + height: MediaQuery.of(context).size.height * 0.5, + child: Consumer( builder: (context, ref, child) { final publicServers = ref.watch(pServerProvider); - return Column( - children: [ - Padding( - padding: const EdgeInsets.all(16.0), - child: Row( - children: [ - const Icon(Icons.public), - const SizedBox(width: 8), - const Text( - '公共服务器列表', - style: TextStyle( - fontSize: 18, - fontWeight: FontWeight.bold, - ), - ), - const Spacer(), - IconButton( - icon: const Icon(Icons.refresh), - onPressed: () { - // 不关闭底部表单,直接刷新数据 - _fetchEasyTierStatus(); - }, - tooltip: '刷新服务器列表', - ), - IconButton( - icon: const Icon(Icons.close), - onPressed: () => Navigator.pop(context), - tooltip: '关闭', - ), - ], - ), - ), - const Divider(), - Expanded( - child: publicServers.isEmpty - ? Center( - child: Column( - mainAxisAlignment: MainAxisAlignment.center, - children: [ - const Text('暂无公共服务器数据'), - const SizedBox(height: 16), - ElevatedButton( - onPressed: () { - _fetchEasyTierStatus(); - }, - child: const Text('获取公共服务器数据'), - ), - ], - ), - ) - : ListView.builder( - controller: scrollController, - itemCount: publicServers.length, - itemBuilder: (context, index) { - final server = publicServers[index]; - return ListTile( - leading: Icon( - server.isOfficialServer - ? Icons.verified_user - : Icons.person, - color: server.isOfficialServer - ? Colors.green - : Colors.blue, - ), - title: Text(server.name), - subtitle: Column( - crossAxisAlignment: - CrossAxisAlignment.start, - children: [ - Text( - '地址: ${server.address}', - overflow: TextOverflow.ellipsis, - ), - Text( - 'IP: ${server.ip}', - overflow: TextOverflow.ellipsis, - ), - Text( - '提供商: ${server.provider}', - overflow: TextOverflow.ellipsis, - ), - Text( - '版本: ${server.version}', - overflow: TextOverflow.ellipsis, - ), - Row( - mainAxisSize: MainAxisSize.min, - children: [ - Flexible( - child: Chip( - label: Text( - server.isOfficialServer - ? '官方' - : '第三方', - style: const TextStyle( - fontSize: 10), - ), - backgroundColor: - server.isOfficialServer - ? Colors.green - .withOpacity(0.2) - : Colors.blue - .withOpacity(0.2), - visualDensity: - VisualDensity.compact, - labelPadding: - const EdgeInsets.symmetric( - horizontal: 4), - ), - ), - const SizedBox(width: 4), - Flexible( - child: Chip( - label: Text( - server.isTransferable - ? '可转发' - : '不可转发', - style: const TextStyle( - fontSize: 10), - ), - backgroundColor: server - .isTransferable - ? Colors.orange - .withOpacity(0.2) - : Colors.red.withOpacity(0.2), - visualDensity: - VisualDensity.compact, - labelPadding: - const EdgeInsets.symmetric( - horizontal: 4), - ), - ), - ], - ), - ], - ), - isThreeLine: true, - trailing: IconButton( - icon: const Icon(Icons.add_circle), - color: Colors.green, - onPressed: () => - _addPublicServerToList(server), - tooltip: '添加到我的服务器', - ), - ); + return publicServers.isEmpty + ? Center( + child: Column( + mainAxisAlignment: MainAxisAlignment.center, + children: [ + const Text('暂无公共服务器数据'), + const SizedBox(height: 16), + ElevatedButton( + onPressed: () { + _fetchEasyTierStatus(); }, + child: const Text('获取公共服务器数据'), ), - ), - ], - ); + ], + ), + ) + : ListView.builder( + // 修改为ListView.builder,移除separated + itemCount: publicServers.length, + itemBuilder: (context, index) { + final server = publicServers[index]; + return Column( + children: [ + ListTile( + leading: Icon( + server.isOfficialServer + ? Icons.verified_user + : Icons.person, + color: server.isOfficialServer + ? Colors.green + : Colors.blue, + ), + title: Text(server.name), + subtitle: Column( + crossAxisAlignment: CrossAxisAlignment.start, + children: [ + Text( + '地址: ${server.address}', + overflow: TextOverflow.ellipsis, + ), + Text( + 'IP: ${server.ip}', + overflow: TextOverflow.ellipsis, + ), + Row( + mainAxisSize: MainAxisSize.min, + children: [ + Flexible( + child: Chip( + label: Text( + server.isOfficialServer + ? '官方' + : '第三方', + style: + const TextStyle(fontSize: 10), + ), + backgroundColor: server + .isOfficialServer + ? Colors.green.withOpacity(0.2) + : Colors.blue.withOpacity(0.2), + visualDensity: + VisualDensity.compact, + labelPadding: + const EdgeInsets.symmetric( + horizontal: 4), + ), + ), + const SizedBox(width: 4), + Flexible( + child: Chip( + label: Text( + server.isTransferable + ? '可转发' + : '不可转发', + style: + const TextStyle(fontSize: 10), + ), + backgroundColor: server + .isTransferable + ? Colors.orange.withOpacity(0.2) + : Colors.red.withOpacity(0.2), + visualDensity: + VisualDensity.compact, + labelPadding: + const EdgeInsets.symmetric( + horizontal: 4), + ), + ), + ], + ), + ], + ), + isThreeLine: true, + trailing: IconButton( + icon: const Icon(Icons.add_circle), + color: Colors.green, + onPressed: () => + _addPublicServerToList(server), + tooltip: '添加到我的服务器', + ), + ), + if (index < publicServers.length - 1) + const Divider(height: 1), + ], + ); + }, + ); }, - ); - }, + ), + ), + actions: [ + TextButton( + onPressed: () => Navigator.pop(context), + child: const Text('关闭'), + ), + ], ); }, ); @@ -812,12 +784,8 @@ class _SettingsPageState extends ConsumerState { Card( child: Column( children: [ - ListTile( - leading: const Icon(Icons.dns), - title: const Text('已选中的服务器'), - subtitle: Text(serverIP), - ), ExpansionTile( + initiallyExpanded: false, leading: const Icon(Icons.list), title: const Text('服务器列表'), children: [ diff --git a/lib/utils/up.dart b/lib/utils/up.dart index 019465b..ac96630 100644 --- a/lib/utils/up.dart +++ b/lib/utils/up.dart @@ -3,6 +3,7 @@ import 'dart:math'; import 'package:astral/utils/app_info.dart'; import 'package:flutter/material.dart'; import 'package:http/http.dart' as http; +import 'package:fl_chart/fl_chart.dart'; import 'package:package_info_plus/package_info_plus.dart'; import 'package:url_launcher/url_launcher.dart'; diff --git a/lib/widgets/card.dart b/lib/widgets/card.dart index 10da7d5..920204b 100644 --- a/lib/widgets/card.dart +++ b/lib/widgets/card.dart @@ -39,6 +39,7 @@ class _FloatingCardState extends State { child: ConstrainedBox( constraints: BoxConstraints( maxWidth: widget.maxWidth ?? double.infinity, + minHeight: widget.height ?? 74, // 默认最小高度为74 ), child: AnimatedContainer( duration: widget.duration,