refactor(shared): move device providers and data layer from legacy_shared to sf_shared

Device providers (legacyDevicesProvider, selectedDeviceProvider), repository,
datasource, and GetDevicesResponseModel now live in sf_shared. Also moved
dio_error_mapper (safeCall, mapDioError, formatErrorMessage) to sf_infrastructure.
Consumers import directly from sf_shared instead of re-exporting through legacy_shared.
This commit is contained in:
2026-04-17 08:48:38 +02:00
parent 05ffe572c8
commit e7a4653c01
44 changed files with 94 additions and 25 deletions

View File

@@ -1,2 +1,3 @@
export 'src/env/env_contract.dart';
export 'src/network/dio_error_mapper.dart';
export 'configure_dependencies.dart';

View File

@@ -0,0 +1,54 @@
import 'dart:convert';
import 'package:dio/dio.dart';
Future<T> safeCall<T>(Future<T> Function() call, String fallbackMsg) async {
try {
return await call();
} on DioException catch (error) {
throw mapDioError(error, defaultMessage: fallbackMsg);
}
}
Exception mapDioError(DioException error, {required String defaultMessage}) {
final apiMsg = _extractApiMessage(error.response?.data);
final msg = apiMsg ?? error.message ?? defaultMessage;
return Exception(msg);
}
String? _extractApiMessage(Object? data) {
if (data == null) return null;
if (data is Map) {
final errorObj = data['error'];
if (errorObj is Map && errorObj['message'] is String) {
return (errorObj['message'] as String).trim();
}
if (data['message'] is String) {
return (data['message'] as String).trim();
}
return null;
}
if (data is String) {
final raw = data.trim();
if (raw.isEmpty) return null;
try {
final decoded = jsonDecode(raw);
return _extractApiMessage(decoded);
} catch (_) {
return raw;
}
}
return null;
}
String formatErrorMessage(Object error) {
final raw = error.toString();
if (raw.startsWith('Exception: ')) {
return raw.substring('Exception: '.length);
}
return raw;
}

View File

@@ -58,3 +58,12 @@ export 'src/providers/wallet_transactions_provider.dart';
export 'src/domain/value_objects/phone_number.dart';
export 'src/services/device_contact_picker.dart';
export 'src/providers/device_contact_picker_provider.dart';
export 'src/data/models/get_devices_response_model.dart';
export 'src/data/datasource/devices_remote_datasource.dart';
export 'src/data/datasource/devices_remote_datasource_impl.dart';
export 'src/data/repositories/devices_repository_impl.dart';
export 'src/domain/repositories/devices_repository.dart';
export 'src/providers/devices_remote_datasource_repository_provider.dart';
export 'src/providers/devices_repository_provider.dart';
export 'src/providers/legacy_devices_provider.dart';
export 'src/providers/selected_device_provider.dart';

View File

@@ -0,0 +1,5 @@
import 'package:sf_shared/sf_shared.dart';
abstract class DevicesRemoteDatasource {
Future<List<DeviceEntity>> getDevices();
}

View File

@@ -0,0 +1,24 @@
import 'package:sf_infrastructure/sf_infrastructure.dart';
import 'package:sf_shared/sf_shared.dart';
class DevicesRemoteDatasourceImpl implements DevicesRemoteDatasource {
DevicesRemoteDatasourceImpl(this._repository);
final SaveFamilyRepository _repository;
@override
Future<List<DeviceEntity>> getDevices() async {
final response = await safeCall(
() => _repository.get<Map<String, dynamic>>('/devices'),
'Error getting devices',
);
final data = response.data;
if (data == null || data.isEmpty) {
throw Exception('Empty response from /devices');
}
final model = GetDevicesResponseModel.fromJson(data);
return model.toEntity();
}
}

View File

@@ -0,0 +1,95 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:sf_shared/sf_shared.dart';
part 'get_devices_response_model.freezed.dart';
part 'get_devices_response_model.g.dart';
@freezed
abstract class GetDevicesResponseModel with _$GetDevicesResponseModel {
const factory GetDevicesResponseModel({
required List<GetDevicesItemResponseModel> items,
}) = _GetDevicesResponseModel;
factory GetDevicesResponseModel.fromJson(Map<String, dynamic> json) =>
_$GetDevicesResponseModelFromJson(json);
}
@freezed
abstract class GetDevicesItemResponseModel with _$GetDevicesItemResponseModel {
const factory GetDevicesItemResponseModel({
required String id,
required String identificator,
int? battery,
String? userId,
String? companyId,
String? delegationId,
String? groupId,
required Map<String, dynamic> flags,
List<String>? tags,
int? lastConnection,
String? carrierGenre,
int? carrierBirthday,
int? carrierWeight,
int? carrierStepLength,
required String carrierName,
String? comment,
String? phone,
String? simId,
String? simStatus,
Map<String, dynamic>? paymentOptions,
required bool queueCommands,
required Map<String, dynamic> settings,
required String connectionServer,
required String protocol,
required String type,
Map<String, dynamic>? capabilities,
String? backgroundImageId,
required int createdAt,
int? updatedAt,
}) = _GetDevicesItemResponseModel;
factory GetDevicesItemResponseModel.fromJson(Map<String, dynamic> json) =>
_$GetDevicesItemResponseModelFromJson(json);
}
extension GetDevicesResponseModelMapper on GetDevicesResponseModel {
List<DeviceEntity> toEntity() {
return items
.map(
(item) => DeviceEntity(
id: item.id,
identificator: item.identificator,
battery: item.battery,
userId: item.userId,
companyId: item.companyId,
delegationId: item.delegationId,
groupId: item.groupId,
flags: item.flags,
tags: item.tags,
lastConnection: item.lastConnection?.toString(),
carrierGenre: item.carrierGenre,
carrierBirthday: item.carrierBirthday?.toString(),
carrierWeight: item.carrierWeight,
carrierStepLength: item.carrierStepLength,
carrierName: item.carrierName,
comment: item.comment,
phone: item.phone,
simId: item.simId,
paymentOptions: item.paymentOptions,
settings: DeviceSettingsModel.fromJson(item.settings).toEntity(),
connectionServer: item.connectionServer,
protocol: item.protocol,
type: item.type,
capabilities: item.capabilities != null
? DeviceCapabilitiesModel.fromJson(
item.capabilities!,
).toEntity()
: null,
backgroundImageId: item.backgroundImageId,
createdAt: item.createdAt.toString(),
updatedAt: item.updatedAt?.toString(),
),
)
.toList();
}
}

