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