contacts endpoints and state fix
This commit is contained in:
@@ -269,7 +269,7 @@ class _SaveSection extends ConsumerWidget {
|
||||
personalDataViewModelProvider.select((s)=>s.errorMessage)
|
||||
);
|
||||
if (errorMessage.isNotEmpty) {
|
||||
showTopSnackbar(context, message: errorMessage);
|
||||
showTopSnackbar(context, message: errorMessage, type: MessageType.error);
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:device_management/src/core/data/models/create_contact_request_model.dart';
|
||||
import 'package:device_management/src/core/data/models/get_contacts_response_model.dart';
|
||||
|
||||
import '../models/update_contact_request_model.dart';
|
||||
|
||||
abstract class ContactsRemoteDatasource {
|
||||
Future<GetContactsResponseModel> getContacts({required String userId});
|
||||
|
||||
Future<void> updateContact({required String userId, required UpdateContactRequestModel request});
|
||||
|
||||
Future<void> createContact({required ContactRequestModel request});
|
||||
|
||||
Future<void> deleteContact({required String contactId});
|
||||
}
|
||||
@@ -0,0 +1,68 @@
|
||||
import 'package:device_management/src/core/data/models/create_contact_request_model.dart';
|
||||
import 'package:dio/dio.dart';
|
||||
import 'package:legacy_shared/legacy_shared.dart';
|
||||
import 'package:sf_infrastructure/sf_infrastructure.dart';
|
||||
|
||||
import '../models/get_contacts_response_model.dart';
|
||||
import '../models/update_contact_request_model.dart';
|
||||
import 'contacts_remote_datasource.dart';
|
||||
|
||||
class ContactsRemoteDatasourceImpl implements ContactsRemoteDatasource {
|
||||
ContactsRemoteDatasourceImpl(this._repository);
|
||||
|
||||
final QuestiaRepository _repository;
|
||||
|
||||
@override
|
||||
Future<GetContactsResponseModel> getContacts({required String userId}) async {
|
||||
try {
|
||||
final response = await _repository.get<Map<String, dynamic>>(
|
||||
'/users/$userId/contacts',
|
||||
);
|
||||
|
||||
final data = response.data;
|
||||
if (data == null || data.isEmpty) {
|
||||
throw Exception('Empty response from /users/:userId/contacts');
|
||||
}
|
||||
|
||||
final model = GetContactsResponseModel.fromJson(data);
|
||||
return model;
|
||||
} on DioException catch (error) {
|
||||
throw mapDioError(error, defaultMessage: 'Error to get contacts');
|
||||
}
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateContact({required String userId, required UpdateContactRequestModel request}) async {
|
||||
final body = request.toJson();
|
||||
await safeCall(
|
||||
() => _repository.put<dynamic>(
|
||||
'/contacts/$userId',
|
||||
body: body,
|
||||
),
|
||||
'Error in /contacts',
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> createContact({required ContactRequestModel request}) async {
|
||||
final body = request.toJson();
|
||||
|
||||
await safeCall(
|
||||
() => _repository.post<dynamic>(
|
||||
'/contacts',
|
||||
body: body,
|
||||
),
|
||||
'Error in /contacts',
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteContact({required String contactId}) async {
|
||||
await safeCall(
|
||||
() => _repository.delete<dynamic>(
|
||||
'/contacts/$contactId',
|
||||
),
|
||||
'Error in /contacts',
|
||||
);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,7 @@
|
||||
import 'package:device_management/src/core/data/models/entities/locate_device_request_entity.dart';
|
||||
import 'package:device_management/src/features/contacts/domain/entities/contact_entity.dart';
|
||||
import 'package:device_management/src/features/remote_connection/domain/entities/picture_entity.dart';
|
||||
|
||||
abstract class FunctionsRemoteDatasource {
|
||||
Future<List<ContactEntity>> getContacts({required String userId});
|
||||
|
||||
Future<List<PictureEntity>> getPictures({required String userId});
|
||||
|
||||
Future<PictureEntity> takePicture({required String userId});
|
||||
|
||||
Future<void> locateDevice({required LocateDeviceRequestEntity request});
|
||||
}
|
||||
|
||||
@@ -1,11 +1,4 @@
|
||||
import 'dart:convert';
|
||||
|
||||
import 'package:dio/dio.dart';
|
||||
// import 'package:flutter/material.dart';
|
||||
import 'package:device_management/src/core/data/datasources/functions_remote_datasource.dart';
|
||||
import 'package:device_management/src/core/data/models/entities/locate_device_request_entity.dart';
|
||||
import 'package:device_management/src/core/data/models/send_command_request_model.dart';
|
||||
import 'package:device_management/src/features/contacts/domain/entities/contact_entity.dart';
|
||||
import 'package:device_management/src/features/remote_connection/domain/entities/picture_entity.dart';
|
||||
import 'package:sf_infrastructure/sf_infrastructure.dart';
|
||||
|
||||
@@ -14,47 +7,6 @@ class FunctionsRemoteDatasourceImpl implements FunctionsRemoteDatasource {
|
||||
|
||||
final QuestiaRepository _repository;
|
||||
|
||||
@override
|
||||
Future<List<ContactEntity>> getContacts({required String userId}) async {
|
||||
/*try {
|
||||
final response = await _repository.get<Map<String, dynamic>>(
|
||||
'/users/$userId/contacts',
|
||||
);
|
||||
|
||||
final data = response.data;
|
||||
if (data == null || data.isEmpty) {
|
||||
throw Exception('Empty response from /users/:userId/contacts');
|
||||
}
|
||||
|
||||
final model = GetContactsResponseModel.fromJson(data);
|
||||
return model.toEntity();
|
||||
} on DioException catch (error) {
|
||||
throw _mapDioError(error, defaultMessage: 'Error to get contacts');
|
||||
}*/
|
||||
return [
|
||||
ContactEntity(
|
||||
id: '1111',
|
||||
name: 'Ana',
|
||||
phone: '111111111',
|
||||
createdAt: 1,
|
||||
delegationId: null,
|
||||
groupId: null,
|
||||
userId: null,
|
||||
updatedAt: null,
|
||||
),
|
||||
ContactEntity(
|
||||
id: '1112',
|
||||
name: 'Carlos',
|
||||
phone: '222222222',
|
||||
createdAt: 2,
|
||||
delegationId: null,
|
||||
groupId: null,
|
||||
userId: null,
|
||||
updatedAt: null,
|
||||
),
|
||||
];
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<PictureEntity>> getPictures({required String userId}) async {
|
||||
/*try {
|
||||
@@ -70,7 +22,7 @@ class FunctionsRemoteDatasourceImpl implements FunctionsRemoteDatasource {
|
||||
final model = GetPicturesResponseModel.fromJson(data);
|
||||
return model.toEntity();
|
||||
} on DioException catch (error) {
|
||||
throw _mapDioError(error, defaultMessage: 'Error to get pictures');
|
||||
throw mapDioError(error, defaultMessage: 'Error to get pictures');
|
||||
}*/
|
||||
return [];
|
||||
}
|
||||
@@ -90,7 +42,7 @@ class FunctionsRemoteDatasourceImpl implements FunctionsRemoteDatasource {
|
||||
final model = GetContactsResponseModel.fromJson(data);
|
||||
return model.toEntity();
|
||||
} on DioException catch (error) {
|
||||
throw _mapDioError(error, defaultMessage: 'Error to get contacts');
|
||||
throw mapDioError(error, defaultMessage: 'Error to get contacts');
|
||||
}*/
|
||||
return PictureEntity(
|
||||
id: '1',
|
||||
@@ -100,54 +52,4 @@ class FunctionsRemoteDatasourceImpl implements FunctionsRemoteDatasource {
|
||||
asset: 'assets/shared/images/iso_sf.png',
|
||||
);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> locateDevice({
|
||||
required LocateDeviceRequestEntity request,
|
||||
}) async {
|
||||
try {
|
||||
final body = request.toModel().toJson();
|
||||
await _repository.post<void>('/commands', body: body);
|
||||
} on DioException catch (error) {
|
||||
throw _mapDioError(
|
||||
error,
|
||||
defaultMessage: error.response?.data ?? 'Error to locate device',
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'create_contact_request_model.freezed.dart';
|
||||
part 'create_contact_request_model.g.dart';
|
||||
|
||||
@freezed
|
||||
abstract class ContactRequestModel with _$ContactRequestModel {
|
||||
const factory ContactRequestModel({
|
||||
required String id,
|
||||
required String name,
|
||||
required String phone,
|
||||
String? userId,
|
||||
}) = _ContactRequestModel;
|
||||
|
||||
factory ContactRequestModel.fromJson(Map<String, dynamic> json) =>
|
||||
_$ContactRequestModelFromJson(json);
|
||||
}
|
||||
@@ -0,0 +1,286 @@
|
||||
// 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 'create_contact_request_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// dart format off
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
/// @nodoc
|
||||
mixin _$ContactRequestModel {
|
||||
|
||||
String get id; String get name; String get phone; String? get userId;
|
||||
/// Create a copy of ContactRequestModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$ContactRequestModelCopyWith<ContactRequestModel> get copyWith => _$ContactRequestModelCopyWithImpl<ContactRequestModel>(this as ContactRequestModel, _$identity);
|
||||
|
||||
/// Serializes this ContactRequestModel to a JSON map.
|
||||
Map<String, dynamic> toJson();
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is ContactRequestModel&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name)&&(identical(other.phone, phone) || other.phone == phone)&&(identical(other.userId, userId) || other.userId == userId));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,id,name,phone,userId);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ContactRequestModel(id: $id, name: $name, phone: $phone, userId: $userId)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $ContactRequestModelCopyWith<$Res> {
|
||||
factory $ContactRequestModelCopyWith(ContactRequestModel value, $Res Function(ContactRequestModel) _then) = _$ContactRequestModelCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
String id, String name, String phone, String? userId
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class _$ContactRequestModelCopyWithImpl<$Res>
|
||||
implements $ContactRequestModelCopyWith<$Res> {
|
||||
_$ContactRequestModelCopyWithImpl(this._self, this._then);
|
||||
|
||||
final ContactRequestModel _self;
|
||||
final $Res Function(ContactRequestModel) _then;
|
||||
|
||||
/// Create a copy of ContactRequestModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? name = null,Object? phone = null,Object? userId = freezed,}) {
|
||||
return _then(_self.copyWith(
|
||||
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
|
||||
as String,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
|
||||
as String,phone: null == phone ? _self.phone : phone // ignore: cast_nullable_to_non_nullable
|
||||
as String,userId: freezed == userId ? _self.userId : userId // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [ContactRequestModel].
|
||||
extension ContactRequestModelPatterns on ContactRequestModel {
|
||||
/// 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( _ContactRequestModel value)? $default,{required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _ContactRequestModel() 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( _ContactRequestModel value) $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _ContactRequestModel():
|
||||
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( _ContactRequestModel value)? $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _ContactRequestModel() 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 name, String phone, String? userId)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _ContactRequestModel() when $default != null:
|
||||
return $default(_that.id,_that.name,_that.phone,_that.userId);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 name, String phone, String? userId) $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _ContactRequestModel():
|
||||
return $default(_that.id,_that.name,_that.phone,_that.userId);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 name, String phone, String? userId)? $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _ContactRequestModel() when $default != null:
|
||||
return $default(_that.id,_that.name,_that.phone,_that.userId);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
|
||||
class _ContactRequestModel implements ContactRequestModel {
|
||||
const _ContactRequestModel({required this.id, required this.name, required this.phone, this.userId});
|
||||
factory _ContactRequestModel.fromJson(Map<String, dynamic> json) => _$ContactRequestModelFromJson(json);
|
||||
|
||||
@override final String id;
|
||||
@override final String name;
|
||||
@override final String phone;
|
||||
@override final String? userId;
|
||||
|
||||
/// Create a copy of ContactRequestModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$ContactRequestModelCopyWith<_ContactRequestModel> get copyWith => __$ContactRequestModelCopyWithImpl<_ContactRequestModel>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$ContactRequestModelToJson(this, );
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _ContactRequestModel&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name)&&(identical(other.phone, phone) || other.phone == phone)&&(identical(other.userId, userId) || other.userId == userId));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,id,name,phone,userId);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ContactRequestModel(id: $id, name: $name, phone: $phone, userId: $userId)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$ContactRequestModelCopyWith<$Res> implements $ContactRequestModelCopyWith<$Res> {
|
||||
factory _$ContactRequestModelCopyWith(_ContactRequestModel value, $Res Function(_ContactRequestModel) _then) = __$ContactRequestModelCopyWithImpl;
|
||||
@override @useResult
|
||||
$Res call({
|
||||
String id, String name, String phone, String? userId
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$ContactRequestModelCopyWithImpl<$Res>
|
||||
implements _$ContactRequestModelCopyWith<$Res> {
|
||||
__$ContactRequestModelCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _ContactRequestModel _self;
|
||||
final $Res Function(_ContactRequestModel) _then;
|
||||
|
||||
/// Create a copy of ContactRequestModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? name = null,Object? phone = null,Object? userId = freezed,}) {
|
||||
return _then(_ContactRequestModel(
|
||||
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
|
||||
as String,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
|
||||
as String,phone: null == phone ? _self.phone : phone // ignore: cast_nullable_to_non_nullable
|
||||
as String,userId: freezed == userId ? _self.userId : userId // ignore: cast_nullable_to_non_nullable
|
||||
as String?,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// dart format on
|
||||
@@ -0,0 +1,24 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'create_contact_request_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_ContactRequestModel _$ContactRequestModelFromJson(Map<String, dynamic> json) =>
|
||||
_ContactRequestModel(
|
||||
id: json['id'] as String,
|
||||
name: json['name'] as String,
|
||||
phone: json['phone'] as String,
|
||||
userId: json['userId'] as String?,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$ContactRequestModelToJson(
|
||||
_ContactRequestModel instance,
|
||||
) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
'phone': instance.phone,
|
||||
'userId': instance.userId,
|
||||
};
|
||||
@@ -0,0 +1,49 @@
|
||||
import 'package:device_management/src/features/contacts/domain/entities/contact_entity.dart';
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'get_contacts_response_model.freezed.dart';
|
||||
part 'get_contacts_response_model.g.dart';
|
||||
|
||||
@freezed
|
||||
abstract class GetContactsResponseModel with _$GetContactsResponseModel {
|
||||
const factory GetContactsResponseModel({
|
||||
required List<GetContactsItemResponseModel> items,
|
||||
}) = _GetContactsResponseModel;
|
||||
|
||||
factory GetContactsResponseModel.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetContactsResponseModelFromJson(json);
|
||||
|
||||
}
|
||||
|
||||
@freezed
|
||||
abstract class GetContactsItemResponseModel with _$GetContactsItemResponseModel {
|
||||
const factory GetContactsItemResponseModel({
|
||||
required String id,
|
||||
required String name,
|
||||
required String phone,
|
||||
required String? delegationId,
|
||||
required String? groupId,
|
||||
required String? userId,
|
||||
required int createdAt,
|
||||
required int? updatedAt,
|
||||
}) =
|
||||
_GetContactsItemResponseModel;
|
||||
|
||||
factory GetContactsItemResponseModel.fromJson(Map<String, dynamic> json) =>
|
||||
_$GetContactsItemResponseModelFromJson(json);
|
||||
}
|
||||
|
||||
extension GetContactsItemResponseModelMapper on GetContactsResponseModel {
|
||||
List<ContactEntity> toEntity() {
|
||||
return items.map((GetContactsItemResponseModel item) => ContactEntity(
|
||||
id: item.id,
|
||||
name: item.name,
|
||||
phone: item.phone,
|
||||
delegationId: item.delegationId,
|
||||
groupId: item.groupId,
|
||||
userId: item.userId,
|
||||
createdAt: item.createdAt,
|
||||
updatedAt: item.updatedAt,
|
||||
)).toList();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,567 @@
|
||||
// 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_contacts_response_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// dart format off
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
/// @nodoc
|
||||
mixin _$GetContactsResponseModel {
|
||||
|
||||
List<GetContactsItemResponseModel> get items;
|
||||
/// Create a copy of GetContactsResponseModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$GetContactsResponseModelCopyWith<GetContactsResponseModel> get copyWith => _$GetContactsResponseModelCopyWithImpl<GetContactsResponseModel>(this as GetContactsResponseModel, _$identity);
|
||||
|
||||
/// Serializes this GetContactsResponseModel to a JSON map.
|
||||
Map<String, dynamic> toJson();
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is GetContactsResponseModel&&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 'GetContactsResponseModel(items: $items)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $GetContactsResponseModelCopyWith<$Res> {
|
||||
factory $GetContactsResponseModelCopyWith(GetContactsResponseModel value, $Res Function(GetContactsResponseModel) _then) = _$GetContactsResponseModelCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
List<GetContactsItemResponseModel> items
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class _$GetContactsResponseModelCopyWithImpl<$Res>
|
||||
implements $GetContactsResponseModelCopyWith<$Res> {
|
||||
_$GetContactsResponseModelCopyWithImpl(this._self, this._then);
|
||||
|
||||
final GetContactsResponseModel _self;
|
||||
final $Res Function(GetContactsResponseModel) _then;
|
||||
|
||||
/// Create a copy of GetContactsResponseModel
|
||||
/// 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<GetContactsItemResponseModel>,
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [GetContactsResponseModel].
|
||||
extension GetContactsResponseModelPatterns on GetContactsResponseModel {
|
||||
/// 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( _GetContactsResponseModel value)? $default,{required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _GetContactsResponseModel() 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( _GetContactsResponseModel value) $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _GetContactsResponseModel():
|
||||
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( _GetContactsResponseModel value)? $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _GetContactsResponseModel() 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<GetContactsItemResponseModel> items)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _GetContactsResponseModel() 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<GetContactsItemResponseModel> items) $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _GetContactsResponseModel():
|
||||
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<GetContactsItemResponseModel> items)? $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _GetContactsResponseModel() when $default != null:
|
||||
return $default(_that.items);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
|
||||
class _GetContactsResponseModel implements GetContactsResponseModel {
|
||||
const _GetContactsResponseModel({required final List<GetContactsItemResponseModel> items}): _items = items;
|
||||
factory _GetContactsResponseModel.fromJson(Map<String, dynamic> json) => _$GetContactsResponseModelFromJson(json);
|
||||
|
||||
final List<GetContactsItemResponseModel> _items;
|
||||
@override List<GetContactsItemResponseModel> get items {
|
||||
if (_items is EqualUnmodifiableListView) return _items;
|
||||
// ignore: implicit_dynamic_type
|
||||
return EqualUnmodifiableListView(_items);
|
||||
}
|
||||
|
||||
|
||||
/// Create a copy of GetContactsResponseModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$GetContactsResponseModelCopyWith<_GetContactsResponseModel> get copyWith => __$GetContactsResponseModelCopyWithImpl<_GetContactsResponseModel>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$GetContactsResponseModelToJson(this, );
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _GetContactsResponseModel&&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 'GetContactsResponseModel(items: $items)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$GetContactsResponseModelCopyWith<$Res> implements $GetContactsResponseModelCopyWith<$Res> {
|
||||
factory _$GetContactsResponseModelCopyWith(_GetContactsResponseModel value, $Res Function(_GetContactsResponseModel) _then) = __$GetContactsResponseModelCopyWithImpl;
|
||||
@override @useResult
|
||||
$Res call({
|
||||
List<GetContactsItemResponseModel> items
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$GetContactsResponseModelCopyWithImpl<$Res>
|
||||
implements _$GetContactsResponseModelCopyWith<$Res> {
|
||||
__$GetContactsResponseModelCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _GetContactsResponseModel _self;
|
||||
final $Res Function(_GetContactsResponseModel) _then;
|
||||
|
||||
/// Create a copy of GetContactsResponseModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? items = null,}) {
|
||||
return _then(_GetContactsResponseModel(
|
||||
items: null == items ? _self._items : items // ignore: cast_nullable_to_non_nullable
|
||||
as List<GetContactsItemResponseModel>,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// @nodoc
|
||||
mixin _$GetContactsItemResponseModel {
|
||||
|
||||
String get id; String get name; String get phone; String? get delegationId; String? get groupId; String? get userId; int get createdAt; int? get updatedAt;
|
||||
/// Create a copy of GetContactsItemResponseModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$GetContactsItemResponseModelCopyWith<GetContactsItemResponseModel> get copyWith => _$GetContactsItemResponseModelCopyWithImpl<GetContactsItemResponseModel>(this as GetContactsItemResponseModel, _$identity);
|
||||
|
||||
/// Serializes this GetContactsItemResponseModel to a JSON map.
|
||||
Map<String, dynamic> toJson();
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is GetContactsItemResponseModel&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name)&&(identical(other.phone, phone) || other.phone == phone)&&(identical(other.delegationId, delegationId) || other.delegationId == delegationId)&&(identical(other.groupId, groupId) || other.groupId == groupId)&&(identical(other.userId, userId) || other.userId == userId)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,id,name,phone,delegationId,groupId,userId,createdAt,updatedAt);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'GetContactsItemResponseModel(id: $id, name: $name, phone: $phone, delegationId: $delegationId, groupId: $groupId, userId: $userId, createdAt: $createdAt, updatedAt: $updatedAt)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $GetContactsItemResponseModelCopyWith<$Res> {
|
||||
factory $GetContactsItemResponseModelCopyWith(GetContactsItemResponseModel value, $Res Function(GetContactsItemResponseModel) _then) = _$GetContactsItemResponseModelCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
String id, String name, String phone, String? delegationId, String? groupId, String? userId, int createdAt, int? updatedAt
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class _$GetContactsItemResponseModelCopyWithImpl<$Res>
|
||||
implements $GetContactsItemResponseModelCopyWith<$Res> {
|
||||
_$GetContactsItemResponseModelCopyWithImpl(this._self, this._then);
|
||||
|
||||
final GetContactsItemResponseModel _self;
|
||||
final $Res Function(GetContactsItemResponseModel) _then;
|
||||
|
||||
/// Create a copy of GetContactsItemResponseModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? name = null,Object? phone = null,Object? delegationId = freezed,Object? groupId = freezed,Object? userId = 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,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
|
||||
as String,phone: null == phone ? _self.phone : phone // 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?,userId: freezed == userId ? _self.userId : userId // 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 [GetContactsItemResponseModel].
|
||||
extension GetContactsItemResponseModelPatterns on GetContactsItemResponseModel {
|
||||
/// 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( _GetContactsItemResponseModel value)? $default,{required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _GetContactsItemResponseModel() 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( _GetContactsItemResponseModel value) $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _GetContactsItemResponseModel():
|
||||
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( _GetContactsItemResponseModel value)? $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _GetContactsItemResponseModel() 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 name, String phone, String? delegationId, String? groupId, String? userId, int createdAt, int? updatedAt)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _GetContactsItemResponseModel() when $default != null:
|
||||
return $default(_that.id,_that.name,_that.phone,_that.delegationId,_that.groupId,_that.userId,_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 name, String phone, String? delegationId, String? groupId, String? userId, int createdAt, int? updatedAt) $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _GetContactsItemResponseModel():
|
||||
return $default(_that.id,_that.name,_that.phone,_that.delegationId,_that.groupId,_that.userId,_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 name, String phone, String? delegationId, String? groupId, String? userId, int createdAt, int? updatedAt)? $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _GetContactsItemResponseModel() when $default != null:
|
||||
return $default(_that.id,_that.name,_that.phone,_that.delegationId,_that.groupId,_that.userId,_that.createdAt,_that.updatedAt);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
|
||||
class _GetContactsItemResponseModel implements GetContactsItemResponseModel {
|
||||
const _GetContactsItemResponseModel({required this.id, required this.name, required this.phone, required this.delegationId, required this.groupId, required this.userId, required this.createdAt, required this.updatedAt});
|
||||
factory _GetContactsItemResponseModel.fromJson(Map<String, dynamic> json) => _$GetContactsItemResponseModelFromJson(json);
|
||||
|
||||
@override final String id;
|
||||
@override final String name;
|
||||
@override final String phone;
|
||||
@override final String? delegationId;
|
||||
@override final String? groupId;
|
||||
@override final String? userId;
|
||||
@override final int createdAt;
|
||||
@override final int? updatedAt;
|
||||
|
||||
/// Create a copy of GetContactsItemResponseModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$GetContactsItemResponseModelCopyWith<_GetContactsItemResponseModel> get copyWith => __$GetContactsItemResponseModelCopyWithImpl<_GetContactsItemResponseModel>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$GetContactsItemResponseModelToJson(this, );
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _GetContactsItemResponseModel&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name)&&(identical(other.phone, phone) || other.phone == phone)&&(identical(other.delegationId, delegationId) || other.delegationId == delegationId)&&(identical(other.groupId, groupId) || other.groupId == groupId)&&(identical(other.userId, userId) || other.userId == userId)&&(identical(other.createdAt, createdAt) || other.createdAt == createdAt)&&(identical(other.updatedAt, updatedAt) || other.updatedAt == updatedAt));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,id,name,phone,delegationId,groupId,userId,createdAt,updatedAt);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'GetContactsItemResponseModel(id: $id, name: $name, phone: $phone, delegationId: $delegationId, groupId: $groupId, userId: $userId, createdAt: $createdAt, updatedAt: $updatedAt)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$GetContactsItemResponseModelCopyWith<$Res> implements $GetContactsItemResponseModelCopyWith<$Res> {
|
||||
factory _$GetContactsItemResponseModelCopyWith(_GetContactsItemResponseModel value, $Res Function(_GetContactsItemResponseModel) _then) = __$GetContactsItemResponseModelCopyWithImpl;
|
||||
@override @useResult
|
||||
$Res call({
|
||||
String id, String name, String phone, String? delegationId, String? groupId, String? userId, int createdAt, int? updatedAt
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$GetContactsItemResponseModelCopyWithImpl<$Res>
|
||||
implements _$GetContactsItemResponseModelCopyWith<$Res> {
|
||||
__$GetContactsItemResponseModelCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _GetContactsItemResponseModel _self;
|
||||
final $Res Function(_GetContactsItemResponseModel) _then;
|
||||
|
||||
/// Create a copy of GetContactsItemResponseModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? name = null,Object? phone = null,Object? delegationId = freezed,Object? groupId = freezed,Object? userId = freezed,Object? createdAt = null,Object? updatedAt = freezed,}) {
|
||||
return _then(_GetContactsItemResponseModel(
|
||||
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
|
||||
as String,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
|
||||
as String,phone: null == phone ? _self.phone : phone // 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?,userId: freezed == userId ? _self.userId : userId // 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
|
||||
@@ -0,0 +1,47 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'get_contacts_response_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_GetContactsResponseModel _$GetContactsResponseModelFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => _GetContactsResponseModel(
|
||||
items: (json['items'] as List<dynamic>)
|
||||
.map(
|
||||
(e) => GetContactsItemResponseModel.fromJson(e as Map<String, dynamic>),
|
||||
)
|
||||
.toList(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GetContactsResponseModelToJson(
|
||||
_GetContactsResponseModel instance,
|
||||
) => <String, dynamic>{'items': instance.items};
|
||||
|
||||
_GetContactsItemResponseModel _$GetContactsItemResponseModelFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => _GetContactsItemResponseModel(
|
||||
id: json['id'] as String,
|
||||
name: json['name'] as String,
|
||||
phone: json['phone'] as String,
|
||||
delegationId: json['delegationId'] as String?,
|
||||
groupId: json['groupId'] as String?,
|
||||
userId: json['userId'] as String?,
|
||||
createdAt: (json['createdAt'] as num).toInt(),
|
||||
updatedAt: (json['updatedAt'] as num?)?.toInt(),
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$GetContactsItemResponseModelToJson(
|
||||
_GetContactsItemResponseModel instance,
|
||||
) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
'phone': instance.phone,
|
||||
'delegationId': instance.delegationId,
|
||||
'groupId': instance.groupId,
|
||||
'userId': instance.userId,
|
||||
'createdAt': instance.createdAt,
|
||||
'updatedAt': instance.updatedAt,
|
||||
};
|
||||
@@ -1,24 +0,0 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
import 'package:device_management/src/core/data/models/entities/locate_device_request_entity.dart';
|
||||
|
||||
part 'send_command_request_model.freezed.dart';
|
||||
part 'send_command_request_model.g.dart';
|
||||
|
||||
@freezed
|
||||
abstract class SendCommandRequestModel with _$SendCommandRequestModel {
|
||||
const factory SendCommandRequestModel({
|
||||
required String deviceName,
|
||||
required String command,
|
||||
}) = _SendCommandRequestModel;
|
||||
|
||||
factory SendCommandRequestModel.fromJson(Map<String, dynamic> json) =>
|
||||
_$SendCommandRequestModelFromJson(json);
|
||||
|
||||
}
|
||||
|
||||
extension SendCommandRequestModelMapper on LocateDeviceRequestEntity {
|
||||
SendCommandRequestModel toModel() => SendCommandRequestModel(
|
||||
deviceName: deviceName,
|
||||
command: 'FIND_DEVICE',
|
||||
);
|
||||
}
|
||||
@@ -1,280 +0,0 @@
|
||||
// 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 'send_command_request_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// dart format off
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
/// @nodoc
|
||||
mixin _$SendCommandRequestModel {
|
||||
|
||||
String get deviceName; String get command;
|
||||
/// Create a copy of SendCommandRequestModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$SendCommandRequestModelCopyWith<SendCommandRequestModel> get copyWith => _$SendCommandRequestModelCopyWithImpl<SendCommandRequestModel>(this as SendCommandRequestModel, _$identity);
|
||||
|
||||
/// Serializes this SendCommandRequestModel to a JSON map.
|
||||
Map<String, dynamic> toJson();
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is SendCommandRequestModel&&(identical(other.deviceName, deviceName) || other.deviceName == deviceName)&&(identical(other.command, command) || other.command == command));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,deviceName,command);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'SendCommandRequestModel(deviceName: $deviceName, command: $command)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $SendCommandRequestModelCopyWith<$Res> {
|
||||
factory $SendCommandRequestModelCopyWith(SendCommandRequestModel value, $Res Function(SendCommandRequestModel) _then) = _$SendCommandRequestModelCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
String deviceName, String command
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class _$SendCommandRequestModelCopyWithImpl<$Res>
|
||||
implements $SendCommandRequestModelCopyWith<$Res> {
|
||||
_$SendCommandRequestModelCopyWithImpl(this._self, this._then);
|
||||
|
||||
final SendCommandRequestModel _self;
|
||||
final $Res Function(SendCommandRequestModel) _then;
|
||||
|
||||
/// Create a copy of SendCommandRequestModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? deviceName = null,Object? command = null,}) {
|
||||
return _then(_self.copyWith(
|
||||
deviceName: null == deviceName ? _self.deviceName : deviceName // ignore: cast_nullable_to_non_nullable
|
||||
as String,command: null == command ? _self.command : command // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [SendCommandRequestModel].
|
||||
extension SendCommandRequestModelPatterns on SendCommandRequestModel {
|
||||
/// 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( _SendCommandRequestModel value)? $default,{required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _SendCommandRequestModel() 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( _SendCommandRequestModel value) $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _SendCommandRequestModel():
|
||||
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( _SendCommandRequestModel value)? $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _SendCommandRequestModel() 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 deviceName, String command)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _SendCommandRequestModel() when $default != null:
|
||||
return $default(_that.deviceName,_that.command);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 deviceName, String command) $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _SendCommandRequestModel():
|
||||
return $default(_that.deviceName,_that.command);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 deviceName, String command)? $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _SendCommandRequestModel() when $default != null:
|
||||
return $default(_that.deviceName,_that.command);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
|
||||
class _SendCommandRequestModel implements SendCommandRequestModel {
|
||||
const _SendCommandRequestModel({required this.deviceName, required this.command});
|
||||
factory _SendCommandRequestModel.fromJson(Map<String, dynamic> json) => _$SendCommandRequestModelFromJson(json);
|
||||
|
||||
@override final String deviceName;
|
||||
@override final String command;
|
||||
|
||||
/// Create a copy of SendCommandRequestModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$SendCommandRequestModelCopyWith<_SendCommandRequestModel> get copyWith => __$SendCommandRequestModelCopyWithImpl<_SendCommandRequestModel>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$SendCommandRequestModelToJson(this, );
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _SendCommandRequestModel&&(identical(other.deviceName, deviceName) || other.deviceName == deviceName)&&(identical(other.command, command) || other.command == command));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,deviceName,command);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'SendCommandRequestModel(deviceName: $deviceName, command: $command)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$SendCommandRequestModelCopyWith<$Res> implements $SendCommandRequestModelCopyWith<$Res> {
|
||||
factory _$SendCommandRequestModelCopyWith(_SendCommandRequestModel value, $Res Function(_SendCommandRequestModel) _then) = __$SendCommandRequestModelCopyWithImpl;
|
||||
@override @useResult
|
||||
$Res call({
|
||||
String deviceName, String command
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$SendCommandRequestModelCopyWithImpl<$Res>
|
||||
implements _$SendCommandRequestModelCopyWith<$Res> {
|
||||
__$SendCommandRequestModelCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _SendCommandRequestModel _self;
|
||||
final $Res Function(_SendCommandRequestModel) _then;
|
||||
|
||||
/// Create a copy of SendCommandRequestModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? deviceName = null,Object? command = null,}) {
|
||||
return _then(_SendCommandRequestModel(
|
||||
deviceName: null == deviceName ? _self.deviceName : deviceName // ignore: cast_nullable_to_non_nullable
|
||||
as String,command: null == command ? _self.command : command // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// dart format on
|
||||
@@ -1,21 +0,0 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'send_command_request_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_SendCommandRequestModel _$SendCommandRequestModelFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => _SendCommandRequestModel(
|
||||
deviceName: json['deviceName'] as String,
|
||||
command: json['command'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$SendCommandRequestModelToJson(
|
||||
_SendCommandRequestModel instance,
|
||||
) => <String, dynamic>{
|
||||
'deviceName': instance.deviceName,
|
||||
'command': instance.command,
|
||||
};
|
||||
@@ -0,0 +1,16 @@
|
||||
import 'package:freezed_annotation/freezed_annotation.dart';
|
||||
|
||||
part 'update_contact_request_model.freezed.dart';
|
||||
part 'update_contact_request_model.g.dart';
|
||||
|
||||
@freezed
|
||||
abstract class UpdateContactRequestModel with _$UpdateContactRequestModel {
|
||||
const factory UpdateContactRequestModel({
|
||||
required String id,
|
||||
required String name,
|
||||
required String phone,
|
||||
}) = _UpdateContactRequestModel;
|
||||
|
||||
factory UpdateContactRequestModel.fromJson(Map<String, dynamic> json) =>
|
||||
_$UpdateContactRequestModelFromJson(json);
|
||||
}
|
||||
@@ -0,0 +1,283 @@
|
||||
// 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 'update_contact_request_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// FreezedGenerator
|
||||
// **************************************************************************
|
||||
|
||||
// dart format off
|
||||
T _$identity<T>(T value) => value;
|
||||
|
||||
/// @nodoc
|
||||
mixin _$UpdateContactRequestModel {
|
||||
|
||||
String get id; String get name; String get phone;
|
||||
/// Create a copy of UpdateContactRequestModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
$UpdateContactRequestModelCopyWith<UpdateContactRequestModel> get copyWith => _$UpdateContactRequestModelCopyWithImpl<UpdateContactRequestModel>(this as UpdateContactRequestModel, _$identity);
|
||||
|
||||
/// Serializes this UpdateContactRequestModel to a JSON map.
|
||||
Map<String, dynamic> toJson();
|
||||
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is UpdateContactRequestModel&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name)&&(identical(other.phone, phone) || other.phone == phone));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,id,name,phone);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'UpdateContactRequestModel(id: $id, name: $name, phone: $phone)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class $UpdateContactRequestModelCopyWith<$Res> {
|
||||
factory $UpdateContactRequestModelCopyWith(UpdateContactRequestModel value, $Res Function(UpdateContactRequestModel) _then) = _$UpdateContactRequestModelCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
String id, String name, String phone
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class _$UpdateContactRequestModelCopyWithImpl<$Res>
|
||||
implements $UpdateContactRequestModelCopyWith<$Res> {
|
||||
_$UpdateContactRequestModelCopyWithImpl(this._self, this._then);
|
||||
|
||||
final UpdateContactRequestModel _self;
|
||||
final $Res Function(UpdateContactRequestModel) _then;
|
||||
|
||||
/// Create a copy of UpdateContactRequestModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? id = null,Object? name = null,Object? phone = null,}) {
|
||||
return _then(_self.copyWith(
|
||||
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
|
||||
as String,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
|
||||
as String,phone: null == phone ? _self.phone : phone // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/// Adds pattern-matching-related methods to [UpdateContactRequestModel].
|
||||
extension UpdateContactRequestModelPatterns on UpdateContactRequestModel {
|
||||
/// 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( _UpdateContactRequestModel value)? $default,{required TResult orElse(),}){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _UpdateContactRequestModel() 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( _UpdateContactRequestModel value) $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _UpdateContactRequestModel():
|
||||
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( _UpdateContactRequestModel value)? $default,){
|
||||
final _that = this;
|
||||
switch (_that) {
|
||||
case _UpdateContactRequestModel() 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 name, String phone)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _UpdateContactRequestModel() when $default != null:
|
||||
return $default(_that.id,_that.name,_that.phone);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 name, String phone) $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _UpdateContactRequestModel():
|
||||
return $default(_that.id,_that.name,_that.phone);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 name, String phone)? $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _UpdateContactRequestModel() when $default != null:
|
||||
return $default(_that.id,_that.name,_that.phone);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
@JsonSerializable()
|
||||
|
||||
class _UpdateContactRequestModel implements UpdateContactRequestModel {
|
||||
const _UpdateContactRequestModel({required this.id, required this.name, required this.phone});
|
||||
factory _UpdateContactRequestModel.fromJson(Map<String, dynamic> json) => _$UpdateContactRequestModelFromJson(json);
|
||||
|
||||
@override final String id;
|
||||
@override final String name;
|
||||
@override final String phone;
|
||||
|
||||
/// Create a copy of UpdateContactRequestModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@pragma('vm:prefer-inline')
|
||||
_$UpdateContactRequestModelCopyWith<_UpdateContactRequestModel> get copyWith => __$UpdateContactRequestModelCopyWithImpl<_UpdateContactRequestModel>(this, _$identity);
|
||||
|
||||
@override
|
||||
Map<String, dynamic> toJson() {
|
||||
return _$UpdateContactRequestModelToJson(this, );
|
||||
}
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _UpdateContactRequestModel&&(identical(other.id, id) || other.id == id)&&(identical(other.name, name) || other.name == name)&&(identical(other.phone, phone) || other.phone == phone));
|
||||
}
|
||||
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,id,name,phone);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'UpdateContactRequestModel(id: $id, name: $name, phone: $phone)';
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
/// @nodoc
|
||||
abstract mixin class _$UpdateContactRequestModelCopyWith<$Res> implements $UpdateContactRequestModelCopyWith<$Res> {
|
||||
factory _$UpdateContactRequestModelCopyWith(_UpdateContactRequestModel value, $Res Function(_UpdateContactRequestModel) _then) = __$UpdateContactRequestModelCopyWithImpl;
|
||||
@override @useResult
|
||||
$Res call({
|
||||
String id, String name, String phone
|
||||
});
|
||||
|
||||
|
||||
|
||||
|
||||
}
|
||||
/// @nodoc
|
||||
class __$UpdateContactRequestModelCopyWithImpl<$Res>
|
||||
implements _$UpdateContactRequestModelCopyWith<$Res> {
|
||||
__$UpdateContactRequestModelCopyWithImpl(this._self, this._then);
|
||||
|
||||
final _UpdateContactRequestModel _self;
|
||||
final $Res Function(_UpdateContactRequestModel) _then;
|
||||
|
||||
/// Create a copy of UpdateContactRequestModel
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? id = null,Object? name = null,Object? phone = null,}) {
|
||||
return _then(_UpdateContactRequestModel(
|
||||
id: null == id ? _self.id : id // ignore: cast_nullable_to_non_nullable
|
||||
as String,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
|
||||
as String,phone: null == phone ? _self.phone : phone // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
));
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
// dart format on
|
||||
@@ -0,0 +1,23 @@
|
||||
// GENERATED CODE - DO NOT MODIFY BY HAND
|
||||
|
||||
part of 'update_contact_request_model.dart';
|
||||
|
||||
// **************************************************************************
|
||||
// JsonSerializableGenerator
|
||||
// **************************************************************************
|
||||
|
||||
_UpdateContactRequestModel _$UpdateContactRequestModelFromJson(
|
||||
Map<String, dynamic> json,
|
||||
) => _UpdateContactRequestModel(
|
||||
id: json['id'] as String,
|
||||
name: json['name'] as String,
|
||||
phone: json['phone'] as String,
|
||||
);
|
||||
|
||||
Map<String, dynamic> _$UpdateContactRequestModelToJson(
|
||||
_UpdateContactRequestModel instance,
|
||||
) => <String, dynamic>{
|
||||
'id': instance.id,
|
||||
'name': instance.name,
|
||||
'phone': instance.phone,
|
||||
};
|
||||
@@ -0,0 +1,34 @@
|
||||
import 'package:device_management/src/core/data/models/get_contacts_response_model.dart';
|
||||
import 'package:device_management/src/features/contacts/domain/entities/contact_entity.dart';
|
||||
|
||||
import '../../domain/repositories/contacts_repository.dart';
|
||||
import '../datasources/contacts_remote_datasource.dart';
|
||||
import '../models/create_contact_request_model.dart';
|
||||
import '../models/update_contact_request_model.dart';
|
||||
|
||||
class ContactsRepositoryImpl implements ContactsRepository {
|
||||
const ContactsRepositoryImpl(this._remote);
|
||||
|
||||
final ContactsRemoteDatasource _remote;
|
||||
|
||||
@override
|
||||
Future<List<ContactEntity>> getContacts({required String userId}) async {
|
||||
final model = await _remote.getContacts(userId: userId);
|
||||
return model.toEntity();
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> updateContact({required String userId, required UpdateContactRequestModel request}) {
|
||||
return _remote.updateContact(userId: userId, request: request);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> createContact({required ContactRequestModel request}) {
|
||||
return _remote.createContact(request: request);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> deleteContact({required String contactId}) {
|
||||
return _remote.deleteContact(contactId: contactId);
|
||||
}
|
||||
}
|
||||
@@ -1,7 +1,5 @@
|
||||
import 'package:device_management/src/core/data/datasources/functions_remote_datasource.dart';
|
||||
import 'package:device_management/src/core/data/models/entities/locate_device_request_entity.dart';
|
||||
import 'package:device_management/src/core/domain/repositories/functions_repository.dart';
|
||||
import 'package:device_management/src/features/contacts/domain/entities/contact_entity.dart';
|
||||
import 'package:device_management/src/features/remote_connection/domain/entities/picture_entity.dart';
|
||||
|
||||
class FunctionsRepositoryImpl implements FunctionsRepository {
|
||||
@@ -9,11 +7,6 @@ class FunctionsRepositoryImpl implements FunctionsRepository {
|
||||
|
||||
final FunctionsRemoteDatasource _remote;
|
||||
|
||||
@override
|
||||
Future<List<ContactEntity>> getContacts({required String userId}) {
|
||||
return _remote.getContacts(userId: userId);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<List<PictureEntity>> getPictures({required String userId}) async {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 2000));
|
||||
@@ -25,10 +18,4 @@ class FunctionsRepositoryImpl implements FunctionsRepository {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 2000));
|
||||
return _remote.takePicture(userId: userId);
|
||||
}
|
||||
|
||||
@override
|
||||
Future<void> locateDevice({required LocateDeviceRequestEntity request}) async {
|
||||
await Future<void>.delayed(const Duration(milliseconds: 2000));
|
||||
return _remote.locateDevice(request: request);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,14 @@
|
||||
import 'package:device_management/src/core/data/models/create_contact_request_model.dart';
|
||||
|
||||
import '../../../features/contacts/domain/entities/contact_entity.dart';
|
||||
import '../../data/models/update_contact_request_model.dart';
|
||||
|
||||
abstract class ContactsRepository {
|
||||
Future<List<ContactEntity>> getContacts({required String userId});
|
||||
|
||||
Future<void> updateContact({required String userId, required UpdateContactRequestModel request});
|
||||
|
||||
Future<void> createContact({required ContactRequestModel request});
|
||||
|
||||
Future<void> deleteContact({required String contactId});
|
||||
}
|
||||
@@ -1,13 +1,7 @@
|
||||
import 'package:device_management/src/core/data/models/entities/locate_device_request_entity.dart';
|
||||
import 'package:device_management/src/features/contacts/domain/entities/contact_entity.dart';
|
||||
import 'package:device_management/src/features/remote_connection/domain/entities/picture_entity.dart';
|
||||
|
||||
abstract class FunctionsRepository {
|
||||
Future<List<ContactEntity>> getContacts({required String userId});
|
||||
|
||||
Future<List<PictureEntity>> getPictures({required String userId});
|
||||
|
||||
Future<PictureEntity> takePicture({required String userId});
|
||||
|
||||
Future<void> locateDevice({required LocateDeviceRequestEntity request});
|
||||
}
|
||||
|
||||
@@ -0,0 +1,10 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:sf_infrastructure/sf_infrastructure.dart';
|
||||
|
||||
import '../data/datasources/contacts_remote_datasource.dart';
|
||||
import '../data/datasources/contacts_remote_datasource_impl.dart';
|
||||
|
||||
final contactsRemoteDatasourceProvider = Provider<ContactsRemoteDatasource>((ref) {
|
||||
final questiaRepository = getIt<QuestiaRepository>();
|
||||
return ContactsRemoteDatasourceImpl(questiaRepository);
|
||||
});
|
||||
@@ -0,0 +1,10 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
|
||||
import '../data/repositories/contacts_repository_impl.dart';
|
||||
import '../domain/repositories/contacts_repository.dart';
|
||||
import 'contacts_remote_datasource_provider.dart';
|
||||
|
||||
final contactsRepositoryProvider = Provider<ContactsRepository>((ref) {
|
||||
final remote = ref.read(contactsRemoteDatasourceProvider);
|
||||
return ContactsRepositoryImpl(remote);
|
||||
});
|
||||
@@ -1,5 +0,0 @@
|
||||
import 'package:device_management/src/features/contacts/domain/entities/contact_entity.dart';
|
||||
|
||||
abstract class GetContactsUseCase {
|
||||
Future<List<ContactEntity>> getContacts({required String userId});
|
||||
}
|
||||
@@ -1,14 +0,0 @@
|
||||
import 'package:device_management/src/core/domain/repositories/functions_repository.dart';
|
||||
import 'package:device_management/src/features/contacts/domain/entities/contact_entity.dart';
|
||||
import 'package:device_management/src/features/contacts/domain/get_contacts_use_case.dart';
|
||||
|
||||
class GetContactsUseCaseImpl implements GetContactsUseCase {
|
||||
GetContactsUseCaseImpl(this._repository);
|
||||
|
||||
final FunctionsRepository _repository;
|
||||
|
||||
@override
|
||||
Future<List<ContactEntity>> getContacts({required String userId}) {
|
||||
return _repository.getContacts(userId: userId);
|
||||
}
|
||||
}
|
||||
@@ -1,13 +1,17 @@
|
||||
import 'package:design_system/design_system.dart';
|
||||
import 'package:device_management/src/features/contacts/presentation/widgets/new_contact_dialog.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:device_management/src/features/contacts/domain/entities/contact_entity.dart';
|
||||
import 'package:device_management/src/features/contacts/presentation/edit_contact_screen.dart';
|
||||
import 'package:device_management/src/features/contacts/presentation/state/contacts_view_model.dart';
|
||||
import 'package:legacy_shared/legacy_shared.dart';
|
||||
import 'package:navigation/navigation.dart';
|
||||
import 'package:sf_localizations/sf_localizations.dart';
|
||||
import 'package:utils/utils.dart';
|
||||
|
||||
import 'widgets/confirm_delete_dialog.dart';
|
||||
|
||||
class ContactsScreen extends ConsumerWidget {
|
||||
final NavigationContract navigationContract;
|
||||
|
||||
@@ -20,89 +24,46 @@ class ContactsScreen extends ConsumerWidget {
|
||||
|
||||
final theme = ref.watch(themePortProvider);
|
||||
|
||||
return Scaffold(
|
||||
backgroundColor: theme.getColorFor(ThemeCode.backgroundPrimary),
|
||||
body: SafeArea(
|
||||
child: Column(
|
||||
children: [
|
||||
Container(
|
||||
padding: SizeUtils.getByScreen(
|
||||
small: EdgeInsets.symmetric(horizontal: 22, vertical: 10),
|
||||
big: EdgeInsets.symmetric(horizontal: 21, vertical: 8)
|
||||
),
|
||||
child: Stack(
|
||||
children: [
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
IconButton(onPressed: () {navigationContract.goBack();},
|
||||
icon: Icon(Icons.arrow_back)),
|
||||
if (!state.isEditing) ...[
|
||||
DecoratedBox(
|
||||
decoration: BoxDecoration(
|
||||
color: theme.getColorFor(ThemeCode.legacyPrimary),
|
||||
shape: BoxShape.circle
|
||||
),
|
||||
child: IconButton(onPressed: vm.toggleIsEditing,
|
||||
icon: Icon(Icons.edit_outlined,
|
||||
color: Colors.white,
|
||||
size: SizeUtils.getByScreen(small: 30, big: 28),
|
||||
)
|
||||
),
|
||||
)
|
||||
]
|
||||
],
|
||||
),
|
||||
Center(
|
||||
child: Text(context.translate('Agenda'),
|
||||
style: TextStyle(
|
||||
fontSize: SizeUtils.getByScreen(small: 28, big: 27)
|
||||
),
|
||||
)
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
SizedBox(height: SizeUtils.getByScreen(small: 20, big: 18)),
|
||||
Expanded( child: Container(
|
||||
padding: SizeUtils.getByScreen(
|
||||
small: EdgeInsets.symmetric(horizontal: 22, vertical: 10),
|
||||
big: EdgeInsets.symmetric(horizontal: 21, vertical: 8)
|
||||
),
|
||||
child: ListView.separated(
|
||||
itemBuilder: (BuildContext context, int index)=>ContactCard(
|
||||
contact: state.contacts[index],
|
||||
isEditing: state.isEditing,
|
||||
),
|
||||
separatorBuilder: (BuildContext context, int index)=>SizedBox(
|
||||
height: SizeUtils.getByScreen(small: 18, big: 17)
|
||||
),
|
||||
itemCount: state.contacts.length
|
||||
),
|
||||
)),
|
||||
if (state.isEditing) ...[
|
||||
Container(
|
||||
padding: SizeUtils.getByScreen(
|
||||
small: EdgeInsets.symmetric(horizontal: 26, vertical: 14),
|
||||
big: EdgeInsets.symmetric(horizontal: 24, vertical: 12)
|
||||
),
|
||||
),
|
||||
],
|
||||
Container(
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: theme.getColorFor(ThemeCode.legacyPrimary),
|
||||
),
|
||||
width: SizeUtils.getByScreen(small: 48, big: 46),
|
||||
child: CustomTextButton(
|
||||
onPressed: (){},
|
||||
text: '+',
|
||||
color: Colors.white,
|
||||
size: SizeUtils.getByScreen(small: 48, big: 47),
|
||||
),
|
||||
),
|
||||
],
|
||||
)
|
||||
return LegacyPageLayout(
|
||||
theme: theme,
|
||||
title: context.translate(I18n.contacts),
|
||||
showEdit: true,
|
||||
onEditChange: vm.toggleIsEditing,
|
||||
body: Container(
|
||||
padding: SizeUtils.getByScreen(
|
||||
small: EdgeInsets.symmetric(horizontal: 22, vertical: 10),
|
||||
big: EdgeInsets.symmetric(horizontal: 21, vertical: 8)
|
||||
),
|
||||
child: ListView.separated(
|
||||
itemBuilder: (BuildContext context, int index)=>ContactCard(
|
||||
contact: state.contacts[index],
|
||||
isEditing: state.isEditing,
|
||||
),
|
||||
separatorBuilder: (BuildContext context, int index)=>SizedBox(
|
||||
height: SizeUtils.getByScreen(small: 18, big: 17)
|
||||
),
|
||||
itemCount: state.contacts.length
|
||||
),
|
||||
),
|
||||
footer: Container(
|
||||
decoration: BoxDecoration(
|
||||
shape: BoxShape.circle,
|
||||
color: theme.getColorFor(ThemeCode.legacyPrimary),
|
||||
),
|
||||
width: SizeUtils.getByScreen(small: 48, big: 46),
|
||||
child: CustomTextButton(
|
||||
onPressed: (){
|
||||
showDialog(context: context, builder: (context) =>
|
||||
Dialog(
|
||||
backgroundColor: Colors.transparent,
|
||||
child: NewContactDialog(),
|
||||
)
|
||||
);
|
||||
},
|
||||
text: '+',
|
||||
color: Colors.white,
|
||||
size: SizeUtils.getByScreen(small: 48, big: 47),
|
||||
),
|
||||
),
|
||||
);
|
||||
}
|
||||
@@ -172,45 +133,7 @@ class ContactCard extends ConsumerWidget {
|
||||
),
|
||||
child: IconButton(
|
||||
onPressed: (){showDialog(context: context, builder: (context)=>Dialog(
|
||||
child: Container(
|
||||
padding: SizeUtils.getByScreen(
|
||||
small: EdgeInsets.symmetric(horizontal: 32, vertical: 30),
|
||||
big: EdgeInsets.symmetric(horizontal: 30, vertical: 28)
|
||||
),
|
||||
width: SizeUtils.getByScreen(small: 360, big: 350),
|
||||
height: SizeUtils.getByScreen(small: 195, big: 185),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(context.translate(I18n.deleteUserDialog),
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: SizeUtils.getByScreen(small: 19, big: 18)),
|
||||
),
|
||||
SizedBox(height: SizeUtils.getByScreen(small: 28, big: 27)),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(child: PrimaryButton(
|
||||
onPressed: (){Navigator.pop(context);},
|
||||
text: context.translate(I18n.cancel),
|
||||
color: theme.getColorFor(ThemeCode.legacyPrimary),
|
||||
height: SizeUtils.getByScreen(small: 38, big: 36),
|
||||
radius: SizeUtils.getByScreen(small: 32, big: 34),
|
||||
)),
|
||||
SizedBox(width: SizeUtils.getByScreen(small: 4, big: 16)),
|
||||
Expanded(child: PrimaryButton(
|
||||
onPressed: (){
|
||||
Navigator.pop(context);
|
||||
},
|
||||
text: context.translate(I18n.delete),
|
||||
color: theme.getColorFor(ThemeCode.legacyPrimary),
|
||||
height: SizeUtils.getByScreen(small: 38, big: 36),
|
||||
radius: SizeUtils.getByScreen(small: 32, big: 34),
|
||||
))
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
),
|
||||
child: ConfirmDeleteDialog(contact: contact),
|
||||
));},
|
||||
icon: Icon(
|
||||
Icons.close,
|
||||
|
||||
@@ -125,7 +125,28 @@ class EditContactScreen extends ConsumerWidget {
|
||||
],
|
||||
),
|
||||
PrimaryButton(
|
||||
onPressed: (){vm.updateContact(contact);},
|
||||
onPressed: () async {
|
||||
await vm.updateContact(contact);
|
||||
|
||||
final errorMessage = ref.read(
|
||||
contactsViewModelProvider.select((s)=>s.errorMessage)
|
||||
);
|
||||
if (errorMessage.isNotEmpty) {
|
||||
showTopSnackbar(
|
||||
context,
|
||||
message: errorMessage,
|
||||
type: MessageType.error
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final isComplete = ref.read(
|
||||
contactsViewModelProvider.select((s)=>s.isComplete)
|
||||
);
|
||||
if (isComplete){
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
text: context.translate(I18n.save),
|
||||
color: theme.getColorFor(ThemeCode.legacyPrimary)
|
||||
)
|
||||
|
||||
@@ -1,9 +0,0 @@
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:device_management/src/core/providers/functions_repository_provider.dart';
|
||||
import 'package:device_management/src/features/contacts/domain/get_contacts_use_case.dart';
|
||||
import 'package:device_management/src/features/contacts/domain/get_contacts_use_case_impl.dart';
|
||||
|
||||
final getContactsUseCaseProvider = Provider.autoDispose<GetContactsUseCase>((ref) {
|
||||
final functionsRepository = ref.read(functionsRepositoryProvider);
|
||||
return GetContactsUseCaseImpl(functionsRepository);
|
||||
});
|
||||
@@ -1,12 +1,13 @@
|
||||
import 'package:device_management/src/core/data/models/update_contact_request_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:device_management/src/features/contacts/domain/entities/contact_entity.dart';
|
||||
import 'package:device_management/src/features/contacts/domain/get_contacts_use_case.dart';
|
||||
import 'package:device_management/src/features/contacts/presentation/providers/get_contacts_use_case_provider.dart';
|
||||
import 'package:device_management/src/features/contacts/presentation/state/contacts_view_state.dart';
|
||||
// import 'package:legacy_shared/src/providers/logged_user_provider.dart';
|
||||
// import 'package:legacy_shared/src/data/models/entities/user_entity.dart';
|
||||
// import 'package:sf_localizations/sf_localizations.dart';
|
||||
import 'package:sf_shared/sf_shared.dart';
|
||||
|
||||
import '../../../../core/data/models/create_contact_request_model.dart';
|
||||
import '../../../../core/domain/repositories/contacts_repository.dart';
|
||||
import '../../../../core/providers/contacts_repository_provider.dart';
|
||||
|
||||
final contactsViewModelProvider =
|
||||
NotifierProvider.autoDispose<ContactsViewModel, ContactsViewState>(
|
||||
@@ -14,30 +15,41 @@ NotifierProvider.autoDispose<ContactsViewModel, ContactsViewState>(
|
||||
);
|
||||
|
||||
class ContactsViewModel extends Notifier<ContactsViewState> {
|
||||
late final GetContactsUseCase _getContactsUseCase;
|
||||
static final RegExp _phoneRegex = RegExp(r'^\+?\d{6,15}$');
|
||||
|
||||
late final ContactsRepository _contactsRepository;
|
||||
|
||||
late final TextEditingController nameController;
|
||||
late final TextEditingController phoneController;
|
||||
|
||||
// late final UserEntity loggedUser;
|
||||
|
||||
@override
|
||||
ContactsViewState build() {
|
||||
_getContactsUseCase = ref.read(getContactsUseCaseProvider);
|
||||
_contactsRepository = ref.read(contactsRepositoryProvider);
|
||||
|
||||
// loggedUser = ref.read(loggedUserProvider);
|
||||
_initControllers();
|
||||
_init();
|
||||
|
||||
return const ContactsViewState();
|
||||
}
|
||||
|
||||
void _initControllers() {
|
||||
nameController = TextEditingController();
|
||||
phoneController = TextEditingController();
|
||||
|
||||
nameController.addListener(_onNameChanged);
|
||||
phoneController.addListener(_onPhoneChanged);
|
||||
|
||||
_getContactsUseCase.getContacts(userId: '').then(setContacts);
|
||||
|
||||
ref.onDispose(disposeControllers);
|
||||
}
|
||||
|
||||
return const ContactsViewState();
|
||||
Future<void> _init() async {
|
||||
final user = await ref.read(userInfoProvider.future);
|
||||
|
||||
final contacts = await _contactsRepository.getContacts(userId: user.id);
|
||||
state = state.copyWith(
|
||||
contacts: contacts,
|
||||
isLoading: false,
|
||||
);
|
||||
}
|
||||
|
||||
void setContacts(List<ContactEntity> contacts) {
|
||||
@@ -64,7 +76,125 @@ class ContactsViewModel extends Notifier<ContactsViewState> {
|
||||
state = state.copyWith(phone: text, errorMessage: '');
|
||||
}
|
||||
|
||||
void updateContact(ContactEntity contact) {
|
||||
void updateDialCode(String dialCode) {
|
||||
state = state.copyWith(dialCode: dialCode, errorMessage: '');
|
||||
}
|
||||
|
||||
Future<void> updateContact(ContactEntity contact) async {
|
||||
if (state.isLoading) return;
|
||||
if (state.errorMessage.isNotEmpty) return;
|
||||
|
||||
try {
|
||||
state = state.copyWith(
|
||||
isLoading: true,
|
||||
isComplete: false
|
||||
);
|
||||
|
||||
final name = state.name;
|
||||
final phone = state.phone;
|
||||
final dialCode = state.dialCode;
|
||||
|
||||
if (name.isEmpty && phone.isEmpty) {
|
||||
state = state.copyWith(isLoading: false);
|
||||
return;
|
||||
}
|
||||
|
||||
if (phone.isNotEmpty && !_phoneRegex.hasMatch(phone)) {
|
||||
state = state.copyWith(
|
||||
isLoading: false,
|
||||
errorMessage: 'errorMessagePhoneIsInvalid'
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final request = UpdateContactRequestModel(
|
||||
id: contact.id,
|
||||
name: name.isEmpty? contact.name : name,
|
||||
phone: phone.isEmpty? contact.phone : dialCode + phone
|
||||
);
|
||||
|
||||
final user = await ref.read(userInfoProvider.future);
|
||||
|
||||
_contactsRepository.updateContact(userId: user.id, request: request);
|
||||
|
||||
state = state.copyWith(
|
||||
isLoading: false,
|
||||
isComplete: true
|
||||
);
|
||||
} catch(e) {
|
||||
state = state.copyWith(
|
||||
isLoading: false,
|
||||
errorMessage: e.toString()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> createContact() async {
|
||||
if (state.isLoading) return;
|
||||
if (state.errorMessage.isNotEmpty) return;
|
||||
|
||||
try {
|
||||
state = state.copyWith(
|
||||
isLoading: true,
|
||||
isComplete: false
|
||||
);
|
||||
|
||||
final name = state.name;
|
||||
final phone = state.phone;
|
||||
|
||||
if (!_phoneRegex.hasMatch(phone)) {
|
||||
state = state.copyWith(errorMessage: 'errorMessagePhoneIsInvalid');
|
||||
return;
|
||||
}
|
||||
|
||||
final user = await ref.read(userInfoProvider.future);
|
||||
|
||||
final request = ContactRequestModel(
|
||||
id: '',
|
||||
name: name,
|
||||
phone: phone,
|
||||
userId: user.id,
|
||||
);
|
||||
|
||||
_contactsRepository.createContact(request: request);
|
||||
|
||||
state = state.copyWith(
|
||||
isLoading: false,
|
||||
isComplete: true
|
||||
);
|
||||
} catch(e) {
|
||||
state = state.copyWith(
|
||||
isLoading: false,
|
||||
errorMessage: e.toString()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> deleteContact(ContactEntity contact) async {
|
||||
|
||||
if (state.isLoading) return;
|
||||
|
||||
try {
|
||||
state = state.copyWith(
|
||||
isLoading: true,
|
||||
isComplete: false,
|
||||
);
|
||||
|
||||
await _contactsRepository.deleteContact(contactId: contact.id);
|
||||
|
||||
state = state.copyWith(
|
||||
isLoading: false,
|
||||
isComplete: true,
|
||||
);
|
||||
|
||||
ref.invalidateSelf();
|
||||
|
||||
} catch(e) {
|
||||
state = state.copyWith(
|
||||
isLoading: false,
|
||||
errorMessage: e.toString()
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -8,9 +8,11 @@ abstract class ContactsViewState with _$ContactsViewState {
|
||||
const factory ContactsViewState({
|
||||
@Default([]) List<ContactEntity> contacts,
|
||||
@Default(false) bool isLoading,
|
||||
@Default(false) bool isComplete,
|
||||
@Default(false) bool isEditing,
|
||||
@Default('') String name,
|
||||
@Default('') String phone,
|
||||
@Default('+34') String dialCode,
|
||||
@Default('') String errorMessage,
|
||||
}) = _ContactsViewState;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ T _$identity<T>(T value) => value;
|
||||
/// @nodoc
|
||||
mixin _$ContactsViewState {
|
||||
|
||||
List<ContactEntity> get contacts; bool get isLoading; bool get isEditing; String get name; String get phone; String get errorMessage;
|
||||
List<ContactEntity> get contacts; bool get isLoading; bool get isComplete; bool get isEditing; String get name; String get phone; String get dialCode; String get errorMessage;
|
||||
/// Create a copy of ContactsViewState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@@ -25,16 +25,16 @@ $ContactsViewStateCopyWith<ContactsViewState> get copyWith => _$ContactsViewStat
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is ContactsViewState&&const DeepCollectionEquality().equals(other.contacts, contacts)&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.isEditing, isEditing) || other.isEditing == isEditing)&&(identical(other.name, name) || other.name == name)&&(identical(other.phone, phone) || other.phone == phone)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is ContactsViewState&&const DeepCollectionEquality().equals(other.contacts, contacts)&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.isComplete, isComplete) || other.isComplete == isComplete)&&(identical(other.isEditing, isEditing) || other.isEditing == isEditing)&&(identical(other.name, name) || other.name == name)&&(identical(other.phone, phone) || other.phone == phone)&&(identical(other.dialCode, dialCode) || other.dialCode == dialCode)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(contacts),isLoading,isEditing,name,phone,errorMessage);
|
||||
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(contacts),isLoading,isComplete,isEditing,name,phone,dialCode,errorMessage);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ContactsViewState(contacts: $contacts, isLoading: $isLoading, isEditing: $isEditing, name: $name, phone: $phone, errorMessage: $errorMessage)';
|
||||
return 'ContactsViewState(contacts: $contacts, isLoading: $isLoading, isComplete: $isComplete, isEditing: $isEditing, name: $name, phone: $phone, dialCode: $dialCode, errorMessage: $errorMessage)';
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ abstract mixin class $ContactsViewStateCopyWith<$Res> {
|
||||
factory $ContactsViewStateCopyWith(ContactsViewState value, $Res Function(ContactsViewState) _then) = _$ContactsViewStateCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
List<ContactEntity> contacts, bool isLoading, bool isEditing, String name, String phone, String errorMessage
|
||||
List<ContactEntity> contacts, bool isLoading, bool isComplete, bool isEditing, String name, String phone, String dialCode, String errorMessage
|
||||
});
|
||||
|
||||
|
||||
@@ -62,13 +62,15 @@ class _$ContactsViewStateCopyWithImpl<$Res>
|
||||
|
||||
/// Create a copy of ContactsViewState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? contacts = null,Object? isLoading = null,Object? isEditing = null,Object? name = null,Object? phone = null,Object? errorMessage = null,}) {
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? contacts = null,Object? isLoading = null,Object? isComplete = null,Object? isEditing = null,Object? name = null,Object? phone = null,Object? dialCode = null,Object? errorMessage = null,}) {
|
||||
return _then(_self.copyWith(
|
||||
contacts: null == contacts ? _self.contacts : contacts // ignore: cast_nullable_to_non_nullable
|
||||
as List<ContactEntity>,isLoading: null == isLoading ? _self.isLoading : isLoading // ignore: cast_nullable_to_non_nullable
|
||||
as bool,isComplete: null == isComplete ? _self.isComplete : isComplete // ignore: cast_nullable_to_non_nullable
|
||||
as bool,isEditing: null == isEditing ? _self.isEditing : isEditing // ignore: cast_nullable_to_non_nullable
|
||||
as bool,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
|
||||
as String,phone: null == phone ? _self.phone : phone // ignore: cast_nullable_to_non_nullable
|
||||
as String,dialCode: null == dialCode ? _self.dialCode : dialCode // ignore: cast_nullable_to_non_nullable
|
||||
as String,errorMessage: null == errorMessage ? _self.errorMessage : errorMessage // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
));
|
||||
@@ -155,10 +157,10 @@ return $default(_that);case _:
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( List<ContactEntity> contacts, bool isLoading, bool isEditing, String name, String phone, String errorMessage)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( List<ContactEntity> contacts, bool isLoading, bool isComplete, bool isEditing, String name, String phone, String dialCode, String errorMessage)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _ContactsViewState() when $default != null:
|
||||
return $default(_that.contacts,_that.isLoading,_that.isEditing,_that.name,_that.phone,_that.errorMessage);case _:
|
||||
return $default(_that.contacts,_that.isLoading,_that.isComplete,_that.isEditing,_that.name,_that.phone,_that.dialCode,_that.errorMessage);case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
@@ -176,10 +178,10 @@ return $default(_that.contacts,_that.isLoading,_that.isEditing,_that.name,_that.
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( List<ContactEntity> contacts, bool isLoading, bool isEditing, String name, String phone, String errorMessage) $default,) {final _that = this;
|
||||
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( List<ContactEntity> contacts, bool isLoading, bool isComplete, bool isEditing, String name, String phone, String dialCode, String errorMessage) $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _ContactsViewState():
|
||||
return $default(_that.contacts,_that.isLoading,_that.isEditing,_that.name,_that.phone,_that.errorMessage);case _:
|
||||
return $default(_that.contacts,_that.isLoading,_that.isComplete,_that.isEditing,_that.name,_that.phone,_that.dialCode,_that.errorMessage);case _:
|
||||
throw StateError('Unexpected subclass');
|
||||
|
||||
}
|
||||
@@ -196,10 +198,10 @@ return $default(_that.contacts,_that.isLoading,_that.isEditing,_that.name,_that.
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( List<ContactEntity> contacts, bool isLoading, bool isEditing, String name, String phone, String errorMessage)? $default,) {final _that = this;
|
||||
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( List<ContactEntity> contacts, bool isLoading, bool isComplete, bool isEditing, String name, String phone, String dialCode, String errorMessage)? $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _ContactsViewState() when $default != null:
|
||||
return $default(_that.contacts,_that.isLoading,_that.isEditing,_that.name,_that.phone,_that.errorMessage);case _:
|
||||
return $default(_that.contacts,_that.isLoading,_that.isComplete,_that.isEditing,_that.name,_that.phone,_that.dialCode,_that.errorMessage);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
@@ -211,7 +213,7 @@ return $default(_that.contacts,_that.isLoading,_that.isEditing,_that.name,_that.
|
||||
|
||||
|
||||
class _ContactsViewState implements ContactsViewState {
|
||||
const _ContactsViewState({final List<ContactEntity> contacts = const [], this.isLoading = false, this.isEditing = false, this.name = '', this.phone = '', this.errorMessage = ''}): _contacts = contacts;
|
||||
const _ContactsViewState({final List<ContactEntity> contacts = const [], this.isLoading = false, this.isComplete = false, this.isEditing = false, this.name = '', this.phone = '', this.dialCode = '+34', this.errorMessage = ''}): _contacts = contacts;
|
||||
|
||||
|
||||
final List<ContactEntity> _contacts;
|
||||
@@ -222,9 +224,11 @@ class _ContactsViewState implements ContactsViewState {
|
||||
}
|
||||
|
||||
@override@JsonKey() final bool isLoading;
|
||||
@override@JsonKey() final bool isComplete;
|
||||
@override@JsonKey() final bool isEditing;
|
||||
@override@JsonKey() final String name;
|
||||
@override@JsonKey() final String phone;
|
||||
@override@JsonKey() final String dialCode;
|
||||
@override@JsonKey() final String errorMessage;
|
||||
|
||||
/// Create a copy of ContactsViewState
|
||||
@@ -237,16 +241,16 @@ _$ContactsViewStateCopyWith<_ContactsViewState> get copyWith => __$ContactsViewS
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _ContactsViewState&&const DeepCollectionEquality().equals(other._contacts, _contacts)&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.isEditing, isEditing) || other.isEditing == isEditing)&&(identical(other.name, name) || other.name == name)&&(identical(other.phone, phone) || other.phone == phone)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _ContactsViewState&&const DeepCollectionEquality().equals(other._contacts, _contacts)&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.isComplete, isComplete) || other.isComplete == isComplete)&&(identical(other.isEditing, isEditing) || other.isEditing == isEditing)&&(identical(other.name, name) || other.name == name)&&(identical(other.phone, phone) || other.phone == phone)&&(identical(other.dialCode, dialCode) || other.dialCode == dialCode)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(_contacts),isLoading,isEditing,name,phone,errorMessage);
|
||||
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(_contacts),isLoading,isComplete,isEditing,name,phone,dialCode,errorMessage);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ContactsViewState(contacts: $contacts, isLoading: $isLoading, isEditing: $isEditing, name: $name, phone: $phone, errorMessage: $errorMessage)';
|
||||
return 'ContactsViewState(contacts: $contacts, isLoading: $isLoading, isComplete: $isComplete, isEditing: $isEditing, name: $name, phone: $phone, dialCode: $dialCode, errorMessage: $errorMessage)';
|
||||
}
|
||||
|
||||
|
||||
@@ -257,7 +261,7 @@ abstract mixin class _$ContactsViewStateCopyWith<$Res> implements $ContactsViewS
|
||||
factory _$ContactsViewStateCopyWith(_ContactsViewState value, $Res Function(_ContactsViewState) _then) = __$ContactsViewStateCopyWithImpl;
|
||||
@override @useResult
|
||||
$Res call({
|
||||
List<ContactEntity> contacts, bool isLoading, bool isEditing, String name, String phone, String errorMessage
|
||||
List<ContactEntity> contacts, bool isLoading, bool isComplete, bool isEditing, String name, String phone, String dialCode, String errorMessage
|
||||
});
|
||||
|
||||
|
||||
@@ -274,13 +278,15 @@ class __$ContactsViewStateCopyWithImpl<$Res>
|
||||
|
||||
/// Create a copy of ContactsViewState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? contacts = null,Object? isLoading = null,Object? isEditing = null,Object? name = null,Object? phone = null,Object? errorMessage = null,}) {
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? contacts = null,Object? isLoading = null,Object? isComplete = null,Object? isEditing = null,Object? name = null,Object? phone = null,Object? dialCode = null,Object? errorMessage = null,}) {
|
||||
return _then(_ContactsViewState(
|
||||
contacts: null == contacts ? _self._contacts : contacts // ignore: cast_nullable_to_non_nullable
|
||||
as List<ContactEntity>,isLoading: null == isLoading ? _self.isLoading : isLoading // ignore: cast_nullable_to_non_nullable
|
||||
as bool,isComplete: null == isComplete ? _self.isComplete : isComplete // ignore: cast_nullable_to_non_nullable
|
||||
as bool,isEditing: null == isEditing ? _self.isEditing : isEditing // ignore: cast_nullable_to_non_nullable
|
||||
as bool,name: null == name ? _self.name : name // ignore: cast_nullable_to_non_nullable
|
||||
as String,phone: null == phone ? _self.phone : phone // ignore: cast_nullable_to_non_nullable
|
||||
as String,dialCode: null == dialCode ? _self.dialCode : dialCode // ignore: cast_nullable_to_non_nullable
|
||||
as String,errorMessage: null == errorMessage ? _self.errorMessage : errorMessage // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
));
|
||||
|
||||
@@ -0,0 +1,81 @@
|
||||
import 'package:design_system/design_system.dart';
|
||||
import 'package:device_management/src/features/contacts/domain/entities/contact_entity.dart';
|
||||
import 'package:device_management/src/features/contacts/presentation/state/contacts_view_model.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:sf_localizations/sf_localizations.dart';
|
||||
import 'package:utils/utils.dart';
|
||||
|
||||
class ConfirmDeleteDialog extends ConsumerWidget {
|
||||
|
||||
final ContactEntity contact;
|
||||
|
||||
const ConfirmDeleteDialog({required this.contact});
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final theme = ref.read(themePortProvider);
|
||||
|
||||
final vm = ref.read(contactsViewModelProvider.notifier);
|
||||
|
||||
return Container(
|
||||
padding: SizeUtils.getByScreen(
|
||||
small: EdgeInsets.symmetric(horizontal: 32, vertical: 30),
|
||||
big: EdgeInsets.symmetric(horizontal: 30, vertical: 28)
|
||||
),
|
||||
width: SizeUtils.getByScreen(small: 360, big: 350),
|
||||
height: SizeUtils.getByScreen(small: 195, big: 185),
|
||||
child: Column(
|
||||
children: [
|
||||
Text(context.translate(I18n.deleteContactMessage),
|
||||
textAlign: TextAlign.center,
|
||||
style: TextStyle(fontSize: SizeUtils.getByScreen(small: 19, big: 18)),
|
||||
),
|
||||
SizedBox(height: SizeUtils.getByScreen(small: 28, big: 27)),
|
||||
Row(
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: [
|
||||
Expanded(child: PrimaryButton(
|
||||
onPressed: (){Navigator.pop(context);},
|
||||
text: context.translate(I18n.cancel),
|
||||
color: theme.getColorFor(ThemeCode.legacyPrimary),
|
||||
height: SizeUtils.getByScreen(small: 38, big: 36),
|
||||
radius: SizeUtils.getByScreen(small: 32, big: 34),
|
||||
)),
|
||||
SizedBox(width: SizeUtils.getByScreen(small: 4, big: 16)),
|
||||
Expanded(child: PrimaryButton(
|
||||
onPressed: () async {
|
||||
await vm.deleteContact(contact);
|
||||
|
||||
final errorMessage = ref.read(
|
||||
contactsViewModelProvider.select((s)=>s.errorMessage)
|
||||
);
|
||||
if (errorMessage.isNotEmpty) {
|
||||
showTopSnackbar(
|
||||
context,
|
||||
message: errorMessage,
|
||||
type: MessageType.error
|
||||
);
|
||||
}
|
||||
|
||||
final isComplete = ref.read(
|
||||
contactsViewModelProvider.select((s)=>s.isComplete)
|
||||
);
|
||||
if (isComplete) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
|
||||
},
|
||||
text: context.translate(I18n.delete),
|
||||
color: theme.getColorFor(ThemeCode.legacyPrimary),
|
||||
height: SizeUtils.getByScreen(small: 38, big: 36),
|
||||
radius: SizeUtils.getByScreen(small: 32, big: 34),
|
||||
))
|
||||
],
|
||||
)
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,115 @@
|
||||
import 'package:design_system/design_system.dart';
|
||||
import 'package:country_code_picker/country_code_picker.dart';
|
||||
import 'package:device_management/src/features/contacts/presentation/state/contacts_view_model.dart';
|
||||
import 'package:flutter/cupertino.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:flutter_svg/flutter_svg.dart';
|
||||
import 'package:sf_localizations/sf_localizations.dart';
|
||||
|
||||
class NewContactDialog extends ConsumerWidget {
|
||||
|
||||
const NewContactDialog();
|
||||
|
||||
@override
|
||||
Widget build(BuildContext context, WidgetRef ref) {
|
||||
final theme = ref.read(themePortProvider);
|
||||
|
||||
final vm = ref.read(contactsViewModelProvider.notifier);
|
||||
final state = ref.watch(contactsViewModelProvider);
|
||||
|
||||
return Container(
|
||||
padding: EdgeInsets.symmetric(horizontal: 10, vertical: 10),
|
||||
height: 430,
|
||||
width: 400,
|
||||
decoration: BoxDecoration(
|
||||
color: theme.getColorFor(ThemeCode.backgroundPrimary),
|
||||
borderRadius: BorderRadius.all(Radius.circular(6))
|
||||
),
|
||||
child: Column(
|
||||
children: [
|
||||
Stack(
|
||||
children: [
|
||||
Align(
|
||||
alignment: Alignment.topRight,
|
||||
child: IconButton(
|
||||
onPressed: (){Navigator.pop(context);},
|
||||
icon: Icon(Icons.close,
|
||||
color: theme.getColorFor(ThemeCode.legacyPrimary),
|
||||
),
|
||||
),
|
||||
),
|
||||
Center(
|
||||
child: Text(context.translate(I18n.newContact).toUpperCase(),
|
||||
style: TextStyle(
|
||||
color: theme.getColorFor(ThemeCode.legacyPrimary),
|
||||
fontWeight: FontWeight.w500
|
||||
),
|
||||
),
|
||||
)
|
||||
],
|
||||
),
|
||||
SizedBox(
|
||||
height: 120,
|
||||
child: SvgPicture.asset('assets/shared/images/profile.svg'),
|
||||
),
|
||||
SizedBox(height: 14),
|
||||
CustomTextField(
|
||||
hint: context.translate(I18n.name),
|
||||
controller: vm.nameController,
|
||||
),
|
||||
SizedBox(height: 14),
|
||||
Row(
|
||||
spacing: 10,
|
||||
children: [
|
||||
CountryPrefixPicker(
|
||||
headerText: context.translate(I18n.selectYourCountry),
|
||||
onChanged: (CountryCode value) {
|
||||
vm.updateDialCode(value.dialCode ?? state.dialCode);
|
||||
},
|
||||
),
|
||||
Expanded(
|
||||
child: CustomTextField(
|
||||
controller: vm.phoneController,
|
||||
hint: context.translate(I18n.phoneNumber),
|
||||
keyboardType: TextInputType.number,
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
SizedBox(height: 14),
|
||||
Padding(
|
||||
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 10),
|
||||
child: PrimaryButton(
|
||||
onPressed: () async {
|
||||
await vm.createContact();
|
||||
|
||||
final errorMessage = ref.read(
|
||||
contactsViewModelProvider.select((s)=>s.errorMessage)
|
||||
);
|
||||
if (errorMessage.isNotEmpty){
|
||||
showTopSnackbar(
|
||||
context,
|
||||
message: errorMessage,
|
||||
type: MessageType.error
|
||||
);
|
||||
return;
|
||||
}
|
||||
|
||||
final isComplete = ref.read(
|
||||
contactsViewModelProvider.select((s)=>s.isComplete)
|
||||
);
|
||||
if (isComplete) {
|
||||
Navigator.pop(context);
|
||||
}
|
||||
},
|
||||
text: context.translate(I18n.save),
|
||||
color: theme.getColorFor(ThemeCode.legacyPrimary)
|
||||
),
|
||||
),
|
||||
],
|
||||
),
|
||||
);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -548,5 +548,7 @@
|
||||
"male": "Male",
|
||||
"female": "Female",
|
||||
"ratherNotSay": "I'd rather not say",
|
||||
"personalDataMessage": "*This is the app user's personal data"
|
||||
"personalDataMessage": "*This is the app user's personal data",
|
||||
"newContact": "New contact",
|
||||
"deleteContactMessage": "Are you sure you want to delete this phone from the list?"
|
||||
}
|
||||
@@ -546,5 +546,7 @@
|
||||
"male": "Hombre",
|
||||
"female": "Mujer",
|
||||
"ratherNotSay": "Prefiero no decirlo",
|
||||
"personalDataMessage": "*Estos son los datos personales del usuario de la aplicación"
|
||||
"personalDataMessage": "*Estos son los datos personales del usuario de la aplicación",
|
||||
"newContact": "Nuevo contacto",
|
||||
"deleteContactMessage": "¿Estás seguro de que deseas eliminar este número de la lista?"
|
||||
}
|
||||
@@ -667,4 +667,6 @@ class I18n {
|
||||
static const String female = 'female';
|
||||
static const String ratherNotSay = 'ratherNotSay';
|
||||
static const String personalDataMessage = 'personalDataMessage';
|
||||
static const String newContact = 'newContact';
|
||||
static const String deleteContactMessage = 'deleteContactMessage';
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user