Skip to content

Commit fbc9d4e

Browse files
committed
大更新
1 parent bdf32d0 commit fbc9d4e

4 files changed

Lines changed: 221 additions & 429 deletions

File tree

lib/main.dart

Lines changed: 82 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -84,27 +84,86 @@ void stopTestBackend() {
8484
}
8585
}
8686

87-
class MyApp extends StatelessWidget {
87+
class MyApp extends StatefulWidget {
8888
const MyApp({Key? key}) : super(key: key);
8989

90-
// 简单主题与入口
90+
@override
91+
State<MyApp> createState() => _MyAppState();
92+
}
93+
94+
class _MyAppState extends State<MyApp> {
95+
ThemeMode _themeMode = ThemeMode.light;
96+
97+
void _toggleTheme() {
98+
setState(() {
99+
_themeMode = _themeMode == ThemeMode.light ? ThemeMode.dark : ThemeMode.light;
100+
});
101+
}
102+
103+
ThemeData _buildLightTheme() {
104+
return ThemeData(
105+
colorScheme: ColorScheme.fromSeed(seedColor: Colors.blueGrey),
106+
useMaterial3: true,
107+
scaffoldBackgroundColor: Colors.grey.shade100,
108+
cardTheme: CardThemeData(
109+
color: Colors.white,
110+
elevation: 0,
111+
shape: RoundedRectangleBorder(
112+
borderRadius: BorderRadius.circular(12),
113+
side: BorderSide(color: Colors.grey.shade200, width: 1),
114+
),
115+
),
116+
appBarTheme: const AppBarTheme(
117+
backgroundColor: Colors.white,
118+
foregroundColor: Colors.black,
119+
elevation: 0,
120+
),
121+
bottomNavigationBarTheme: const BottomNavigationBarThemeData(
122+
backgroundColor: Colors.white,
123+
),
124+
);
125+
}
126+
127+
ThemeData _buildDarkTheme() {
128+
return ThemeData(
129+
colorScheme: ColorScheme.fromSeed(
130+
seedColor: Colors.blueGrey,
131+
brightness: Brightness.dark,
132+
),
133+
useMaterial3: true,
134+
scaffoldBackgroundColor: const Color(0xFF121212),
135+
cardTheme: CardThemeData(
136+
color: const Color(0xFF1E1E1E),
137+
elevation: 0,
138+
shape: RoundedRectangleBorder(
139+
borderRadius: BorderRadius.circular(12),
140+
side: BorderSide(color: Colors.grey.shade800, width: 1),
141+
),
142+
),
143+
appBarTheme: const AppBarTheme(
144+
backgroundColor: Color(0xFF1E1E1E),
145+
foregroundColor: Colors.white,
146+
elevation: 0,
147+
),
148+
bottomNavigationBarTheme: const BottomNavigationBarThemeData(
149+
backgroundColor: Color(0xFF1E1E1E),
150+
unselectedItemColor: Colors.white70,
151+
selectedItemColor: Colors.white,
152+
),
153+
);
154+
}
155+
91156
@override
92157
Widget build(BuildContext context) {
93158
return MaterialApp(
94159
title: '机器狗 Flutter 迁移示例',
95-
theme: ThemeData(
96-
colorScheme: ColorScheme.fromSeed(seedColor: Colors.deepPurple),
97-
useMaterial3: true,
98-
scaffoldBackgroundColor: Colors.white,
99-
cardTheme: CardThemeData(
100-
elevation: 0,
101-
shape: RoundedRectangleBorder(
102-
borderRadius: BorderRadius.circular(12),
103-
side: BorderSide(color: Colors.grey.shade200, width: 1),
104-
),
105-
),
160+
theme: _buildLightTheme(),
161+
darkTheme: _buildDarkTheme(),
162+
themeMode: _themeMode,
163+
home: RootPage(
164+
onToggleTheme: _toggleTheme,
165+
themeMode: _themeMode,
106166
),
107-
home: const RootPage(),
108167
builder: (context, child) {
109168
return InAppNotificationOverlay(child: child ?? const SizedBox.shrink());
110169
},
@@ -114,7 +173,10 @@ class MyApp extends StatelessWidget {
114173
}
115174

116175
class RootPage extends StatefulWidget {
117-
const RootPage({Key? key}) : super(key: key);
176+
const RootPage({Key? key, required this.onToggleTheme, required this.themeMode}) : super(key: key);
177+
178+
final VoidCallback onToggleTheme;
179+
final ThemeMode themeMode;
118180

119181
@override
120182
State<RootPage> createState() => _RootPageState();
@@ -424,6 +486,11 @@ class _RootPageState extends State<RootPage> {
424486
appBar: AppBar(
425487
title: Text(userType == 'patient' ? '患者端' : '家属端'),
426488
actions: [
489+
IconButton(
490+
icon: Icon(widget.themeMode == ThemeMode.dark ? Icons.dark_mode : Icons.light_mode),
491+
onPressed: widget.onToggleTheme,
492+
tooltip: widget.themeMode == ThemeMode.dark ? '切换到亮色' : '切换到暗色',
493+
),
427494
IconButton(
428495
icon: const Icon(Icons.notifications),
429496
onPressed: () {

lib/screens/help_screen.dart

Lines changed: 18 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ class _HelpScreenState extends State<HelpScreen> {
204204
Container(
205205
padding: const EdgeInsets.all(12),
206206
decoration: BoxDecoration(
207-
color: Colors.blue.shade50,
207+
color: Colors.white,
208208
borderRadius: BorderRadius.circular(8),
209209
),
210210
child: Column(
@@ -215,12 +215,14 @@ class _HelpScreenState extends State<HelpScreen> {
215215
style: theme.textTheme.bodyLarge?.copyWith(fontWeight: FontWeight.w500),
216216
),
217217
const SizedBox(height: 8),
218-
ElevatedButton.icon(
219-
onPressed: showLocationDialog,
220-
icon: const Icon(Icons.volume_up, size: 18),
221-
label: const Text('播报位置'),
222-
style: ElevatedButton.styleFrom(
223-
backgroundColor: Colors.blue.shade700,
218+
Center(
219+
child: ElevatedButton.icon(
220+
onPressed: showLocationDialog,
221+
icon: const Icon(Icons.volume_up, size: 18),
222+
label: const Text('播报位置'),
223+
style: ElevatedButton.styleFrom(
224+
backgroundColor: Colors.blue.shade700,
225+
),
224226
),
225227
),
226228
],
@@ -258,7 +260,7 @@ class _HelpScreenState extends State<HelpScreen> {
258260
Container(
259261
padding: const EdgeInsets.all(12),
260262
decoration: BoxDecoration(
261-
color: Colors.green.shade50,
263+
color: Colors.white,
262264
borderRadius: BorderRadius.circular(8),
263265
),
264266
child: Column(
@@ -269,12 +271,14 @@ class _HelpScreenState extends State<HelpScreen> {
269271
style: theme.textTheme.bodyLarge?.copyWith(fontWeight: FontWeight.w500),
270272
),
271273
const SizedBox(height: 8),
272-
ElevatedButton.icon(
273-
onPressed: showNavigateDialog,
274-
icon: const Icon(Icons.directions, size: 18),
275-
label: const Text('启动导航'),
276-
style: ElevatedButton.styleFrom(
277-
backgroundColor: Colors.green.shade700,
274+
Center(
275+
child: ElevatedButton.icon(
276+
onPressed: showNavigateDialog,
277+
icon: const Icon(Icons.directions, size: 18),
278+
label: const Text('启动导航'),
279+
style: ElevatedButton.styleFrom(
280+
backgroundColor: Colors.green.shade700,
281+
),
278282
),
279283
),
280284
],

0 commit comments

Comments
 (0)