feat:增加主题色存储本地的功能
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
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';
|
||||
|
||||
@@ -57,88 +58,6 @@ class AppDrawer extends StatelessWidget {
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildThemeColorList(BuildContext context, AppProvider appProvider) {
|
||||
return Padding(
|
||||
padding: const EdgeInsets.symmetric(horizontal: 16, vertical: 4),
|
||||
child: GridView.builder(
|
||||
shrinkWrap: true,
|
||||
physics: const NeverScrollableScrollPhysics(),
|
||||
gridDelegate: const SliverGridDelegateWithFixedCrossAxisCount(
|
||||
crossAxisCount: 4,
|
||||
crossAxisSpacing: 8,
|
||||
mainAxisSpacing: 8,
|
||||
childAspectRatio: 1.2,
|
||||
),
|
||||
itemCount: appProvider.availableThemes.length,
|
||||
itemBuilder: (context, index) {
|
||||
final themeColor = appProvider.availableThemes[index];
|
||||
final isSelected = appProvider.currentTheme == themeColor;
|
||||
|
||||
return _buildThemeColorItem(
|
||||
themeColor: themeColor,
|
||||
isSelected: isSelected,
|
||||
onTap: () => appProvider.changeTheme(themeColor),
|
||||
);
|
||||
},
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildThemeColorItem({
|
||||
required ThemeColor themeColor,
|
||||
required bool isSelected,
|
||||
required VoidCallback onTap,
|
||||
}) {
|
||||
return GestureDetector(
|
||||
onTap: onTap,
|
||||
child: Container(
|
||||
decoration: BoxDecoration(
|
||||
color:
|
||||
isSelected
|
||||
? themeColor.primaryColor.withAlpha(50)
|
||||
: Colors.transparent,
|
||||
borderRadius: BorderRadius.circular(8),
|
||||
border: Border.all(
|
||||
color: isSelected ? themeColor.primaryColor : Colors.grey.shade300,
|
||||
width: isSelected ? 2 : 1,
|
||||
),
|
||||
),
|
||||
child: Column(
|
||||
mainAxisAlignment: MainAxisAlignment.center,
|
||||
children: [
|
||||
// 颜色圆点
|
||||
Container(
|
||||
width: 20,
|
||||
height: 20,
|
||||
decoration: BoxDecoration(
|
||||
color: themeColor.primaryColor,
|
||||
shape: BoxShape.circle,
|
||||
border: Border.all(color: Colors.white, width: 2),
|
||||
boxShadow: [
|
||||
BoxShadow(
|
||||
color: Colors.black.withAlpha(10),
|
||||
blurRadius: 2,
|
||||
offset: const Offset(0, 1),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
const SizedBox(height: 4),
|
||||
Text(
|
||||
themeColor.name,
|
||||
style: TextStyle(
|
||||
fontSize: 10,
|
||||
fontWeight: isSelected ? FontWeight.bold : FontWeight.normal,
|
||||
color:
|
||||
isSelected ? themeColor.primaryColor : Colors.grey.shade600,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildThemeSection(BuildContext context, AppProvider appProvider) {
|
||||
return Column(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
@@ -148,7 +67,7 @@ class AppDrawer extends StatelessWidget {
|
||||
child: Text('主题颜色', style: Theme.of(context).textTheme.titleMedium),
|
||||
),
|
||||
_buildDarkModeSection(context, appProvider),
|
||||
_buildThemeColorList(context, appProvider),
|
||||
buildThemeColorList(context, appProvider),
|
||||
],
|
||||
);
|
||||
}
|
||||
@@ -178,49 +97,6 @@ class AppDrawer extends StatelessWidget {
|
||||
// 抽屉头部
|
||||
buildDrawerHeader(context),
|
||||
|
||||
// 菜单项
|
||||
_buildDrawerItem(
|
||||
context: context,
|
||||
icon: Icons.flash_on,
|
||||
title: '闪灵',
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
appProvider.changeTab(0);
|
||||
},
|
||||
),
|
||||
_buildDrawerItem(
|
||||
context: context,
|
||||
icon: Icons.checklist,
|
||||
title: '待办事项',
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
appProvider.changeTab(1);
|
||||
},
|
||||
),
|
||||
|
||||
const Divider(),
|
||||
|
||||
_buildDrawerItem(
|
||||
context: context,
|
||||
icon: Icons.analytics,
|
||||
title: '统计',
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
// 这里可以导航到统计页面
|
||||
},
|
||||
),
|
||||
_buildDrawerItem(
|
||||
context: context,
|
||||
icon: Icons.archive,
|
||||
title: '归档',
|
||||
onTap: () {
|
||||
Navigator.pop(context);
|
||||
// 这里可以导航到归档页面
|
||||
},
|
||||
),
|
||||
|
||||
const Divider(),
|
||||
|
||||
_buildThemeSection(context, appProvider),
|
||||
|
||||
const Divider(),
|
||||
|
||||
Reference in New Issue
Block a user