fix(contacts): use dynamic max limits from device capabilities
This commit is contained in:
@@ -7,7 +7,6 @@ import 'package:sf_localizations/sf_localizations.dart';
|
||||
import 'package:utils/utils.dart';
|
||||
|
||||
import 'state/contacts_view_model.dart';
|
||||
import 'state/contacts_view_state.dart';
|
||||
import 'widgets/contact_card.dart';
|
||||
import 'widgets/new_contact_dialog.dart';
|
||||
|
||||
@@ -60,7 +59,7 @@ class ContactsScreen extends ConsumerWidget {
|
||||
child: InkWell(
|
||||
customBorder: const CircleBorder(),
|
||||
onTap: () {
|
||||
if (state.contacts.length >= kContactsMaxLimit) {
|
||||
if (state.contacts.length >= state.maxContacts) {
|
||||
showTopSnackbar(
|
||||
context,
|
||||
message: context.translate(I18n.errorContactsMax),
|
||||
|
||||
@@ -24,8 +24,12 @@ class ContactsViewModel extends Notifier<ContactsViewState> {
|
||||
ContactsViewState build() {
|
||||
_contactsRepository = ref.read(contactsRepositoryProvider);
|
||||
_tracking = ref.read(sfTrackingProvider);
|
||||
|
||||
final capabilities = ref.read(selectedDeviceProvider).value?.capabilities;
|
||||
final maxContacts = capabilities?.contacts?.maxForType('white') ?? 10;
|
||||
|
||||
_load();
|
||||
return const ContactsViewState();
|
||||
return ContactsViewState(maxContacts: maxContacts);
|
||||
}
|
||||
|
||||
void toggleIsEditing() {
|
||||
|
||||
@@ -5,8 +5,6 @@ import '../../domain/entities/contact_error.dart';
|
||||
|
||||
part 'contacts_view_state.freezed.dart';
|
||||
|
||||
const int kContactsMaxLimit = 10;
|
||||
|
||||
@freezed
|
||||
abstract class ContactsViewState with _$ContactsViewState {
|
||||
const factory ContactsViewState({
|
||||
@@ -14,6 +12,7 @@ abstract class ContactsViewState with _$ContactsViewState {
|
||||
@Default(true) bool isLoading,
|
||||
@Default(false) bool isSubmitting,
|
||||
@Default(false) bool isEditing,
|
||||
@Default(10) int maxContacts,
|
||||
ContactError? error,
|
||||
}) = _ContactsViewState;
|
||||
}
|
||||
|
||||
@@ -14,7 +14,7 @@ T _$identity<T>(T value) => value;
|
||||
/// @nodoc
|
||||
mixin _$ContactsViewState {
|
||||
|
||||
List<ContactEntity> get contacts; bool get isLoading; bool get isSubmitting; bool get isEditing; ContactError? get error;
|
||||
List<ContactEntity> get contacts; bool get isLoading; bool get isSubmitting; bool get isEditing; int get maxContacts; ContactError? get error;
|
||||
/// 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.isSubmitting, isSubmitting) || other.isSubmitting == isSubmitting)&&(identical(other.isEditing, isEditing) || other.isEditing == isEditing)&&(identical(other.error, error) || other.error == error));
|
||||
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.isSubmitting, isSubmitting) || other.isSubmitting == isSubmitting)&&(identical(other.isEditing, isEditing) || other.isEditing == isEditing)&&(identical(other.maxContacts, maxContacts) || other.maxContacts == maxContacts)&&(identical(other.error, error) || other.error == error));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(contacts),isLoading,isSubmitting,isEditing,error);
|
||||
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(contacts),isLoading,isSubmitting,isEditing,maxContacts,error);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ContactsViewState(contacts: $contacts, isLoading: $isLoading, isSubmitting: $isSubmitting, isEditing: $isEditing, error: $error)';
|
||||
return 'ContactsViewState(contacts: $contacts, isLoading: $isLoading, isSubmitting: $isSubmitting, isEditing: $isEditing, maxContacts: $maxContacts, error: $error)';
|
||||
}
|
||||
|
||||
|
||||
@@ -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 isSubmitting, bool isEditing, ContactError? error
|
||||
List<ContactEntity> contacts, bool isLoading, bool isSubmitting, bool isEditing, int maxContacts, ContactError? error
|
||||
});
|
||||
|
||||
|
||||
@@ -62,13 +62,14 @@ 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? isSubmitting = null,Object? isEditing = null,Object? error = freezed,}) {
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? contacts = null,Object? isLoading = null,Object? isSubmitting = null,Object? isEditing = null,Object? maxContacts = null,Object? error = freezed,}) {
|
||||
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,isSubmitting: null == isSubmitting ? _self.isSubmitting : isSubmitting // ignore: cast_nullable_to_non_nullable
|
||||
as bool,isEditing: null == isEditing ? _self.isEditing : isEditing // ignore: cast_nullable_to_non_nullable
|
||||
as bool,error: freezed == error ? _self.error : error // ignore: cast_nullable_to_non_nullable
|
||||
as bool,maxContacts: null == maxContacts ? _self.maxContacts : maxContacts // ignore: cast_nullable_to_non_nullable
|
||||
as int,error: freezed == error ? _self.error : error // ignore: cast_nullable_to_non_nullable
|
||||
as ContactError?,
|
||||
));
|
||||
}
|
||||
@@ -154,10 +155,10 @@ return $default(_that);case _:
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( List<ContactEntity> contacts, bool isLoading, bool isSubmitting, bool isEditing, ContactError? error)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( List<ContactEntity> contacts, bool isLoading, bool isSubmitting, bool isEditing, int maxContacts, ContactError? error)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _ContactsViewState() when $default != null:
|
||||
return $default(_that.contacts,_that.isLoading,_that.isSubmitting,_that.isEditing,_that.error);case _:
|
||||
return $default(_that.contacts,_that.isLoading,_that.isSubmitting,_that.isEditing,_that.maxContacts,_that.error);case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
@@ -175,10 +176,10 @@ return $default(_that.contacts,_that.isLoading,_that.isSubmitting,_that.isEditin
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( List<ContactEntity> contacts, bool isLoading, bool isSubmitting, bool isEditing, ContactError? error) $default,) {final _that = this;
|
||||
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( List<ContactEntity> contacts, bool isLoading, bool isSubmitting, bool isEditing, int maxContacts, ContactError? error) $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _ContactsViewState():
|
||||
return $default(_that.contacts,_that.isLoading,_that.isSubmitting,_that.isEditing,_that.error);case _:
|
||||
return $default(_that.contacts,_that.isLoading,_that.isSubmitting,_that.isEditing,_that.maxContacts,_that.error);case _:
|
||||
throw StateError('Unexpected subclass');
|
||||
|
||||
}
|
||||
@@ -195,10 +196,10 @@ return $default(_that.contacts,_that.isLoading,_that.isSubmitting,_that.isEditin
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( List<ContactEntity> contacts, bool isLoading, bool isSubmitting, bool isEditing, ContactError? error)? $default,) {final _that = this;
|
||||
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( List<ContactEntity> contacts, bool isLoading, bool isSubmitting, bool isEditing, int maxContacts, ContactError? error)? $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _ContactsViewState() when $default != null:
|
||||
return $default(_that.contacts,_that.isLoading,_that.isSubmitting,_that.isEditing,_that.error);case _:
|
||||
return $default(_that.contacts,_that.isLoading,_that.isSubmitting,_that.isEditing,_that.maxContacts,_that.error);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
@@ -210,7 +211,7 @@ return $default(_that.contacts,_that.isLoading,_that.isSubmitting,_that.isEditin
|
||||
|
||||
|
||||
class _ContactsViewState implements ContactsViewState {
|
||||
const _ContactsViewState({final List<ContactEntity> contacts = const [], this.isLoading = true, this.isSubmitting = false, this.isEditing = false, this.error}): _contacts = contacts;
|
||||
const _ContactsViewState({final List<ContactEntity> contacts = const [], this.isLoading = true, this.isSubmitting = false, this.isEditing = false, this.maxContacts = 10, this.error}): _contacts = contacts;
|
||||
|
||||
|
||||
final List<ContactEntity> _contacts;
|
||||
@@ -223,6 +224,7 @@ class _ContactsViewState implements ContactsViewState {
|
||||
@override@JsonKey() final bool isLoading;
|
||||
@override@JsonKey() final bool isSubmitting;
|
||||
@override@JsonKey() final bool isEditing;
|
||||
@override@JsonKey() final int maxContacts;
|
||||
@override final ContactError? error;
|
||||
|
||||
/// Create a copy of ContactsViewState
|
||||
@@ -235,16 +237,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.isSubmitting, isSubmitting) || other.isSubmitting == isSubmitting)&&(identical(other.isEditing, isEditing) || other.isEditing == isEditing)&&(identical(other.error, error) || other.error == error));
|
||||
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.isSubmitting, isSubmitting) || other.isSubmitting == isSubmitting)&&(identical(other.isEditing, isEditing) || other.isEditing == isEditing)&&(identical(other.maxContacts, maxContacts) || other.maxContacts == maxContacts)&&(identical(other.error, error) || other.error == error));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(_contacts),isLoading,isSubmitting,isEditing,error);
|
||||
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(_contacts),isLoading,isSubmitting,isEditing,maxContacts,error);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'ContactsViewState(contacts: $contacts, isLoading: $isLoading, isSubmitting: $isSubmitting, isEditing: $isEditing, error: $error)';
|
||||
return 'ContactsViewState(contacts: $contacts, isLoading: $isLoading, isSubmitting: $isSubmitting, isEditing: $isEditing, maxContacts: $maxContacts, error: $error)';
|
||||
}
|
||||
|
||||
|
||||
@@ -255,7 +257,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 isSubmitting, bool isEditing, ContactError? error
|
||||
List<ContactEntity> contacts, bool isLoading, bool isSubmitting, bool isEditing, int maxContacts, ContactError? error
|
||||
});
|
||||
|
||||
|
||||
@@ -272,13 +274,14 @@ 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? isSubmitting = null,Object? isEditing = null,Object? error = freezed,}) {
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? contacts = null,Object? isLoading = null,Object? isSubmitting = null,Object? isEditing = null,Object? maxContacts = null,Object? error = freezed,}) {
|
||||
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,isSubmitting: null == isSubmitting ? _self.isSubmitting : isSubmitting // ignore: cast_nullable_to_non_nullable
|
||||
as bool,isEditing: null == isEditing ? _self.isEditing : isEditing // ignore: cast_nullable_to_non_nullable
|
||||
as bool,error: freezed == error ? _self.error : error // ignore: cast_nullable_to_non_nullable
|
||||
as bool,maxContacts: null == maxContacts ? _self.maxContacts : maxContacts // ignore: cast_nullable_to_non_nullable
|
||||
as int,error: freezed == error ? _self.error : error // ignore: cast_nullable_to_non_nullable
|
||||
as ContactError?,
|
||||
));
|
||||
}
|
||||
|
||||
@@ -11,7 +11,6 @@ import '../../../../core/domain/repositories/contacts_repository.dart';
|
||||
import '../../../../core/providers/contacts_repository_provider.dart';
|
||||
import '../../domain/entities/contact_error.dart';
|
||||
import 'contacts_view_model.dart';
|
||||
import 'contacts_view_state.dart';
|
||||
import 'new_contact_view_state.dart';
|
||||
|
||||
final newContactViewModelProvider =
|
||||
@@ -87,7 +86,7 @@ class NewContactViewModel extends Notifier<NewContactViewState> {
|
||||
if (state.isSubmitting) return false;
|
||||
|
||||
final listState = ref.read(contactsViewModelProvider);
|
||||
if (listState.contacts.length >= kContactsMaxLimit) {
|
||||
if (listState.contacts.length >= listState.maxContacts) {
|
||||
state = state.copyWith(error: ContactError.maxReached);
|
||||
return false;
|
||||
}
|
||||
|
||||
@@ -83,7 +83,17 @@ class SosContactsScreen extends ConsumerWidget {
|
||||
shape: BoxShape.circle,
|
||||
),
|
||||
child: IconButton(
|
||||
onPressed: () => showAddSosContactSheet(context),
|
||||
onPressed: () {
|
||||
if (state.contacts.length >= state.maxContacts) {
|
||||
showTopSnackbar(
|
||||
context,
|
||||
message: context.translate(I18n.errorSosContactsMax),
|
||||
type: MessageType.error,
|
||||
);
|
||||
return;
|
||||
}
|
||||
showAddSosContactSheet(context);
|
||||
},
|
||||
icon: Icon(
|
||||
Icons.add,
|
||||
color: Colors.white,
|
||||
|
||||
@@ -2,6 +2,7 @@ import 'dart:async';
|
||||
|
||||
import 'package:flutter_riverpod/flutter_riverpod.dart';
|
||||
import 'package:legacy_shared/legacy_shared.dart';
|
||||
import 'package:sf_shared/sf_shared.dart';
|
||||
import 'package:settings/src/core/domain/entities/contact_list_contact_entity.dart';
|
||||
import 'package:settings/src/core/domain/repositories/sos_contacts_repository.dart';
|
||||
import 'package:settings/src/core/providers/sos_contacts_repository_provider.dart';
|
||||
@@ -22,8 +23,12 @@ class SosContactsViewModel extends Notifier<SosContactsViewState> {
|
||||
SosContactsViewState build() {
|
||||
_repository = ref.read(sosContactsRepositoryProvider);
|
||||
_tracking = ref.read(sfTrackingProvider);
|
||||
|
||||
final capabilities = ref.read(selectedDeviceProvider).value?.capabilities;
|
||||
final maxContacts = capabilities?.contacts?.maxForType('emergency', fallback: 3) ?? 3;
|
||||
|
||||
Future.microtask(_load);
|
||||
return const SosContactsViewState();
|
||||
return SosContactsViewState(maxContacts: maxContacts);
|
||||
}
|
||||
|
||||
Future<void> _load() async {
|
||||
@@ -46,6 +51,7 @@ class SosContactsViewModel extends Notifier<SosContactsViewState> {
|
||||
}
|
||||
|
||||
Future<void> addContact(ContactListContactEntity contact) async {
|
||||
if (state.contacts.length >= state.maxContacts) return;
|
||||
state = state.copyWith(isSaving: true, errorMessage: '');
|
||||
|
||||
try {
|
||||
|
||||
@@ -9,6 +9,7 @@ abstract class SosContactsViewState with _$SosContactsViewState {
|
||||
@Default([]) List<ContactListContactEntity> contacts,
|
||||
@Default(true) bool isLoading,
|
||||
@Default(false) bool isSaving,
|
||||
@Default(3) int maxContacts,
|
||||
@Default('') String successMessage,
|
||||
@Default('') String errorMessage,
|
||||
}) = _SosContactsViewState;
|
||||
|
||||
@@ -14,7 +14,7 @@ T _$identity<T>(T value) => value;
|
||||
/// @nodoc
|
||||
mixin _$SosContactsViewState {
|
||||
|
||||
List<ContactListContactEntity> get contacts; bool get isLoading; bool get isSaving; String get successMessage; String get errorMessage;
|
||||
List<ContactListContactEntity> get contacts; bool get isLoading; bool get isSaving; int get maxContacts; String get successMessage; String get errorMessage;
|
||||
/// Create a copy of SosContactsViewState
|
||||
/// with the given fields replaced by the non-null parameter values.
|
||||
@JsonKey(includeFromJson: false, includeToJson: false)
|
||||
@@ -25,16 +25,16 @@ $SosContactsViewStateCopyWith<SosContactsViewState> get copyWith => _$SosContact
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is SosContactsViewState&&const DeepCollectionEquality().equals(other.contacts, contacts)&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.isSaving, isSaving) || other.isSaving == isSaving)&&(identical(other.successMessage, successMessage) || other.successMessage == successMessage)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is SosContactsViewState&&const DeepCollectionEquality().equals(other.contacts, contacts)&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.isSaving, isSaving) || other.isSaving == isSaving)&&(identical(other.maxContacts, maxContacts) || other.maxContacts == maxContacts)&&(identical(other.successMessage, successMessage) || other.successMessage == successMessage)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(contacts),isLoading,isSaving,successMessage,errorMessage);
|
||||
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(contacts),isLoading,isSaving,maxContacts,successMessage,errorMessage);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'SosContactsViewState(contacts: $contacts, isLoading: $isLoading, isSaving: $isSaving, successMessage: $successMessage, errorMessage: $errorMessage)';
|
||||
return 'SosContactsViewState(contacts: $contacts, isLoading: $isLoading, isSaving: $isSaving, maxContacts: $maxContacts, successMessage: $successMessage, errorMessage: $errorMessage)';
|
||||
}
|
||||
|
||||
|
||||
@@ -45,7 +45,7 @@ abstract mixin class $SosContactsViewStateCopyWith<$Res> {
|
||||
factory $SosContactsViewStateCopyWith(SosContactsViewState value, $Res Function(SosContactsViewState) _then) = _$SosContactsViewStateCopyWithImpl;
|
||||
@useResult
|
||||
$Res call({
|
||||
List<ContactListContactEntity> contacts, bool isLoading, bool isSaving, String successMessage, String errorMessage
|
||||
List<ContactListContactEntity> contacts, bool isLoading, bool isSaving, int maxContacts, String successMessage, String errorMessage
|
||||
});
|
||||
|
||||
|
||||
@@ -62,12 +62,13 @@ class _$SosContactsViewStateCopyWithImpl<$Res>
|
||||
|
||||
/// Create a copy of SosContactsViewState
|
||||
/// 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? isSaving = null,Object? successMessage = null,Object? errorMessage = null,}) {
|
||||
@pragma('vm:prefer-inline') @override $Res call({Object? contacts = null,Object? isLoading = null,Object? isSaving = null,Object? maxContacts = null,Object? successMessage = null,Object? errorMessage = null,}) {
|
||||
return _then(_self.copyWith(
|
||||
contacts: null == contacts ? _self.contacts : contacts // ignore: cast_nullable_to_non_nullable
|
||||
as List<ContactListContactEntity>,isLoading: null == isLoading ? _self.isLoading : isLoading // ignore: cast_nullable_to_non_nullable
|
||||
as bool,isSaving: null == isSaving ? _self.isSaving : isSaving // ignore: cast_nullable_to_non_nullable
|
||||
as bool,successMessage: null == successMessage ? _self.successMessage : successMessage // ignore: cast_nullable_to_non_nullable
|
||||
as bool,maxContacts: null == maxContacts ? _self.maxContacts : maxContacts // ignore: cast_nullable_to_non_nullable
|
||||
as int,successMessage: null == successMessage ? _self.successMessage : successMessage // ignore: cast_nullable_to_non_nullable
|
||||
as String,errorMessage: null == errorMessage ? _self.errorMessage : errorMessage // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
));
|
||||
@@ -154,10 +155,10 @@ return $default(_that);case _:
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( List<ContactListContactEntity> contacts, bool isLoading, bool isSaving, String successMessage, String errorMessage)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( List<ContactListContactEntity> contacts, bool isLoading, bool isSaving, int maxContacts, String successMessage, String errorMessage)? $default,{required TResult orElse(),}) {final _that = this;
|
||||
switch (_that) {
|
||||
case _SosContactsViewState() when $default != null:
|
||||
return $default(_that.contacts,_that.isLoading,_that.isSaving,_that.successMessage,_that.errorMessage);case _:
|
||||
return $default(_that.contacts,_that.isLoading,_that.isSaving,_that.maxContacts,_that.successMessage,_that.errorMessage);case _:
|
||||
return orElse();
|
||||
|
||||
}
|
||||
@@ -175,10 +176,10 @@ return $default(_that.contacts,_that.isLoading,_that.isSaving,_that.successMessa
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( List<ContactListContactEntity> contacts, bool isLoading, bool isSaving, String successMessage, String errorMessage) $default,) {final _that = this;
|
||||
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( List<ContactListContactEntity> contacts, bool isLoading, bool isSaving, int maxContacts, String successMessage, String errorMessage) $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _SosContactsViewState():
|
||||
return $default(_that.contacts,_that.isLoading,_that.isSaving,_that.successMessage,_that.errorMessage);case _:
|
||||
return $default(_that.contacts,_that.isLoading,_that.isSaving,_that.maxContacts,_that.successMessage,_that.errorMessage);case _:
|
||||
throw StateError('Unexpected subclass');
|
||||
|
||||
}
|
||||
@@ -195,10 +196,10 @@ return $default(_that.contacts,_that.isLoading,_that.isSaving,_that.successMessa
|
||||
/// }
|
||||
/// ```
|
||||
|
||||
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( List<ContactListContactEntity> contacts, bool isLoading, bool isSaving, String successMessage, String errorMessage)? $default,) {final _that = this;
|
||||
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( List<ContactListContactEntity> contacts, bool isLoading, bool isSaving, int maxContacts, String successMessage, String errorMessage)? $default,) {final _that = this;
|
||||
switch (_that) {
|
||||
case _SosContactsViewState() when $default != null:
|
||||
return $default(_that.contacts,_that.isLoading,_that.isSaving,_that.successMessage,_that.errorMessage);case _:
|
||||
return $default(_that.contacts,_that.isLoading,_that.isSaving,_that.maxContacts,_that.successMessage,_that.errorMessage);case _:
|
||||
return null;
|
||||
|
||||
}
|
||||
@@ -210,7 +211,7 @@ return $default(_that.contacts,_that.isLoading,_that.isSaving,_that.successMessa
|
||||
|
||||
|
||||
class _SosContactsViewState implements SosContactsViewState {
|
||||
const _SosContactsViewState({final List<ContactListContactEntity> contacts = const [], this.isLoading = true, this.isSaving = false, this.successMessage = '', this.errorMessage = ''}): _contacts = contacts;
|
||||
const _SosContactsViewState({final List<ContactListContactEntity> contacts = const [], this.isLoading = true, this.isSaving = false, this.maxContacts = 3, this.successMessage = '', this.errorMessage = ''}): _contacts = contacts;
|
||||
|
||||
|
||||
final List<ContactListContactEntity> _contacts;
|
||||
@@ -222,6 +223,7 @@ class _SosContactsViewState implements SosContactsViewState {
|
||||
|
||||
@override@JsonKey() final bool isLoading;
|
||||
@override@JsonKey() final bool isSaving;
|
||||
@override@JsonKey() final int maxContacts;
|
||||
@override@JsonKey() final String successMessage;
|
||||
@override@JsonKey() final String errorMessage;
|
||||
|
||||
@@ -235,16 +237,16 @@ _$SosContactsViewStateCopyWith<_SosContactsViewState> get copyWith => __$SosCont
|
||||
|
||||
@override
|
||||
bool operator ==(Object other) {
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _SosContactsViewState&&const DeepCollectionEquality().equals(other._contacts, _contacts)&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.isSaving, isSaving) || other.isSaving == isSaving)&&(identical(other.successMessage, successMessage) || other.successMessage == successMessage)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
|
||||
return identical(this, other) || (other.runtimeType == runtimeType&&other is _SosContactsViewState&&const DeepCollectionEquality().equals(other._contacts, _contacts)&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.isSaving, isSaving) || other.isSaving == isSaving)&&(identical(other.maxContacts, maxContacts) || other.maxContacts == maxContacts)&&(identical(other.successMessage, successMessage) || other.successMessage == successMessage)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
|
||||
}
|
||||
|
||||
|
||||
@override
|
||||
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(_contacts),isLoading,isSaving,successMessage,errorMessage);
|
||||
int get hashCode => Object.hash(runtimeType,const DeepCollectionEquality().hash(_contacts),isLoading,isSaving,maxContacts,successMessage,errorMessage);
|
||||
|
||||
@override
|
||||
String toString() {
|
||||
return 'SosContactsViewState(contacts: $contacts, isLoading: $isLoading, isSaving: $isSaving, successMessage: $successMessage, errorMessage: $errorMessage)';
|
||||
return 'SosContactsViewState(contacts: $contacts, isLoading: $isLoading, isSaving: $isSaving, maxContacts: $maxContacts, successMessage: $successMessage, errorMessage: $errorMessage)';
|
||||
}
|
||||
|
||||
|
||||
@@ -255,7 +257,7 @@ abstract mixin class _$SosContactsViewStateCopyWith<$Res> implements $SosContact
|
||||
factory _$SosContactsViewStateCopyWith(_SosContactsViewState value, $Res Function(_SosContactsViewState) _then) = __$SosContactsViewStateCopyWithImpl;
|
||||
@override @useResult
|
||||
$Res call({
|
||||
List<ContactListContactEntity> contacts, bool isLoading, bool isSaving, String successMessage, String errorMessage
|
||||
List<ContactListContactEntity> contacts, bool isLoading, bool isSaving, int maxContacts, String successMessage, String errorMessage
|
||||
});
|
||||
|
||||
|
||||
@@ -272,12 +274,13 @@ class __$SosContactsViewStateCopyWithImpl<$Res>
|
||||
|
||||
/// Create a copy of SosContactsViewState
|
||||
/// 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? isSaving = null,Object? successMessage = null,Object? errorMessage = null,}) {
|
||||
@override @pragma('vm:prefer-inline') $Res call({Object? contacts = null,Object? isLoading = null,Object? isSaving = null,Object? maxContacts = null,Object? successMessage = null,Object? errorMessage = null,}) {
|
||||
return _then(_SosContactsViewState(
|
||||
contacts: null == contacts ? _self._contacts : contacts // ignore: cast_nullable_to_non_nullable
|
||||
as List<ContactListContactEntity>,isLoading: null == isLoading ? _self.isLoading : isLoading // ignore: cast_nullable_to_non_nullable
|
||||
as bool,isSaving: null == isSaving ? _self.isSaving : isSaving // ignore: cast_nullable_to_non_nullable
|
||||
as bool,successMessage: null == successMessage ? _self.successMessage : successMessage // ignore: cast_nullable_to_non_nullable
|
||||
as bool,maxContacts: null == maxContacts ? _self.maxContacts : maxContacts // ignore: cast_nullable_to_non_nullable
|
||||
as int,successMessage: null == successMessage ? _self.successMessage : successMessage // ignore: cast_nullable_to_non_nullable
|
||||
as String,errorMessage: null == errorMessage ? _self.errorMessage : errorMessage // ignore: cast_nullable_to_non_nullable
|
||||
as String,
|
||||
));
|
||||
|
||||
Reference in New Issue
Block a user