148 lines
3.9 KiB
Dart
148 lines
3.9 KiB
Dart
import 'package:flisp_app/provider/app_provider.dart';
|
|
import 'package:flisp_app/utils/theme_utils.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:provider/provider.dart';
|
|
|
|
class AppDrawer extends StatefulWidget {
|
|
const AppDrawer({super.key});
|
|
|
|
@override
|
|
State<AppDrawer> createState() => AppDrawerState();
|
|
}
|
|
|
|
class AppDrawerState extends State<AppDrawer> {
|
|
DrawerHeader _buildDrawerHeader() {
|
|
return DrawerHeader(
|
|
decoration: BoxDecoration(color: Theme.of(context).colorScheme.primary),
|
|
child: Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
CircleAvatar(
|
|
radius: 30,
|
|
backgroundColor: Colors.white,
|
|
child: Icon(
|
|
Icons.flash_on,
|
|
color: Theme.of(context).colorScheme.primary,
|
|
size: 40,
|
|
),
|
|
),
|
|
SizedBox(height: 10),
|
|
Text(
|
|
'闪灵',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 24,
|
|
fontWeight: FontWeight.bold,
|
|
),
|
|
),
|
|
Text(
|
|
'记录每一刻的灵感',
|
|
style: TextStyle(color: Colors.white70, fontSize: 14),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
Widget _buildDarkModeSection(AppProvider appProvider) {
|
|
return ListTile(
|
|
leading: Icon(
|
|
appProvider.isDarkMode ? Icons.dark_mode : Icons.light_mode,
|
|
color: Theme.of(context).colorScheme.primary,
|
|
),
|
|
title: const Text('暗黑模式'),
|
|
trailing: Switch(
|
|
value: appProvider.isDarkMode,
|
|
onChanged: (value) {
|
|
appProvider.toggleDarkMode(value);
|
|
},
|
|
),
|
|
onTap: () {
|
|
appProvider.toggleDarkMode(!appProvider.isDarkMode);
|
|
},
|
|
);
|
|
}
|
|
|
|
Widget _buildThemeSection(AppProvider appProvider) {
|
|
return Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Padding(
|
|
padding: const EdgeInsets.fromLTRB(16, 16, 16, 8),
|
|
child: Text('主题颜色', style: Theme.of(context).textTheme.titleMedium),
|
|
),
|
|
_buildDarkModeSection(appProvider),
|
|
buildThemeColorList(context, appProvider),
|
|
],
|
|
);
|
|
}
|
|
|
|
// 构建抽屉菜单项
|
|
Widget _buildDrawerItem({
|
|
required IconData icon,
|
|
required String title,
|
|
required VoidCallback onTap,
|
|
}) {
|
|
return ListTile(
|
|
leading: Icon(icon, color: Theme.of(context).colorScheme.primary),
|
|
title: Text(title),
|
|
onTap: onTap,
|
|
);
|
|
}
|
|
|
|
Widget _buildVersionInfo({
|
|
required BuildContext context,
|
|
required String fullVersion,
|
|
}) {
|
|
return Container(
|
|
width: double.infinity,
|
|
padding: EdgeInsets.all(8),
|
|
decoration: BoxDecoration(
|
|
border: Border(top: BorderSide(color: Colors.grey.shade300)),
|
|
),
|
|
child: Text(
|
|
'版本 v$fullVersion',
|
|
textAlign: TextAlign.center,
|
|
style: TextStyle(
|
|
fontSize: 12,
|
|
color: Theme.of(context).colorScheme.primary,
|
|
),
|
|
),
|
|
);
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
final appProvider = context.watch<AppProvider>();
|
|
|
|
return Drawer(
|
|
child: Column(
|
|
children: [
|
|
Expanded(
|
|
child: ListView(
|
|
padding: EdgeInsets.zero,
|
|
children: [
|
|
_buildDrawerHeader(),
|
|
_buildThemeSection(appProvider),
|
|
const Divider(),
|
|
_buildDrawerItem(
|
|
icon: Icons.help,
|
|
title: '帮助与反馈',
|
|
onTap: () {
|
|
Navigator.pop(context);
|
|
// 这里可以导航到帮助页面
|
|
},
|
|
),
|
|
],
|
|
),
|
|
),
|
|
_buildVersionInfo(
|
|
context: context,
|
|
fullVersion: appProvider.fullVersion,
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
}
|