View File

@@ -0,0 +1,666 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
// coverage:ignore-file
// ignore_for_file: type=lint
// ignore_for_file: unused_element, deprecated_member_use, deprecated_member_use_from_same_package, use_function_type_syntax_for_parameters, unnecessary_const, avoid_init_to_null, invalid_override_different_default_values_named, prefer_expression_function_bodies, annotate_overrides, invalid_annotation_target, unnecessary_question_mark
part of 'get_devices_response_model.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$GetDevicesResponseModel {
List<GetDevicesItemResponseModel> get items;
/// Create a copy of GetDevicesResponseModel
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$GetDevicesResponseModelCopyWith<GetDevicesResponseModel> get copyWith => _$GetDevicesResponseModelCopyWithImpl<GetDevicesResponseModel>(this as GetDevicesResponseModel, _$identity);
/// Serializes this GetDevicesResponseModel to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is GetDevicesResponseModel&&const DeepCollectionEquality().equals(other.items, items));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(items));
@override
String toString() {
return 'GetDevicesResponseModel(items: $items)';
}
}
/// @nodoc
abstract mixin class $GetDevicesResponseModelCopyWith<$Res> {
factory $GetDevicesResponseModelCopyWith(GetDevicesResponseModel value, $Res Function(GetDevicesResponseModel) _then) = _$GetDevicesResponseModelCopyWithImpl;
@useResult
$Res call({
List<GetDevicesItemResponseModel> items
});
}
/// @nodoc
class _$GetDevicesResponseModelCopyWithImpl<$Res>
implements $GetDevicesResponseModelCopyWith<$Res> {
_$GetDevicesResponseModelCopyWithImpl(this._self, this._then);
final GetDevicesResponseModel _self;
final $Res Function(GetDevicesResponseModel) _then;
/// Create a copy of GetDevicesResponseModel
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? items = null,}) {
return _then(_self.copyWith(
items: null == items ? _self.items : items // ignore: cast_nullable_to_non_nullable
as List<GetDevicesItemResponseModel>,
));
}
}
/// Adds pattern-matching-related methods to [GetDevicesResponseModel].
extension GetDevicesResponseModelPatterns on GetDevicesResponseModel {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _GetDevicesResponseModel value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _GetDevicesResponseModel() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _GetDevicesResponseModel value) $default,){
final _that = this;
switch (_that) {
case _GetDevicesResponseModel():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _GetDevicesResponseModel value)? $default,){
final _that = this;
switch (_that) {
case _GetDevicesResponseModel() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( List<GetDevicesItemResponseModel> items)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _GetDevicesResponseModel() when $default != null:
return $default(_that.items);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( List<GetDevicesItemResponseModel> items) $default,) {final _that = this;
switch (_that) {
case _GetDevicesResponseModel():
return $default(_that.items);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( List<GetDevicesItemResponseModel> items)? $default,) {final _that = this;
switch (_that) {
case _GetDevicesResponseModel() when $default != null:
return $default(_that.items);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _GetDevicesResponseModel implements GetDevicesResponseModel {
const _GetDevicesResponseModel({required final List<GetDevicesItemResponseModel> items}): _items = items;
factory _GetDevicesResponseModel.fromJson(Map<String, dynamic> json) => _$GetDevicesResponseModelFromJson(json);
final List<GetDevicesItemResponseModel> _items;
@override List<GetDevicesItemResponseModel> get items {
if (_items is EqualUnmodifiableListView) return _items;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(_items);
}
/// Create a copy of GetDevicesResponseModel
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$GetDevicesResponseModelCopyWith<_GetDevicesResponseModel> get copyWith => __$GetDevicesResponseModelCopyWithImpl<_GetDevicesResponseModel>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$GetDevicesResponseModelToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _GetDevicesResponseModel&&const DeepCollectionEquality().equals(other._items, _items));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(_items));
@override
String toString() {
return 'GetDevicesResponseModel(items: $items)';
}
}
/// @nodoc
abstract mixin class _$GetDevicesResponseModelCopyWith<$Res> implements $GetDevicesResponseModelCopyWith<$Res> {
factory _$GetDevicesResponseModelCopyWith(_GetDevicesResponseModel value, $Res Function(_GetDevicesResponseModel) _then) = __$GetDevicesResponseModelCopyWithImpl;
@override @useResult
$Res call({
List<GetDevicesItemResponseModel> items
});
}
/// @nodoc
class __$GetDevicesResponseModelCopyWithImpl<$Res>
implements _$GetDevicesResponseModelCopyWith<$Res> {
__$GetDevicesResponseModelCopyWithImpl(this._self, this._then);
final _GetDevicesResponseModel _self;
final $Res Function(_GetDevicesResponseModel) _then;
/// Create a copy of GetDevicesResponseModel
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? items = null,}) {
return _then(_GetDevicesResponseModel(
items: null == items ? _self._items : items // ignore: cast_nullable_to_non_nullable
as List<GetDevicesItemResponseModel>,
));
}
}
/// @nodoc
mixin _$GetDevicesItemResponseModel {
String get id; String get identificator; int? get battery; String? get userId; String? get companyId; String? get delegationId; String? get groupId; Map<String, dynamic> get flags; List<String>? get tags; int? get lastConnection; String? get carrierGenre; int? get carrierBirthday; int? get carrierWeight; int? get carrierStepLength; String get carrierName; String? get comment; String? get phone; String? get simId; String? get simStatus; Map<String, dynamic>? get paymentOptions; bool get queueCommands; Map<String, dynamic> get settings; String get connectionServer; String get protocol; String get type; Map<String, dynamic>? get capabilities; String? get backgroundImageId; int get createdAt; int? get updatedAt;
/// Create a copy of GetDevicesItemResponseModel
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$GetDevicesItemResponseModelCopyWith<GetDevicesItemResponseModel> get copyWith => _$GetDevicesItemResponseModelCopyWithImpl<GetDevicesItemResponseModel>(this as GetDevicesItemResponseModel, _$identity);
/// Serializes this GetDevicesItemResponseModel to a JSON map.
Map<String, dynamic> toJson();
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is GetDevicesItemResponseModel&&(identical(other.id, id) || other.id == id)&&(identical(other.identificator, identificator) || other.identificator == identificator)&&(identical(other.battery, battery) || other.battery == battery)&&(identical(other.userId, userId) || other.userId == userId)&&(identical(other.companyId, companyId) || other.companyId == companyId)&&(identical(other.delegationId, delegationId) || other.delegationId == delegationId)&&(identical(other.groupId, groupId) || other.groupId == groupId)&&const DeepCollectionEquality().equals(other.flags, flags)&&const DeepCollectionEquality().equals(other.tags, tags)&&(identical(other.lastConnection, lastConnection) || other.lastConnection == lastConnection)&&(identical(other.carrierGenre, carrierGenre) || other.carrierGenre == carrierGenre)&&(identical(other.carrierBirthday, carrierBirthday) || other.carrierBirthday == carrierBirthday)&&(identical(other.carrierWeight, carrierWeight) || other.carrierWeight == carrierWeight)&&(identical(other.carrierStepLength, carrierStepLength) || other.carrierStepLength == carrierStepLength)&&(identical(other.carrierName, carrierName) || other.carrierName == carrierName)&&(identical(other.comment, comment) || other.comment == comment)&&(identical(other.phone, phone) || other.phone == phone)&&(identical(other.simId, simId) || other.simId == simId)&&(identical(other.simStatus, simStatus) || other.simStatus == simStatus)&&const DeepCollectionEquality().equals(other.paymentOptions, paymentOptions)&&(identical(other.queueCommands, queueCommands) || other.queueCommands == queueCommands)&&const DeepCollectionEquality().equals(other.settings, settings)&&(identical(other.connectionServer, connectionServer) || other.connectionServer == connectionServer)&&(identical(other.protocol, protocol) || other.protocol == protocol)&&(identical(other.type, type) || other.type == type)&&const DeepCollectionEquality().equals(other.capabilities, capabilities)&&(identical(other.backgroundImageId, backgroundImageId) || other.backgroundImageId == backgroundImageId)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hashAll([runtimeType,id,identificator,battery,userId,companyId,delegationId,groupId,const DeepCollectionEquality().hash(flags),const DeepCollectionEquality().hash(tags),lastConnection,carrierGenre,carrierBirthday,carrierWeight,carrierStepLength,carrierName,comment,phone,simId,simStatus,const DeepCollectionEquality().hash(paymentOptions),queueCommands,const DeepCollectionEquality().hash(settings),connectionServer,protocol,type,const DeepCollectionEquality().hash(capabilities),backgroundImageId,createdAt,updatedAt]);
@override
String toString() {
return 'GetDevicesItemResponseModel(id: $id, identificator: $identificator, battery: $battery, userId: $userId, companyId: $companyId, delegationId: $delegationId, groupId: $groupId, flags: $flags, tags: $tags, lastConnection: $lastConnection, carrierGenre: $carrierGenre, carrierBirthday: $carrierBirthday, carrierWeight: $carrierWeight, carrierStepLength: $carrierStepLength, carrierName: $carrierName, comment: $comment, phone: $phone, simId: $simId, simStatus: $simStatus, paymentOptions: $paymentOptions, queueCommands: $queueCommands, settings: $settings, connectionServer: $connectionServer, protocol: $protocol, type: $type, capabilities: $capabilities, backgroundImageId: $backgroundImageId, createdAt: $createdAt, updatedAt: $updatedAt)';
}
}
/// @nodoc
abstract mixin class $GetDevicesItemResponseModelCopyWith<$Res> {
factory $GetDevicesItemResponseModelCopyWith(GetDevicesItemResponseModel value, $Res Function(GetDevicesItemResponseModel) _then) = _$GetDevicesItemResponseModelCopyWithImpl;
@useResult
$Res call({
String id, String identificator, int? battery, String? userId, String? companyId, String? delegationId, String? groupId, Map<String, dynamic> flags, List<String>? tags, int? lastConnection, String? carrierGenre, int? carrierBirthday, int? carrierWeight, int? carrierStepLength, String carrierName, String? comment, String? phone, String? simId, String? simStatus, Map<String, dynamic>? paymentOptions, bool queueCommands, Map<String, dynamic> settings, String connectionServer, String protocol, String type, Map<String, dynamic>? capabilities, String? backgroundImageId, int createdAt, int? updatedAt
});
}
/// @nodoc
class _$GetDevicesItemResponseModelCopyWithImpl<$Res>
implements $GetDevicesItemResponseModelCopyWith<$Res> {
_$GetDevicesItemResponseModelCopyWithImpl(this._self, this._then);
final GetDevicesItemResponseModel _self;
final $Res Function(GetDevicesItemResponseModel) _then;
/// Create a copy of GetDevicesItemResponseModel
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? identificator = null,Object? battery = freezed,Object? userId = freezed,Object? companyId = freezed,Object? delegationId = freezed,Object? groupId = freezed,Object? flags = null,Object? tags = freezed,Object? lastConnection = freezed,Object? carrierGenre = freezed,Object? carrierBirthday = freezed,Object? carrierWeight = freezed,Object? carrierStepLength = freezed,Object? carrierName = null,Object? comment = freezed,Object? phone = freezed,Object? simId = freezed,Object? simStatus = freezed,Object? paymentOptions = freezed,Object? queueCommands = null,Object? settings = null,Object? connectionServer = null,Object? protocol = null,Object? type = null,Object? capabilities = freezed,Object? backgroundImageId = freezed,Object? createdAt = null,Object? updatedAt = freezed,}) {
return _then(_self.copyWith(
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
as String,identificator: null == identificator ? _self.identificator : identificator // ignore: cast_nullable_to_non_nullable
as String,battery: freezed == battery ? _self.battery : battery // ignore: cast_nullable_to_non_nullable
as int?,userId: freezed == userId ? _self.userId : userId // ignore: cast_nullable_to_non_nullable
as String?,companyId: freezed == companyId ? _self.companyId : companyId // ignore: cast_nullable_to_non_nullable
as String?,delegationId: freezed == delegationId ? _self.delegationId : delegationId // ignore: cast_nullable_to_non_nullable
as String?,groupId: freezed == groupId ? _self.groupId : groupId // ignore: cast_nullable_to_non_nullable
as String?,flags: null == flags ? _self.flags : flags // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>,tags: freezed == tags ? _self.tags : tags // ignore: cast_nullable_to_non_nullable
as List<String>?,lastConnection: freezed == lastConnection ? _self.lastConnection : lastConnection // ignore: cast_nullable_to_non_nullable
as int?,carrierGenre: freezed == carrierGenre ? _self.carrierGenre : carrierGenre // ignore: cast_nullable_to_non_nullable
as String?,carrierBirthday: freezed == carrierBirthday ? _self.carrierBirthday : carrierBirthday // ignore: cast_nullable_to_non_nullable
as int?,carrierWeight: freezed == carrierWeight ? _self.carrierWeight : carrierWeight // ignore: cast_nullable_to_non_nullable
as int?,carrierStepLength: freezed == carrierStepLength ? _self.carrierStepLength : carrierStepLength // ignore: cast_nullable_to_non_nullable
as int?,carrierName: null == carrierName ? _self.carrierName : carrierName // ignore: cast_nullable_to_non_nullable
as String,comment: freezed == comment ? _self.comment : comment // ignore: cast_nullable_to_non_nullable
as String?,phone: freezed == phone ? _self.phone : phone // ignore: cast_nullable_to_non_nullable
as String?,simId: freezed == simId ? _self.simId : simId // ignore: cast_nullable_to_non_nullable
as String?,simStatus: freezed == simStatus ? _self.simStatus : simStatus // ignore: cast_nullable_to_non_nullable
as String?,paymentOptions: freezed == paymentOptions ? _self.paymentOptions : paymentOptions // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,queueCommands: null == queueCommands ? _self.queueCommands : queueCommands // ignore: cast_nullable_to_non_nullable
as bool,settings: null == settings ? _self.settings : settings // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>,connectionServer: null == connectionServer ? _self.connectionServer : connectionServer // ignore: cast_nullable_to_non_nullable
as String,protocol: null == protocol ? _self.protocol : protocol // ignore: cast_nullable_to_non_nullable
as String,type: null == type ? _self.type : type // ignore: cast_nullable_to_non_nullable
as String,capabilities: freezed == capabilities ? _self.capabilities : capabilities // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,backgroundImageId: freezed == backgroundImageId ? _self.backgroundImageId : backgroundImageId // ignore: cast_nullable_to_non_nullable
as String?,createdAt: null == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable
as int,updatedAt: freezed == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable
as int?,
));
}
}
/// Adds pattern-matching-related methods to [GetDevicesItemResponseModel].
extension GetDevicesItemResponseModelPatterns on GetDevicesItemResponseModel {
/// A variant of `map` that fallback to returning `orElse`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeMap<TResult extends Object?>(TResult Function( _GetDevicesItemResponseModel value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _GetDevicesItemResponseModel() when $default != null:
return $default(_that);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// Callbacks receives the raw object, upcasted.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case final Subclass2 value:
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult map<TResult extends Object?>(TResult Function( _GetDevicesItemResponseModel value) $default,){
final _that = this;
switch (_that) {
case _GetDevicesItemResponseModel():
return $default(_that);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `map` that fallback to returning `null`.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case final Subclass value:
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? mapOrNull<TResult extends Object?>(TResult? Function( _GetDevicesItemResponseModel value)? $default,){
final _that = this;
switch (_that) {
case _GetDevicesItemResponseModel() when $default != null:
return $default(_that);case _:
return null;
}
}
/// A variant of `when` that fallback to an `orElse` callback.
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return orElse();
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( String id, String identificator, int? battery, String? userId, String? companyId, String? delegationId, String? groupId, Map<String, dynamic> flags, List<String>? tags, int? lastConnection, String? carrierGenre, int? carrierBirthday, int? carrierWeight, int? carrierStepLength, String carrierName, String? comment, String? phone, String? simId, String? simStatus, Map<String, dynamic>? paymentOptions, bool queueCommands, Map<String, dynamic> settings, String connectionServer, String protocol, String type, Map<String, dynamic>? capabilities, String? backgroundImageId, int createdAt, int? updatedAt)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _GetDevicesItemResponseModel() when $default != null:
return $default(_that.id,_that.identificator,_that.battery,_that.userId,_that.companyId,_that.delegationId,_that.groupId,_that.flags,_that.tags,_that.lastConnection,_that.carrierGenre,_that.carrierBirthday,_that.carrierWeight,_that.carrierStepLength,_that.carrierName,_that.comment,_that.phone,_that.simId,_that.simStatus,_that.paymentOptions,_that.queueCommands,_that.settings,_that.connectionServer,_that.protocol,_that.type,_that.capabilities,_that.backgroundImageId,_that.createdAt,_that.updatedAt);case _:
return orElse();
}
}
/// A `switch`-like method, using callbacks.
///
/// As opposed to `map`, this offers destructuring.
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case Subclass2(:final field2):
/// return ...;
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( String id, String identificator, int? battery, String? userId, String? companyId, String? delegationId, String? groupId, Map<String, dynamic> flags, List<String>? tags, int? lastConnection, String? carrierGenre, int? carrierBirthday, int? carrierWeight, int? carrierStepLength, String carrierName, String? comment, String? phone, String? simId, String? simStatus, Map<String, dynamic>? paymentOptions, bool queueCommands, Map<String, dynamic> settings, String connectionServer, String protocol, String type, Map<String, dynamic>? capabilities, String? backgroundImageId, int createdAt, int? updatedAt) $default,) {final _that = this;
switch (_that) {
case _GetDevicesItemResponseModel():
return $default(_that.id,_that.identificator,_that.battery,_that.userId,_that.companyId,_that.delegationId,_that.groupId,_that.flags,_that.tags,_that.lastConnection,_that.carrierGenre,_that.carrierBirthday,_that.carrierWeight,_that.carrierStepLength,_that.carrierName,_that.comment,_that.phone,_that.simId,_that.simStatus,_that.paymentOptions,_that.queueCommands,_that.settings,_that.connectionServer,_that.protocol,_that.type,_that.capabilities,_that.backgroundImageId,_that.createdAt,_that.updatedAt);case _:
throw StateError('Unexpected subclass');
}
}
/// A variant of `when` that fallback to returning `null`
///
/// It is equivalent to doing:
/// ```dart
/// switch (sealedClass) {
/// case Subclass(:final field):
/// return ...;
/// case _:
/// return null;
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( String id, String identificator, int? battery, String? userId, String? companyId, String? delegationId, String? groupId, Map<String, dynamic> flags, List<String>? tags, int? lastConnection, String? carrierGenre, int? carrierBirthday, int? carrierWeight, int? carrierStepLength, String carrierName, String? comment, String? phone, String? simId, String? simStatus, Map<String, dynamic>? paymentOptions, bool queueCommands, Map<String, dynamic> settings, String connectionServer, String protocol, String type, Map<String, dynamic>? capabilities, String? backgroundImageId, int createdAt, int? updatedAt)? $default,) {final _that = this;
switch (_that) {
case _GetDevicesItemResponseModel() when $default != null:
return $default(_that.id,_that.identificator,_that.battery,_that.userId,_that.companyId,_that.delegationId,_that.groupId,_that.flags,_that.tags,_that.lastConnection,_that.carrierGenre,_that.carrierBirthday,_that.carrierWeight,_that.carrierStepLength,_that.carrierName,_that.comment,_that.phone,_that.simId,_that.simStatus,_that.paymentOptions,_that.queueCommands,_that.settings,_that.connectionServer,_that.protocol,_that.type,_that.capabilities,_that.backgroundImageId,_that.createdAt,_that.updatedAt);case _:
return null;
}
}
}
/// @nodoc
@JsonSerializable()
class _GetDevicesItemResponseModel implements GetDevicesItemResponseModel {
const _GetDevicesItemResponseModel({required this.id, required this.identificator, this.battery, this.userId, this.companyId, this.delegationId, this.groupId, required final Map<String, dynamic> flags, final List<String>? tags, this.lastConnection, this.carrierGenre, this.carrierBirthday, this.carrierWeight, this.carrierStepLength, required this.carrierName, this.comment, this.phone, this.simId, this.simStatus, final Map<String, dynamic>? paymentOptions, required this.queueCommands, required final Map<String, dynamic> settings, required this.connectionServer, required this.protocol, required this.type, final Map<String, dynamic>? capabilities, this.backgroundImageId, required this.createdAt, this.updatedAt}): _flags = flags,_tags = tags,_paymentOptions = paymentOptions,_settings = settings,_capabilities = capabilities;
factory _GetDevicesItemResponseModel.fromJson(Map<String, dynamic> json) => _$GetDevicesItemResponseModelFromJson(json);
@override final String id;
@override final String identificator;
@override final int? battery;
@override final String? userId;
@override final String? companyId;
@override final String? delegationId;
@override final String? groupId;
final Map<String, dynamic> _flags;
@override Map<String, dynamic> get flags {
if (_flags is EqualUnmodifiableMapView) return _flags;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(_flags);
}
final List<String>? _tags;
@override List<String>? get tags {
final value = _tags;
if (value == null) return null;
if (_tags is EqualUnmodifiableListView) return _tags;
// ignore: implicit_dynamic_type
return EqualUnmodifiableListView(value);
}
@override final int? lastConnection;
@override final String? carrierGenre;
@override final int? carrierBirthday;
@override final int? carrierWeight;
@override final int? carrierStepLength;
@override final String carrierName;
@override final String? comment;
@override final String? phone;
@override final String? simId;
@override final String? simStatus;
final Map<String, dynamic>? _paymentOptions;
@override Map<String, dynamic>? get paymentOptions {
final value = _paymentOptions;
if (value == null) return null;
if (_paymentOptions is EqualUnmodifiableMapView) return _paymentOptions;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(value);
}
@override final bool queueCommands;
final Map<String, dynamic> _settings;
@override Map<String, dynamic> get settings {
if (_settings is EqualUnmodifiableMapView) return _settings;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(_settings);
}
@override final String connectionServer;
@override final String protocol;
@override final String type;
final Map<String, dynamic>? _capabilities;
@override Map<String, dynamic>? get capabilities {
final value = _capabilities;
if (value == null) return null;
if (_capabilities is EqualUnmodifiableMapView) return _capabilities;
// ignore: implicit_dynamic_type
return EqualUnmodifiableMapView(value);
}
@override final String? backgroundImageId;
@override final int createdAt;
@override final int? updatedAt;
/// Create a copy of GetDevicesItemResponseModel
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$GetDevicesItemResponseModelCopyWith<_GetDevicesItemResponseModel> get copyWith => __$GetDevicesItemResponseModelCopyWithImpl<_GetDevicesItemResponseModel>(this, _$identity);
@override
Map<String, dynamic> toJson() {
return _$GetDevicesItemResponseModelToJson(this, );
}
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _GetDevicesItemResponseModel&&(identical(other.id, id) || other.id == id)&&(identical(other.identificator, identificator) || other.identificator == identificator)&&(identical(other.battery, battery) || other.battery == battery)&&(identical(other.userId, userId) || other.userId == userId)&&(identical(other.companyId, companyId) || other.companyId == companyId)&&(identical(other.delegationId, delegationId) || other.delegationId == delegationId)&&(identical(other.groupId, groupId) || other.groupId == groupId)&&const DeepCollectionEquality().equals(other._flags, _flags)&&const DeepCollectionEquality().equals(other._tags, _tags)&&(identical(other.lastConnection, lastConnection) || other.lastConnection == lastConnection)&&(identical(other.carrierGenre, carrierGenre) || other.carrierGenre == carrierGenre)&&(identical(other.carrierBirthday, carrierBirthday) || other.carrierBirthday == carrierBirthday)&&(identical(other.carrierWeight, carrierWeight) || other.carrierWeight == carrierWeight)&&(identical(other.carrierStepLength, carrierStepLength) || other.carrierStepLength == carrierStepLength)&&(identical(other.carrierName, carrierName) || other.carrierName == carrierName)&&(identical(other.comment, comment) || other.comment == comment)&&(identical(other.phone, phone) || other.phone == phone)&&(identical(other.simId, simId) || other.simId == simId)&&(identical(other.simStatus, simStatus) || other.simStatus == simStatus)&&const DeepCollectionEquality().equals(other._paymentOptions, _paymentOptions)&&(identical(other.queueCommands, queueCommands) || other.queueCommands == queueCommands)&&const DeepCollectionEquality().equals(other._settings, _settings)&&(identical(other.connectionServer, connectionServer) || other.connectionServer == connectionServer)&&(identical(other.protocol, protocol) || other.protocol == protocol)&&(identical(other.type, type) || other.type == type)&&const DeepCollectionEquality().equals(other._capabilities, _capabilities)&&(identical(other.backgroundImageId, backgroundImageId) || other.backgroundImageId == backgroundImageId)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt));
}
@JsonKey(includeFromJson: false, includeToJson: false)
@override
int get hashCode => Object.hashAll([runtimeType,id,identificator,battery,userId,companyId,delegationId,groupId,const DeepCollectionEquality().hash(_flags),const DeepCollectionEquality().hash(_tags),lastConnection,carrierGenre,carrierBirthday,carrierWeight,carrierStepLength,carrierName,comment,phone,simId,simStatus,const DeepCollectionEquality().hash(_paymentOptions),queueCommands,const DeepCollectionEquality().hash(_settings),connectionServer,protocol,type,const DeepCollectionEquality().hash(_capabilities),backgroundImageId,createdAt,updatedAt]);
@override
String toString() {
return 'GetDevicesItemResponseModel(id: $id, identificator: $identificator, battery: $battery, userId: $userId, companyId: $companyId, delegationId: $delegationId, groupId: $groupId, flags: $flags, tags: $tags, lastConnection: $lastConnection, carrierGenre: $carrierGenre, carrierBirthday: $carrierBirthday, carrierWeight: $carrierWeight, carrierStepLength: $carrierStepLength, carrierName: $carrierName, comment: $comment, phone: $phone, simId: $simId, simStatus: $simStatus, paymentOptions: $paymentOptions, queueCommands: $queueCommands, settings: $settings, connectionServer: $connectionServer, protocol: $protocol, type: $type, capabilities: $capabilities, backgroundImageId: $backgroundImageId, createdAt: $createdAt, updatedAt: $updatedAt)';
}
}
/// @nodoc
abstract mixin class _$GetDevicesItemResponseModelCopyWith<$Res> implements $GetDevicesItemResponseModelCopyWith<$Res> {
factory _$GetDevicesItemResponseModelCopyWith(_GetDevicesItemResponseModel value, $Res Function(_GetDevicesItemResponseModel) _then) = __$GetDevicesItemResponseModelCopyWithImpl;
@override @useResult
$Res call({
String id, String identificator, int? battery, String? userId, String? companyId, String? delegationId, String? groupId, Map<String, dynamic> flags, List<String>? tags, int? lastConnection, String? carrierGenre, int? carrierBirthday, int? carrierWeight, int? carrierStepLength, String carrierName, String? comment, String? phone, String? simId, String? simStatus, Map<String, dynamic>? paymentOptions, bool queueCommands, Map<String, dynamic> settings, String connectionServer, String protocol, String type, Map<String, dynamic>? capabilities, String? backgroundImageId, int createdAt, int? updatedAt
});
}
/// @nodoc
class __$GetDevicesItemResponseModelCopyWithImpl<$Res>
implements _$GetDevicesItemResponseModelCopyWith<$Res> {
__$GetDevicesItemResponseModelCopyWithImpl(this._self, this._then);
final _GetDevicesItemResponseModel _self;
final $Res Function(_GetDevicesItemResponseModel) _then;
/// Create a copy of GetDevicesItemResponseModel
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? identificator = null,Object? battery = freezed,Object? userId = freezed,Object? companyId = freezed,Object? delegationId = freezed,Object? groupId = freezed,Object? flags = null,Object? tags = freezed,Object? lastConnection = freezed,Object? carrierGenre = freezed,Object? carrierBirthday = freezed,Object? carrierWeight = freezed,Object? carrierStepLength = freezed,Object? carrierName = null,Object? comment = freezed,Object? phone = freezed,Object? simId = freezed,Object? simStatus = freezed,Object? paymentOptions = freezed,Object? queueCommands = null,Object? settings = null,Object? connectionServer = null,Object? protocol = null,Object? type = null,Object? capabilities = freezed,Object? backgroundImageId = freezed,Object? createdAt = null,Object? updatedAt = freezed,}) {
return _then(_GetDevicesItemResponseModel(
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
as String,identificator: null == identificator ? _self.identificator : identificator // ignore: cast_nullable_to_non_nullable
as String,battery: freezed == battery ? _self.battery : battery // ignore: cast_nullable_to_non_nullable
as int?,userId: freezed == userId ? _self.userId : userId // ignore: cast_nullable_to_non_nullable
as String?,companyId: freezed == companyId ? _self.companyId : companyId // ignore: cast_nullable_to_non_nullable
as String?,delegationId: freezed == delegationId ? _self.delegationId : delegationId // ignore: cast_nullable_to_non_nullable
as String?,groupId: freezed == groupId ? _self.groupId : groupId // ignore: cast_nullable_to_non_nullable
as String?,flags: null == flags ? _self._flags : flags // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>,tags: freezed == tags ? _self._tags : tags // ignore: cast_nullable_to_non_nullable
as List<String>?,lastConnection: freezed == lastConnection ? _self.lastConnection : lastConnection // ignore: cast_nullable_to_non_nullable
as int?,carrierGenre: freezed == carrierGenre ? _self.carrierGenre : carrierGenre // ignore: cast_nullable_to_non_nullable
as String?,carrierBirthday: freezed == carrierBirthday ? _self.carrierBirthday : carrierBirthday // ignore: cast_nullable_to_non_nullable
as int?,carrierWeight: freezed == carrierWeight ? _self.carrierWeight : carrierWeight // ignore: cast_nullable_to_non_nullable
as int?,carrierStepLength: freezed == carrierStepLength ? _self.carrierStepLength : carrierStepLength // ignore: cast_nullable_to_non_nullable
as int?,carrierName: null == carrierName ? _self.carrierName : carrierName // ignore: cast_nullable_to_non_nullable
as String,comment: freezed == comment ? _self.comment : comment // ignore: cast_nullable_to_non_nullable
as String?,phone: freezed == phone ? _self.phone : phone // ignore: cast_nullable_to_non_nullable
as String?,simId: freezed == simId ? _self.simId : simId // ignore: cast_nullable_to_non_nullable
as String?,simStatus: freezed == simStatus ? _self.simStatus : simStatus // ignore: cast_nullable_to_non_nullable
as String?,paymentOptions: freezed == paymentOptions ? _self._paymentOptions : paymentOptions // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,queueCommands: null == queueCommands ? _self.queueCommands : queueCommands // ignore: cast_nullable_to_non_nullable
as bool,settings: null == settings ? _self._settings : settings // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>,connectionServer: null == connectionServer ? _self.connectionServer : connectionServer // ignore: cast_nullable_to_non_nullable
as String,protocol: null == protocol ? _self.protocol : protocol // ignore: cast_nullable_to_non_nullable
as String,type: null == type ? _self.type : type // ignore: cast_nullable_to_non_nullable
as String,capabilities: freezed == capabilities ? _self._capabilities : capabilities // ignore: cast_nullable_to_non_nullable
as Map<String, dynamic>?,backgroundImageId: freezed == backgroundImageId ? _self.backgroundImageId : backgroundImageId // ignore: cast_nullable_to_non_nullable
as String?,createdAt: null == createdAt ? _self.createdAt : createdAt // ignore: cast_nullable_to_non_nullable
as int,updatedAt: freezed == updatedAt ? _self.updatedAt : updatedAt // ignore: cast_nullable_to_non_nullable
as int?,
));
}
}
// dart format on

