feat:增加主题色存储本地的功能
This commit is contained in:
@@ -1,4 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:toggle_switch/toggle_switch.dart';
|
||||
|
||||
BoxDecoration buildBoxDecoration() {
|
||||
return BoxDecoration(
|
||||
@@ -8,6 +9,7 @@ BoxDecoration buildBoxDecoration() {
|
||||
);
|
||||
}
|
||||
|
||||
// 卡片
|
||||
class BuildCard extends StatelessWidget {
|
||||
final Widget? child;
|
||||
|
||||
@@ -29,6 +31,7 @@ class BuildCard extends StatelessWidget {
|
||||
}
|
||||
}
|
||||
|
||||
// 底部弹出
|
||||
void buildModalBottom({
|
||||
required BuildContext context,
|
||||
required String title,
|
||||
@@ -113,3 +116,86 @@ Widget buildModalBottomBody(BuildContext context, String title, Widget body) {
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
// 滑动删除
|
||||
Widget buildDismissible({
|
||||
required BuildContext context,
|
||||
required Object id,
|
||||
required Widget child,
|
||||
required VoidCallback onDelete,
|
||||
}) {
|
||||
return Dismissible(
|
||||
key: ValueKey(id),
|
||||
direction: DismissDirection.endToStart,
|
||||
background: _buildDismissBackground(),
|
||||
confirmDismiss: (direction) async {
|
||||
// 这里实现二次确认
|
||||
return await _showDeleteConfirmationDialog(context);
|
||||
},
|
||||
onDismissed: (direction) {
|
||||
onDelete();
|
||||
},
|
||||
child: child,
|
||||
);
|
||||
}
|
||||
|
||||
// 确认对话框
|
||||
Future<bool?> _showDeleteConfirmationDialog(BuildContext context) async {
|
||||
return showDialog<bool>(
|
||||
context: context,
|
||||
builder: (BuildContext context) {
|
||||
return AlertDialog(
|
||||
title: const Text('确认删除'),
|
||||
backgroundColor: Colors.white,
|
||||
content: const Text('确定要删除这个项目吗?'),
|
||||
actions: [
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(false),
|
||||
child: const Text('取消'),
|
||||
),
|
||||
TextButton(
|
||||
onPressed: () => Navigator.of(context).pop(true),
|
||||
child: const Text('删除', style: TextStyle(color: Colors.red)),
|
||||
),
|
||||
],
|
||||
);
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Widget _buildDismissBackground() {
|
||||
return Container(
|
||||
color: Colors.red,
|
||||
alignment: Alignment.centerRight,
|
||||
padding: const EdgeInsets.only(right: 20),
|
||||
child: const Icon(Icons.delete, color: Colors.white, size: 24),
|
||||
);
|
||||
}
|
||||
|
||||
// toggle切换
|
||||
Widget buildToggleSwitch<T extends Enum>({
|
||||
required BuildContext context,
|
||||
required T currentTab,
|
||||
required List<T> tabValues,
|
||||
required List<String> labels,
|
||||
required ValueChanged<T> onTabChanged,
|
||||
}) {
|
||||
return ToggleSwitch(
|
||||
minWidth: 90.0,
|
||||
minHeight: 40.0,
|
||||
initialLabelIndex: tabValues.indexOf(currentTab),
|
||||
totalSwitches: tabValues.length,
|
||||
labels: labels,
|
||||
activeBgColor: [Theme.of(context).colorScheme.primary],
|
||||
activeFgColor: Colors.white,
|
||||
inactiveBgColor: Colors.grey.shade200,
|
||||
inactiveFgColor: Colors.grey.shade700,
|
||||
cornerRadius: 12.0,
|
||||
customTextStyles: [TextStyle(fontSize: 12, fontWeight: FontWeight.w500)],
|
||||
onToggle: (index) {
|
||||
if (index != null && index < tabValues.length) {
|
||||
onTabChanged(tabValues[index]);
|
||||
}
|
||||
},
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user