fix login
This commit is contained in:
parent
f3ef1d1242
commit
942daeffa0
@ -12,8 +12,8 @@ abstract class DeviceRemoteDataSource {
|
||||
/// POST /devices/verify/
|
||||
Future<Map<String, dynamic>> verifyDevice(String sn);
|
||||
|
||||
/// POST /devices/bind/
|
||||
Future<UserDevice> bindDevice(String sn, {int? spiritId});
|
||||
/// POST /devices/bind/ — 返回绑定 ID (int)
|
||||
Future<int> bindDevice(String sn, {int? spiritId});
|
||||
|
||||
/// GET /devices/my_devices/
|
||||
Future<List<UserDevice>> getMyDevices();
|
||||
@ -61,11 +61,11 @@ class DeviceRemoteDataSourceImpl implements DeviceRemoteDataSource {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<UserDevice> bindDevice(String sn, {int? spiritId}) async {
|
||||
Future<int> bindDevice(String sn, {int? spiritId}) async {
|
||||
final body = <String, dynamic>{'sn': sn};
|
||||
if (spiritId != null) body['spirit_id'] = spiritId;
|
||||
final data = await _apiClient.post('/devices/bind/', data: body);
|
||||
return UserDevice.fromJson(data as Map<String, dynamic>);
|
||||
return data as int;
|
||||
}
|
||||
|
||||
@override
|
||||
|
||||
@ -45,7 +45,7 @@ class DeviceRepositoryImpl implements DeviceRepository {
|
||||
}
|
||||
|
||||
@override
|
||||
Future<Either<Failure, UserDevice>> bindDevice(
|
||||
Future<Either<Failure, int>> bindDevice(
|
||||
String sn, {
|
||||
int? spiritId,
|
||||
}) async {
|
||||
|
||||
@ -30,9 +30,9 @@ Map<String, dynamic> _$DeviceTypeToJson(_DeviceType instance) =>
|
||||
_DeviceInfo _$DeviceInfoFromJson(Map<String, dynamic> json) => _DeviceInfo(
|
||||
id: (json['id'] as num).toInt(),
|
||||
sn: json['sn'] as String,
|
||||
deviceType: json['device_type'] == null
|
||||
? null
|
||||
: DeviceType.fromJson(json['device_type'] as Map<String, dynamic>),
|
||||
deviceType: (json['device_type'] is Map<String, dynamic>)
|
||||
? DeviceType.fromJson(json['device_type'] as Map<String, dynamic>)
|
||||
: null,
|
||||
deviceTypeInfo: json['device_type_info'] == null
|
||||
? null
|
||||
: DeviceType.fromJson(json['device_type_info'] as Map<String, dynamic>),
|
||||
|
||||
@ -6,7 +6,7 @@ import '../entities/device_detail.dart';
|
||||
abstract class DeviceRepository {
|
||||
Future<Either<Failure, Map<String, dynamic>>> queryByMac(String mac);
|
||||
Future<Either<Failure, Map<String, dynamic>>> verifyDevice(String sn);
|
||||
Future<Either<Failure, UserDevice>> bindDevice(String sn, {int? spiritId});
|
||||
Future<Either<Failure, int>> bindDevice(String sn, {int? spiritId});
|
||||
Future<Either<Failure, List<UserDevice>>> getMyDevices();
|
||||
Future<Either<Failure, DeviceDetail>> getDeviceDetail(int userDeviceId);
|
||||
Future<Either<Failure, void>> unbindDevice(int userDeviceId);
|
||||
|
||||
@ -23,9 +23,8 @@ class DeviceController extends _$DeviceController {
|
||||
final result = await repository.bindDevice(sn, spiritId: spiritId);
|
||||
return result.fold(
|
||||
(failure) => false,
|
||||
(userDevice) {
|
||||
final current = state.value ?? [];
|
||||
state = AsyncData([...current, userDevice]);
|
||||
(bindingId) {
|
||||
ref.invalidateSelf();
|
||||
return true;
|
||||
},
|
||||
);
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user