View File

@@ -0,0 +1,89 @@
// GENERATED CODE - DO NOT MODIFY BY HAND
part of 'get_devices_response_model.dart';
// **************************************************************************
// JsonSerializableGenerator
// **************************************************************************
_GetDevicesResponseModel _$GetDevicesResponseModelFromJson(
Map<String, dynamic> json,
) => _GetDevicesResponseModel(
items: (json['items'] as List<dynamic>)
.map(
(e) => GetDevicesItemResponseModel.fromJson(e as Map<String, dynamic>),
)
.toList(),
);
Map<String, dynamic> _$GetDevicesResponseModelToJson(
_GetDevicesResponseModel instance,
) => <String, dynamic>{'items': instance.items};
_GetDevicesItemResponseModel _$GetDevicesItemResponseModelFromJson(
Map<String, dynamic> json,
) => _GetDevicesItemResponseModel(
id: json['id'] as String,
identificator: json['identificator'] as String,
battery: (json['battery'] as num?)?.toInt(),
userId: json['userId'] as String?,
companyId: json['companyId'] as String?,
delegationId: json['delegationId'] as String?,
groupId: json['groupId'] as String?,
flags: json['flags'] as Map<String, dynamic>,
tags: (json['tags'] as List<dynamic>?)?.map((e) => e as String).toList(),
lastConnection: (json['lastConnection'] as num?)?.toInt(),
carrierGenre: json['carrierGenre'] as String?,
carrierBirthday: (json['carrierBirthday'] as num?)?.toInt(),
carrierWeight: (json['carrierWeight'] as num?)?.toInt(),
carrierStepLength: (json['carrierStepLength'] as num?)?.toInt(),
carrierName: json['carrierName'] as String,
comment: json['comment'] as String?,
phone: json['phone'] as String?,
simId: json['simId'] as String?,
simStatus: json['simStatus'] as String?,
paymentOptions: json['paymentOptions'] as Map<String, dynamic>?,
queueCommands: json['queueCommands'] as bool,
settings: json['settings'] as Map<String, dynamic>,
connectionServer: json['connectionServer'] as String,
protocol: json['protocol'] as String,
type: json['type'] as String,
capabilities: json['capabilities'] as Map<String, dynamic>?,
backgroundImageId: json['backgroundImageId'] as String?,
createdAt: (json['createdAt'] as num).toInt(),
updatedAt: (json['updatedAt'] as num?)?.toInt(),
);
Map<String, dynamic> _$GetDevicesItemResponseModelToJson(
_GetDevicesItemResponseModel instance,
) => <String, dynamic>{
'id': instance.id,
'identificator': instance.identificator,
'battery': instance.battery,
'userId': instance.userId,
'companyId': instance.companyId,
'delegationId': instance.delegationId,
'groupId': instance.groupId,
'flags': instance.flags,
'tags': instance.tags,
'lastConnection': instance.lastConnection,
'carrierGenre': instance.carrierGenre,
'carrierBirthday': instance.carrierBirthday,
'carrierWeight': instance.carrierWeight,
'carrierStepLength': instance.carrierStepLength,
'carrierName': instance.carrierName,
'comment': instance.comment,
'phone': instance.phone,
'simId': instance.simId,
'simStatus': instance.simStatus,
'paymentOptions': instance.paymentOptions,
'queueCommands': instance.queueCommands,
'settings': instance.settings,
'connectionServer': instance.connectionServer,
'protocol': instance.protocol,
'type': instance.type,
'capabilities': instance.capabilities,
'backgroundImageId': instance.backgroundImageId,
'createdAt': instance.createdAt,
'updatedAt': instance.updatedAt,
};

