S22 本機測試發現的 bug 修復(path, 改名要很小心)
This commit is contained in:
@@ -6,14 +6,40 @@ import 'package:uuid/uuid.dart';
|
||||
import 'dart:io';
|
||||
import 'package:http/http.dart' as http;
|
||||
import 'dart:convert'; // 補上這行,json.decode 才能運作
|
||||
// import 'package:device_info_plus/device_info_plus.dart'; // [修正] 補上裝置資訊引用
|
||||
import 'package:shared_preferences/shared_preferences.dart'; // [新增]
|
||||
|
||||
class HouseNoteApiService {
|
||||
final GenericApiService _apiService = GenericApiService();
|
||||
static String? _cachedUserId;
|
||||
|
||||
// 替代 _getDeviceId 的方案:獲取本地生成的唯一 User ID
|
||||
Future<String> _getAppUserId() async {
|
||||
if (_cachedUserId != null) return _cachedUserId!;
|
||||
|
||||
final prefs = await SharedPreferences.getInstance();
|
||||
// 嘗試從本地記憶體讀取舊有的 ID
|
||||
String? localId = prefs.getString('app_user_unique_id');
|
||||
|
||||
if (localId == null) {
|
||||
// 第一次安裝,產生一個新的隨機 ID
|
||||
localId = const Uuid().v4(); //
|
||||
await prefs.setString('app_user_unique_id', localId);
|
||||
}
|
||||
|
||||
_cachedUserId = localId;
|
||||
return localId;
|
||||
}
|
||||
|
||||
// 獲取所有房屋列表
|
||||
Future<List<House>> fetchHouses() async {
|
||||
String userId = await _getAppUserId();
|
||||
// 格式:當前頁^每頁筆數^排序欄位^*^^^過濾欄位^過濾值
|
||||
// 我們在 queryFilter 的最後方加上 device_id 的過濾條件
|
||||
String queryFilter = "1^100^created_at^*^^^device_id^$userId";
|
||||
|
||||
// 依據建立時間降冪排序
|
||||
String queryFilter = "1^100^created_at^*^^^";
|
||||
// String queryFilter = "1^100^created_at^*^^^";
|
||||
return await _apiService.fetchList<House>(
|
||||
tableName: "hhp_houses",
|
||||
pk: "id",
|
||||
@@ -24,8 +50,11 @@ class HouseNoteApiService {
|
||||
|
||||
// 創建新物件 (UUID 在前端生成)
|
||||
Future<List<House>> createHouse(House house) async {
|
||||
String userId = await _getAppUserId();
|
||||
|
||||
final Map<String, dynamic> data = {
|
||||
"id": house.id,
|
||||
"device_id": userId, // 【關鍵】寫入手機識別碼
|
||||
"title": house.title,
|
||||
"address": house.address,
|
||||
"latitude": house.latitude,
|
||||
|
||||
Reference in New Issue
Block a user