Skip to content

Commit a70101b

Browse files
committed
feat(chat): 将首页改为聊天页并添加服务器设置入口
- 修改应用启动页为聊天页 - 添加设置按钮用于跳转至服务器设置页 - 优化服务器设置页的连接状态显示逻辑
1 parent 0f8ebb5 commit a70101b

File tree

3 files changed

+93
-80
lines changed

3 files changed

+93
-80
lines changed

lib/main.dart

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@ import 'core/di/injection_container.dart' as di;
44
import 'presentation/theme/app_theme.dart';
55
import 'presentation/providers/app_provider.dart';
66
import 'presentation/providers/project_provider.dart';
7-
import 'presentation/pages/home_page.dart';
7+
import 'presentation/providers/chat_provider.dart';
8+
import 'presentation/pages/chat_page.dart';
89
import 'core/constants/app_constants.dart';
910

1011
void main() async {
@@ -31,7 +32,11 @@ class MyApp extends StatelessWidget {
3132
theme: AppTheme.darkTheme,
3233
darkTheme: AppTheme.darkTheme,
3334
themeMode: ThemeMode.dark, // Default to dark theme
34-
home: const HomePage(),
35+
// Start directly with AI Chat page
36+
home: ChangeNotifierProvider(
37+
create: (_) => di.sl<ChatProvider>(),
38+
child: const ChatPage(),
39+
),
3540
debugShowCheckedModeBanner: false,
3641
),
3742
);

lib/presentation/pages/chat_page.dart

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:flutter/material.dart';
22
import 'package:provider/provider.dart';
33
import '../providers/chat_provider.dart';
4+
import 'server_settings_page.dart';
45

