feat:增加朋友圈表单功能
This commit is contained in:
@@ -1,6 +1,5 @@
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_common/models/common_model.dart';
|
||||
import 'package:flutter_common/utils/toast_util.dart';
|
||||
import 'package:food_hub_app/apis/moment.dart';
|
||||
import 'package:food_hub_app/apis/recipe.dart';
|
||||
import 'package:food_hub_app/apis/stats.dart';
|
||||
@@ -43,7 +42,7 @@ class FoodProvider with ChangeNotifier {
|
||||
|
||||
List<Moment> momentList = [];
|
||||
int currentPage = 1;
|
||||
final int pageSize = 3;
|
||||
final int pageSize = 5;
|
||||
bool hasMore = true;
|
||||
|
||||
void resetRecordForm() {
|
||||
@@ -63,6 +62,21 @@ class FoodProvider with ChangeNotifier {
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void updateMomentFormItem({String? content}) {
|
||||
if (content != null) momentFormItem.content = content;
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void addMomentFormImage(List<String> imageUrls) {
|
||||
momentFormItem.imageList.addAll(imageUrls);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void removeMomentFormImage(int index) {
|
||||
momentFormItem.imageList.removeAt(index);
|
||||
notifyListeners();
|
||||
}
|
||||
|
||||
void resetMomentForm() {
|
||||
momentFormItem = Moment.getEmpty();
|
||||
notifyListeners();
|
||||
@@ -301,4 +315,48 @@ class FoodProvider with ChangeNotifier {
|
||||
Future<void> refreshMomentList() async {
|
||||
await queryMomentByPage(isRefresh: true);
|
||||
}
|
||||
|
||||
Future<bool> handleMoment() async {
|
||||
if (isLoading) return true;
|
||||
|
||||
try {
|
||||
isLoading = true;
|
||||
error = null;
|
||||
notifyListeners();
|
||||
|
||||
if (isEditing) {
|
||||
await updateMomentApi(momentFormItem.id!, momentFormItem);
|
||||
} else {
|
||||
await addMomentApi(momentFormItem);
|
||||
}
|
||||
return true;
|
||||
} catch (e) {
|
||||
error = '处理数据失败: $e';
|
||||
debugPrint('处理数据失败: $e');
|
||||
return false;
|
||||
} finally {
|
||||
isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
|
||||
Future<bool> deleteMoment() async {
|
||||
if (isLoading) return true;
|
||||
|
||||
try {
|
||||
isLoading = true;
|
||||
error = null;
|
||||
notifyListeners();
|
||||
|
||||
await deleteMomentApi(momentFormItem.id!);
|
||||
return true;
|
||||
} catch (e) {
|
||||
error = '处理数据失败: $e';
|
||||
debugPrint('处理数据失败: $e');
|
||||
return false;
|
||||
} finally {
|
||||
isLoading = false;
|
||||
notifyListeners();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user