feat:增加删除功能

This commit is contained in:
2025-12-03 19:55:34 +08:00
parent 8d23f06f74
commit adae2bc558
3 changed files with 70 additions and 7 deletions

View File

@@ -1,3 +1,13 @@
import java.util.Properties
import java.io.FileInputStream
// 从根路径加载密钥属性
val keystoreProperties = Properties()
val keystorePropertiesFile = rootProject.file("key.properties")
if (keystorePropertiesFile.exists()) {
keystoreProperties.load(FileInputStream(keystorePropertiesFile))
}
plugins {
id("com.android.application")
id("kotlin-android")
@@ -30,11 +40,34 @@ android {
versionName = flutter.versionName
}
signingConfigs {
create("release") {
if (keystorePropertiesFile.exists()) {
keyAlias = keystoreProperties.getProperty("keyAlias")
keyPassword = keystoreProperties.getProperty("keyPassword")
storeFile = file(keystoreProperties.getProperty("storeFile"))
storePassword = keystoreProperties.getProperty("storePassword")
}
}
}
buildTypes {
debug {
signingConfig = if (keystorePropertiesFile.exists()) {
signingConfigs.getByName("release")
} else {
signingConfigs.getByName("debug")
}
}
release {
// TODO: Add your own signing config for the release build.
// Signing with the debug keys for now, so `flutter run --release` works.
signingConfig = signingConfigs.getByName("debug")
signingConfig = if (keystorePropertiesFile.exists()) {
// 使用发布签名
signingConfigs.getByName("release")
} else {
// 使用默认签名
signingConfigs.getByName("debug")
}
}
}
}

View File

@@ -14,7 +14,7 @@ void main() async {
Hive.registerAdapter(HealthRecordAdapter());
final healthsBox = await Hive.openBox<HealthRecord>('healths');
healthsBox.clear();
// healthsBox.clear();
// await Hive.deleteBoxFromDisk('healths');
runApp(

View File

@@ -167,7 +167,7 @@ class _RecordDailyState extends State<RecordDaily> {
} else {
switch (provider.type) {
case RecordType.weight:
provider.updateWeight(70);
provider.updateWeight(AppConfig.initWeight);
break;
case RecordType.sport:
provider.updateSportProject(AppConfig.sportProjectList[0]);
@@ -189,13 +189,13 @@ class _RecordDailyState extends State<RecordDaily> {
padding: EdgeInsets.all(20),
child: Column(
mainAxisSize: MainAxisSize.min,
children: [RecordForm(type: type), _buildDialogButton()],
children: [RecordForm(type: type), _buildDialogButton(type)],
),
),
);
}
Widget _buildDialogButton() {
Widget _buildDialogButton(RecordType type) {
final colors = Theme.of(context).colorScheme;
return Row(
@@ -211,6 +211,17 @@ class _RecordDailyState extends State<RecordDaily> {
),
),
const SizedBox(width: 12),
Expanded(
child: GFButton(
onPressed: () {
Navigator.of(context).pop();
_deleteRecord(type);
},
color: Colors.red,
text: "删除",
),
),
const SizedBox(width: 12),
Expanded(
child: GFButton(
onPressed: () {
@@ -244,6 +255,25 @@ class _RecordDailyState extends State<RecordDaily> {
}
}
void _deleteRecord(RecordType type) async{
final provider = context.read<HealthProvider>();
switch(type) {
case RecordType.weight:
provider.updateWeight(0);
break;
case RecordType.sport:
provider.updateSportDuration(0);
break;
case RecordType.sleep:
provider.updateSleepStartTime('');
provider.updateSleepEndTime('');
break;
}
_saveRecord();
}
void _saveRecord() async {
final provider = context.read<HealthProvider>();