View File

@@ -0,0 +1,12 @@
import 'package:sf_shared/sf_shared.dart';
class DevicesRepositoryImpl implements SharedDevicesRepository {
const DevicesRepositoryImpl(this._remote);
final DevicesRemoteDatasource _remote;
@override
Future<List<DeviceEntity>> getDevices() async {
return _remote.getDevices();
}
}

View File

@@ -0,0 +1,5 @@
import 'package:sf_shared/sf_shared.dart';
abstract class SharedDevicesRepository {
Future<List<DeviceEntity>> getDevices();
}

View File

@@ -0,0 +1,12 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:sf_infrastructure/sf_infrastructure.dart';
import '../data/datasource/devices_remote_datasource.dart';
import '../data/datasource/devices_remote_datasource_impl.dart';
final devicesRemoteDatasourceProvider = Provider<DevicesRemoteDatasource>((
ref,
) {
final saveFamilyRepository = getIt<SaveFamilyRepository>();
return DevicesRemoteDatasourceImpl(saveFamilyRepository);
});

View File

@@ -0,0 +1,9 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:sf_shared/sf_shared.dart';
final sharedDevicesRepositoryProvider = Provider<SharedDevicesRepository>((
ref,
) {
final remote = ref.read(devicesRemoteDatasourceProvider);
return DevicesRepositoryImpl(remote);
});