56
import '../widgets/chat_message_widget.dart';
67
import '../widgets/chat_input_widget.dart';
@@ -133,14 +134,23 @@ class _ChatPageState extends State<ChatPage> {
133134
],
134135
),
135136
actions: [
137+
IconButton(
138+
icon: const Icon(Icons.settings),
139+
tooltip: 'Settings',
140+
onPressed: () {
141+
Navigator.push(
142+
context,
143+
MaterialPageRoute(
144+
builder: (context) => const ServerSettingsPage(),
145+
),
146+
);
147+
},
148+
),
136149
Consumer<ChatProvider>(
137150
builder: (context, chatProvider, child) {
138151
return PopupMenuButton<String>(
139152
onSelected: (value) async {
140153
switch (value) {
141-
case 'back':
142-
Navigator.of(context).pop();
143-
break;
144154
case 'new_session':
145155
await _createNewSession();
146156
break;
@@ -150,17 +160,6 @@ class _ChatPageState extends State<ChatPage> {
150160
}
151161
},
152162
itemBuilder: (context) => [
153-
const PopupMenuItem(
154-
value: 'back',
155-
child: Row(
156-
children: [
157-
Icon(Icons.arrow_back),
158-
SizedBox(width: 8),
159-
Text('Back'),
160-
],
161-
),
162-
),
163-
const PopupMenuDivider(),
164163
const PopupMenuItem(
165164
value: 'new_session',
166165
child: Row(

lib/presentation/pages/server_settings_page.dart

Lines changed: 73 additions & 64 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ class _ServerSettingsPageState extends State<ServerSettingsPage> {
2323
final _basicUsernameController = TextEditingController();
2424
final _basicPasswordController = TextEditingController();
2525
bool _basicEnabled = false;
26+
bool _hasCheckedConnection = false; // Only show status after explicit check/test
2627

2728
@override
2829
void initState() {
@@ -69,17 +70,18 @@ class _ServerSettingsPageState extends State<ServerSettingsPage> {
6970
appBar: AppBar(
7071
title: const Text('Server Settings'),
7172
actions: [
72-
Consumer<AppProvider>(
73-
builder: (context, appProvider, child) {
74-
return IconButton(
75-
icon: Icon(
76-
appProvider.isConnected ? Icons.cloud_done : Icons.cloud_off,
77-
color: appProvider.isConnected ? Colors.green : Colors.red,
78-
),
79-
onPressed: () => _checkConnection(),
80-
);
81-
},
82-
),
73+
if (_hasCheckedConnection)
74+
Consumer<AppProvider>(
75+
builder: (context, appProvider, child) {
76+
return IconButton(
77+
icon: Icon(
78+
appProvider.isConnected ? Icons.cloud_done : Icons.cloud_off,
79+
color: appProvider.isConnected ? Colors.green : Colors.red,
80+
),
81+
onPressed: () => _checkConnection(),
82+
);
83+
},
84+
),
8385
],
8486
),
8587
resizeToAvoidBottomInset: true,
@@ -95,65 +97,66 @@ class _ServerSettingsPageState extends State<ServerSettingsPage> {
9597
child: Column(
9698
crossAxisAlignment: CrossAxisAlignment.stretch,
9799
children: [
98-
// Connection status card
99-
Consumer<AppProvider>(
100-
builder: (context, appProvider, child) {
101-
return Card(
102-
child: Padding(
103-
padding: const EdgeInsets.all(
104-
AppConstants.defaultPadding,
105-
),
106-
child: Column(
107-
crossAxisAlignment: CrossAxisAlignment.start,
108-
children: [
109-
Row(
110-
children: [
111-
Icon(
112-
appProvider.isConnected
113-
? Icons.check_circle
114-
: Icons.error,
115-
color: appProvider.isConnected
116-
? Colors.green
117-
: Colors.red,
118-
),
119-
const SizedBox(width: AppConstants.smallPadding),
100+
// Connection status card (only visible after explicit test/check)
101+
if (_hasCheckedConnection)
102+
Consumer<AppProvider>(
103+
builder: (context, appProvider, child) {
104+
return Card(
105+
child: Padding(
106+
padding: const EdgeInsets.all(
107+
AppConstants.defaultPadding,
108+
),
109+
child: Column(
110+
crossAxisAlignment: CrossAxisAlignment.start,
111+
children: [
112+
Row(
113+
children: [
114+
Icon(
115+
appProvider.isConnected
116+
? Icons.check_circle
117+
: Icons.error,
118+
color: appProvider.isConnected
119+
? Colors.green
120+
: Colors.red,
121+
),
122+
const SizedBox(width: AppConstants.smallPadding),
123+
Text(
124+
appProvider.isConnected
125+
? 'Connected'
126+
: 'Disconnected',
127+
style: Theme.of(context).textTheme.titleMedium,
128+
),
129+
],
130+
),
131+
if (!appProvider.isConnected &&
132+
appProvider.errorMessage.isNotEmpty) ...[
133+
const SizedBox(height: AppConstants.smallPadding),
120134
Text(
121-
appProvider.isConnected
122-
? 'Connected'
123-
: 'Disconnected',
124-
style: Theme.of(context).textTheme.titleMedium,
135+
appProvider.errorMessage,
136+
style: TextStyle(
137+
color: Theme.of(context).colorScheme.error,
138+
fontSize: 12,
139+
),
125140
),
126141
],
127-
),
128-
if (!appProvider.isConnected &&
129-
appProvider.errorMessage.isNotEmpty) ...[
130-
const SizedBox(height: AppConstants.smallPadding),
131-
Text(
132-
appProvider.errorMessage,
133-
style: TextStyle(
134-
color: Theme.of(context).colorScheme.error,
135-
fontSize: 12,
142+
if (appProvider.isConnected &&
143+
appProvider.appInfo != null) ...[
144+
const SizedBox(height: AppConstants.smallPadding),
145+
Text(
146+
'Host: ${appProvider.appInfo!.hostname}',
147+
style: Theme.of(context).textTheme.bodySmall,
136148
),
137-
),
138-
],
139-
if (appProvider.isConnected &&
140-
appProvider.appInfo != null) ...[
141-
const SizedBox(height: AppConstants.smallPadding),
142-
Text(
143-
'Host: ${appProvider.appInfo!.hostname}',
144-
style: Theme.of(context).textTheme.bodySmall,
145-
),
146-
Text(
147-
'Working Directory: ${appProvider.appInfo!.path.cwd}',
148-
style: Theme.of(context).textTheme.bodySmall,
149-
),
149+
Text(
150+
'Working Directory: ${appProvider.appInfo!.path.cwd}',
151+
style: Theme.of(context).textTheme.bodySmall,
152+
),
153+
],
150154
],
151-
],
155+
),
152156
),
153-
),
154-
);
155-
},
156-
),
157+
);
158+
},
159+
),
157160

158161
const SizedBox(height: AppConstants.defaultPadding),
159162

@@ -376,6 +379,9 @@ class _ServerSettingsPageState extends State<ServerSettingsPage> {
376379
// Then test connection
377380
final appProvider = context.read<AppProvider>();
378381
await appProvider.getAppInfo();
382+
setState(() {
383+
_hasCheckedConnection = true;
384+
});
379385

380386
if (mounted) {
381387
if (appProvider.isConnected) {
@@ -400,6 +406,9 @@ class _ServerSettingsPageState extends State<ServerSettingsPage> {
400406
void _checkConnection() async {
401407
final appProvider = context.read<AppProvider>();
402408
await appProvider.checkConnection();
409+
setState(() {
410+
_hasCheckedConnection = true;
411+
});
403412

404413
if (mounted) {
405414
final message = appProvider.isConnected

0 commit comments

Comments
 (0)