View File

@@ -0,0 +1,39 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:sf_shared/sf_shared.dart';
class LegacyDevices extends AsyncNotifier<List<DeviceEntity>> {
@override
Future<List<DeviceEntity>> build() {
return ref.read(sharedDevicesRepositoryProvider).getDevices();
}
void removeDevice(String deviceId) {
final current = state.value ?? const [];
state = AsyncData(
current.where((d) => d.id != deviceId).toList(growable: false),
);
}
void renameDevice({
required String deviceId,
required String newCarrierName,
}) {
final current = state.value ?? const [];
state = AsyncData([
for (final d in current)
if (d.id == deviceId) d.copyWith(carrierName: newCarrierName) else d,
]);
}
Future<void> refresh() async {
state = const AsyncLoading();
state = await AsyncValue.guard(
() => ref.read(sharedDevicesRepositoryProvider).getDevices(),
);
}
}
final legacyDevicesProvider =
AsyncNotifierProvider<LegacyDevices, List<DeviceEntity>>(
LegacyDevices.new,
);

View File

@@ -0,0 +1,61 @@
import 'package:flutter/foundation.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:sf_shared/sf_shared.dart';
import 'package:shared_preferences/shared_preferences.dart';
const _prefsKey = 'legacy_selected_device_id';
class SelectedDeviceNotifier extends AsyncNotifier<DeviceEntity?> {
@override
Future<DeviceEntity?> build() async {
final devices = await ref.watch(legacyDevicesProvider.future);
if (devices.isEmpty) return null;
final prefs = await SharedPreferences.getInstance();
final persistedId = prefs.getString(_prefsKey);
if (persistedId != null) {
final found = devices.where((d) => d.id == persistedId).firstOrNull;
if (found != null) return found;
}
return devices.first;
}
Future<void> setSelectedDevice(DeviceEntity device) async {
state = AsyncData(device);
try {
final prefs = await SharedPreferences.getInstance();
await prefs.setString(_prefsKey, device.id);
} catch (e) {
debugPrint('[SelectedDeviceNotifier] failed to persist selection: $e');
}
}
void updateSettings(DeviceSettingsEntity settings) {
final current = state.value;
if (current == null) return;
state = AsyncData(current.copyWith(settings: settings));
}
Future<void> clear() async {
state = const AsyncData(null);
try {
final prefs = await SharedPreferences.getInstance();
await prefs.remove(_prefsKey);
} catch (e) {
debugPrint('[SelectedDeviceNotifier] failed to clear selection: $e');
}
}
}
final selectedDeviceProvider =
AsyncNotifierProvider<SelectedDeviceNotifier, DeviceEntity?>(
SelectedDeviceNotifier.new,
);
extension DeviceSettingsSync on Ref {
void syncDeviceSettings(DeviceEntity device, DeviceSettingsEntity settings) {
read(selectedDeviceProvider.notifier).updateSettings(settings);
}
}