Compare commits

...

4 Commits

Author SHA1 Message Date
b291b12865 fix change password criteria 2026-03-18 17:19:37 +01:00
a07246130e fix change password fields and validation 2026-03-18 13:21:16 +01:00
b4bb90d357 change password state fix and endpoint 2026-03-10 17:35:48 +01:00
5ee7852ee7 rewards ui, state and command 2026-03-10 16:08:33 +01:00
35 changed files with 967 additions and 239 deletions

View File

@@ -25,7 +25,7 @@ late final GoRouter appRouter;
void configureAppRouter() {
appRouter = GoRouter(
navigatorKey: rootNavigatorKey,
initialLocation: AppRoutes.legacyOnboarding,
initialLocation: AppRoutes.controlPanel,
debugLogDiagnostics: true,
routes: [
GoRoute(
@@ -108,6 +108,11 @@ void configureAppRouter() {
name: 'locate_device',
pageBuilder: LocateDeviceBuilder().buildPage,
),
GoRoute(
path: 'rewards',
name: 'rewards',
pageBuilder: RewardsBuilder().buildPage,
),
],
),
],

View File

@@ -1,4 +1,3 @@
import 'package:account/src/features/change_password/domain/models/entities/change_password_request_entity.dart';
import 'package:account/src/features/linked_devices/domain/entities/update_device_request_entity.dart';
import 'package:account/src/features/personal_data/domain/entities/update_user_request_entity.dart';
import 'package:sf_shared/sf_shared.dart';
@@ -15,6 +14,4 @@ abstract class AccountRemoteDatasource {
Future<List<UserEntity>> getAppUsers({required String userId});
Future<void> deleteAppUser({required String userId});
Future<void> changePassword({required String userId, required ChangePasswordRequestEntity request});
}

View File

@@ -1,11 +1,9 @@
import 'dart:convert';
import 'package:account/src/core/data/datasource/account_remote_datasource.dart';
import 'package:account/src/core/data/models/change_password_request_model.dart';
import 'package:account/src/core/data/models/get_app_users_response_model.dart';
import 'package:account/src/core/data/models/update_device_request_model.dart';
import 'package:account/src/core/data/models/update_user_request_model.dart';
import 'package:account/src/features/change_password/domain/models/entities/change_password_request_entity.dart';
import 'package:account/src/features/linked_devices/domain/entities/update_device_request_entity.dart';
import 'package:account/src/features/personal_data/domain/entities/update_user_request_entity.dart';
import 'package:dio/dio.dart';
@@ -142,19 +140,6 @@ class AccountRemoteDatasourceImpl implements AccountRemoteDatasource {
throw _mapDioError(error, defaultMessage: 'Error to delete device');
}
}
@override
Future<void> changePassword({required String userId, required ChangePasswordRequestEntity request}) async {
try {
final body = request.toModel().toJson();
await _repository.put<void>(
'/auth/change-password',
body: body,
);
} on DioException catch (error) {
throw _mapDioError(error, defaultMessage: 'Error to change password');
}
}
}
Exception _mapDioError(DioException error, {required String defaultMessage}) {

View File

@@ -0,0 +1,5 @@
import 'package:account/src/features/change_password/domain/models/entities/change_password_request_entity.dart';
abstract class ChangePasswordRemoteDatasource {
Future<void> changePassword({required String userId, required ChangePasswordRequestEntity request});
}

View File

@@ -0,0 +1,27 @@
import 'package:account/src/core/data/models/change_password_request_model.dart';
import 'package:dio/dio.dart';
import 'package:legacy_shared/legacy_shared.dart';
import 'package:sf_infrastructure/sf_infrastructure.dart';
import '../../../features/change_password/domain/models/entities/change_password_request_entity.dart';
import 'change_password_remote_datasource.dart';
class ChangePasswordRemoteDatasourceImpl implements ChangePasswordRemoteDatasource {
ChangePasswordRemoteDatasourceImpl(this._repository);
final QuestiaRepository _repository;
@override
Future<void> changePassword(
{required String userId, required ChangePasswordRequestEntity request}) async {
try {
final body = request.toModel().toJson();
await _repository.put<void>(
'/auth/change-password',
body: body,
);
} on DioException catch (error) {
throw mapDioError(error, defaultMessage: 'Error to change password');
}
}
}

View File

@@ -1,6 +1,5 @@
import 'package:account/src/core/data/datasource/account_remote_datasource.dart';
import 'package:account/src/core/domain/repositories/account_repository.dart';
import 'package:account/src/features/change_password/domain/models/entities/change_password_request_entity.dart';
import 'package:account/src/features/linked_devices/domain/entities/update_device_request_entity.dart';
import 'package:account/src/features/personal_data/domain/entities/update_user_request_entity.dart';
import 'package:sf_shared/sf_shared.dart';
@@ -39,9 +38,4 @@ class AccountRepositoryImpl implements AccountRepository {
Future<void> deleteAppUser({required String userId}) {
return _remote.deleteAppUser(userId: userId);
}
@override
Future<void> changePassword({required String userId, required ChangePasswordRequestEntity request}) {
return _remote.changePassword(userId: userId, request: request);
}
}

View File

@@ -0,0 +1,15 @@
import 'package:account/src/features/change_password/domain/models/entities/change_password_request_entity.dart';
import '../../domain/repositories/change_password_repository.dart';
import '../datasource/change_password_remote_datasource.dart';
class ChangePasswordRepositoryImpl implements ChangePasswordRepository {
const ChangePasswordRepositoryImpl(this._remote);
final ChangePasswordRemoteDatasource _remote;
@override
Future<void> changePassword({required String userId, required ChangePasswordRequestEntity request}) {
return _remote.changePassword(userId: userId, request: request);
}
}

View File

@@ -1,4 +1,3 @@
import 'package:account/src/features/change_password/domain/models/entities/change_password_request_entity.dart';
import 'package:account/src/features/linked_devices/domain/entities/update_device_request_entity.dart';
import 'package:account/src/features/personal_data/domain/entities/update_user_request_entity.dart';
import 'package:sf_shared/sf_shared.dart';
@@ -22,9 +21,4 @@ abstract class AccountRepository {
Future<List<UserEntity>> getAppUsers({required String userId});
Future<void> deleteAppUser({required String userId});
Future<void> changePassword({
required String userId,
required ChangePasswordRequestEntity request
});
}

View File

@@ -0,0 +1,8 @@
import 'package:account/src/features/change_password/domain/models/entities/change_password_request_entity.dart';
abstract class ChangePasswordRepository {
Future<void> changePassword({
required String userId,
required ChangePasswordRequestEntity request
});
}

View File

@@ -0,0 +1,10 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:sf_infrastructure/sf_infrastructure.dart';
import '../data/datasource/change_password_remote_datasource.dart';
import '../data/datasource/change_password_remote_datasource_impl.dart';
final changePasswordRemoteDatasourceProvider = Provider<ChangePasswordRemoteDatasource>((ref) {
final questiaRepository = getIt<QuestiaRepository>();
return ChangePasswordRemoteDatasourceImpl(questiaRepository);
});

View File

@@ -0,0 +1,10 @@
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../data/repositories/change_password_repository_impl.dart';
import '../domain/repositories/change_password_repository.dart';
import 'change_password_remote_datasource_provider.dart';
final changePasswordRepositoryProvider = Provider<ChangePasswordRepository>((ref) {
final remote = ref.read(changePasswordRemoteDatasourceProvider);
return ChangePasswordRepositoryImpl(remote);
});

View File

@@ -1,11 +1,11 @@
import 'package:account/src/core/domain/repositories/account_repository.dart';
import 'package:account/src/core/domain/repositories/change_password_repository.dart';
import 'package:account/src/features/change_password/domain/models/entities/change_password_request_entity.dart';
import 'package:account/src/features/change_password/domain/change_password_use_case.dart';
class ChangePasswordUseCaseImpl implements ChangePasswordUseCase {
ChangePasswordUseCaseImpl(this._repository);
final AccountRepository _repository;
final ChangePasswordRepository _repository;
@override
Future<void> changePassword({required String userId, required ChangePasswordRequestEntity request}) {

View File

@@ -14,13 +14,14 @@ class ChangePasswordScreen extends ConsumerWidget {
@override
Widget build(BuildContext context, WidgetRef ref) {
final vm = ref.read(changePasswordViewModelProvider.notifier);
final state = ref.watch(changePasswordViewModelProvider);
final theme = ref.watch(themePortProvider);
final password = ref.watch(
changePasswordViewModelProvider.select((s)=>s.newPassword)
);
return LegacyPageLayout(
theme: theme,
theme: theme,
title: context.translate(I18n.changePassword),
body: Container(
padding: SizeUtils.getByScreen(
@@ -30,45 +31,219 @@ theme: theme,
child: SingleChildScrollView(child: Column(
crossAxisAlignment: CrossAxisAlignment.center,
children: [
CustomTextField(
controller: vm.currentPasswordController,
hint: '********',
label: context.translate(I18n.password),
),
const _NewPasswordSection(),
SizedBox(height: SizeUtils.getByScreen(small: 24, big: 22)),
CustomTextField(
controller: vm.newPasswordController,
hint: '********',
label: context.translate(I18n.newPassword),
),
const _RepeatPasswordSection(),
SizedBox(height: SizeUtils.getByScreen(small: 24, big: 22)),
CustomTextField(
controller: vm.repeatPasswordController,
hint: '********',
label: context.translate(I18n.repeatPassword),
),
if (state.errorMessage.isNotEmpty) ...[
const SizedBox(height: 8),
Text(
state.errorMessage,
textAlign: TextAlign.center,
style: const TextStyle(
color: Color.fromRGBO(239, 17, 17, 1),
fontSize: 12,
),
),
],
_PasswordCriteriaList(password: password),
const _ErrorMessageSection()
],
))
),
footer: PrimaryButton(
footer: _SaveSection(navigationContract: navigationContract),
);
}
}
class _NewPasswordSection extends ConsumerWidget {
const _NewPasswordSection();
@override
Widget build(BuildContext context, WidgetRef ref) {
final vm = ref.read(changePasswordViewModelProvider.notifier);
final showPassword = ref.watch(
changePasswordViewModelProvider.select((s)=>s.showCurrentPassword)
);
return CustomTextField(
controller: vm.newPasswordController,
hint: '********',
label: context.translate(I18n.newPassword),
showPassword: showPassword,
onVisibilityChanged: vm.toggleNewPasswordVisibility,
);
}
}
class _RepeatPasswordSection extends ConsumerWidget {
const _RepeatPasswordSection();
@override
Widget build(BuildContext context, WidgetRef ref) {
final vm = ref.read(changePasswordViewModelProvider.notifier);
final showPassword = ref.watch(
changePasswordViewModelProvider.select((s)=>s.showCurrentPassword)
);
return CustomTextField(
controller: vm.repeatPasswordController,
hint: '********',
label: context.translate(I18n.repeatPassword),
showPassword: showPassword,
onVisibilityChanged: vm.toggleRepeatedPasswordVisibility,
);
}
}
class _PasswordCriteriaList extends StatelessWidget {
final String password;
const _PasswordCriteriaList({required this.password});
static final _upperRegex = RegExp(r'[A-Z]');
static final _digitRegex = RegExp(r'[0-9]');
static final _specialRegex =
RegExp(r'[!@#$%^&*(),.?":{}|<>\-_+=\[\]\\\/~`]');
@override
Widget build(BuildContext context) {
final hasInput = password.isNotEmpty;
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
spacing: 6,
children: [
_CriteriaRow(
label: context.translate(I18n.passwordLength),
met: password.length >= 8,
hasInput: hasInput,
),
_CriteriaRow(
label: context.translate(I18n.passwordCapital),
met: _upperRegex.hasMatch(password),
hasInput: hasInput,
),
_CriteriaRow(
label: context.translate(I18n.passwordNumber),
met: _digitRegex.hasMatch(password),
hasInput: hasInput,
),
_CriteriaRow(
label: context.translate(I18n.passwordSpecial),
met: _specialRegex.hasMatch(password),
hasInput: hasInput,
),
Text(context.translate((I18n.passwordRepeated)))
],
);
}
}
class _CriteriaRow extends StatelessWidget {
final String label;
final bool met;
final bool hasInput;
const _CriteriaRow({
required this.label,
required this.met,
required this.hasInput,
});
@override
Widget build(BuildContext context) {
final Color color;
final IconData icon;
if (!hasInput) {
color = Colors.grey;
icon = Icons.circle_outlined;
} else if (met) {
color = Colors.green;
icon = Icons.check_circle;
} else {
color = Colors.red.shade400;
icon = Icons.cancel;
}
return Row(
spacing: 8,
children: [
Icon(icon, size: 16, color: color),
Text(
label,
style: TextStyle(fontSize: 13, color: color),
),
],
);
}
}
class _ErrorMessageSection extends ConsumerWidget {
const _ErrorMessageSection();
@override
Widget build(BuildContext context, WidgetRef ref) {
final errorMessage = ref.watch(
changePasswordViewModelProvider.select((s)=>s.errorMessage)
);
if (errorMessage.isNotEmpty) {
return Column(
children: [
const SizedBox(height: 8),
Text(
errorMessage,
textAlign: TextAlign.center,
style: const TextStyle(
color: Color.fromRGBO(239, 17, 17, 1),
fontSize: 12,
),
),
],
);
} else {
return SizedBox.shrink();
}
}
}
class _SaveSection extends ConsumerWidget {
final NavigationContract navigationContract;
const _SaveSection({required this.navigationContract});
@override
Widget build(BuildContext context, WidgetRef ref) {
final theme = ref.read(themePortProvider);
final vm = ref.read(changePasswordViewModelProvider.notifier);
return Padding(
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 10),
child: PrimaryButton(
onPressed: () async {
final bool res = await vm.changePassword();
if (res){
navigationContract.goBack();
await vm.submit();
final errorMessage = ref.read(
changePasswordViewModelProvider.select((s)=>s.errorMessage)
);
if (errorMessage.isNotEmpty) {
showTopSnackbar(
context,
message: errorMessage,
type: MessageType.error
);
return;
}
final isComplete = ref.read(
changePasswordViewModelProvider.select((s)=>s.isComplete)
);
if (isComplete){
navigationContract.goTo(AppRoutes.legacyLogin);
}
},
text: context.translate('OK'),
text: context.translate(I18n.save),
color: theme.getColorFor(ThemeCode.legacyPrimary)
),
);

View File

@@ -1,9 +1,10 @@
import 'package:account/src/core/providers/account_repository_provider.dart';
import 'package:account/src/features/change_password/domain/change_password_use_case.dart';
import 'package:account/src/features/change_password/domain/change_password_use_case_impl.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import '../../../../core/providers/change_password_repository_provider.dart';
final changePasswordUseCaseProvider = Provider.autoDispose<ChangePasswordUseCase>((ref) {
final accountRepository = ref.read(accountRepositoryProvider);
return ChangePasswordUseCaseImpl(accountRepository);
final changePassword = ref.read(changePasswordRepositoryProvider);
return ChangePasswordUseCaseImpl(changePassword);
});

View File

@@ -4,11 +4,8 @@ import 'package:account/src/features/change_password/presentation/providers/chan
import 'package:account/src/features/change_password/presentation/state/change_password_view_state.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:legacy_shared/legacy_shared.dart';
import 'package:sf_shared/sf_shared.dart';
// import 'package:sf_localizations/sf_localizations.dart';
final changePasswordViewModelProvider =
NotifierProvider.autoDispose<ChangePasswordViewModel, ChangePasswordViewState>(
ChangePasswordViewModel.new,
@@ -17,7 +14,6 @@ NotifierProvider.autoDispose<ChangePasswordViewModel, ChangePasswordViewState>(
class ChangePasswordViewModel extends Notifier<ChangePasswordViewState> {
late final ChangePasswordUseCase _changePasswordUseCase;
late final TextEditingController currentPasswordController;
late final TextEditingController newPasswordController;
late final TextEditingController repeatPasswordController;
late final TextEditingController passwordController;
@@ -26,40 +22,36 @@ class ChangePasswordViewModel extends Notifier<ChangePasswordViewState> {
ChangePasswordViewState build() {
_changePasswordUseCase = ref.read(changePasswordUseCaseProvider);
currentPasswordController = TextEditingController();
currentPasswordController.addListener(_onCurrentPasswordChanged);
newPasswordController = TextEditingController();
newPasswordController.addListener(_onNewPasswordChanged);
repeatPasswordController = TextEditingController();
repeatPasswordController.addListener(_onRepeatPasswordController);
ref.onDispose(disposeControllers);
_init();
_initControllers();
return const ChangePasswordViewState();
}
Future<void> _init() async {
void _initControllers() {
newPasswordController = TextEditingController();
newPasswordController.addListener(_onNewPasswordChanged);
final user = await ref.read(userInfoProvider.future);
setUser(user);
repeatPasswordController = TextEditingController();
repeatPasswordController.addListener(_onRepeatPasswordChanged);
ref.onDispose(disposeControllers);
}
void setUser(UserEntity user) {
state = state.copyWith(loggedUser: user);
}
void _onCurrentPasswordChanged() {
final value = currentPasswordController.text;
if (value == state.currentPassword) return;
void toggleCurrentPasswordVisibility() {
state = state.copyWith(
currentPassword: value,
showCurrentPassword: !state.showCurrentPassword
);
}
void toggleNewPasswordVisibility() {
state = state.copyWith(
showNewPassword: !state.showNewPassword
);
}
void toggleRepeatedPasswordVisibility() {
state = state.copyWith(
showRepeatedPassword: !state.showRepeatedPassword
);
}
@@ -70,25 +62,30 @@ class ChangePasswordViewModel extends Notifier<ChangePasswordViewState> {
state = state.copyWith(
newPassword: value,
errorMessage: ''
);
}
void _onRepeatPasswordController() {
void _onRepeatPasswordChanged() {
final value = repeatPasswordController.text;
if (value == state.repeatPassword) return;
state = state.copyWith(
repeatPassword: value,
errorMessage: ''
);
}
bool _validateForm() {
if (state.currentPassword.trim().isEmpty){
state = state.copyWith(errorMessage: 'errorMessageCurrentPasswordIsEmpty');
return false;
}
if (state.newPassword.trim().isEmpty){
final _upperRegex = RegExp(r'[A-Z]');
final _digitRegex = RegExp(r'[0-9]');
final _specialRegex =
RegExp(r'[!@#$%^&*(),.?":{}|<>\-_+=\[\]\\\/~`]');
final password = state.newPassword.trim();
if (password.isEmpty){
state = state.copyWith(errorMessage: 'errorMessageNewPasswordIsEmpty');
return false;
}
@@ -96,10 +93,26 @@ class ChangePasswordViewModel extends Notifier<ChangePasswordViewState> {
state = state.copyWith(errorMessage: 'errorMessageRepeatPasswordIsEmpty');
return false;
}
if (state.newPassword.trim() != state.repeatPassword.trim()){
if (password != state.repeatPassword.trim()){
state = state.copyWith(errorMessage: 'errorMessagePasswordsDontMatch');
return false;
}
if (password.length < 8){
state = state.copyWith(errorMessage: 'errorPasswordMinLength');
return false;
}
if (!_upperRegex.hasMatch(password)) {
state = state.copyWith(errorMessage: 'errorPasswordUppercase');
return false;
}
if (!_digitRegex.hasMatch(password)) {
state = state.copyWith(errorMessage: 'errorPasswordDigits');
return false;
}
if (!_specialRegex.hasMatch(password)) {
state = state.copyWith(errorMessage: 'errorPasswordSpecial');
return false;
}
return true;
}
@@ -110,40 +123,46 @@ class ChangePasswordViewModel extends Notifier<ChangePasswordViewState> {
);
}
Future<bool> changePassword() async {
if (state.isLoading) return false;
if (!_validateForm()) return false;
Future<void> submit() async {
if (state.isLoading) return;
if (!_validateForm()) return;
try {
state = state.copyWith(
isLoading: true,
isComplete: false
);
final user = await ref.read(userInfoProvider.future);
final request = _toRequest();
await _changePasswordUseCase.changePassword(userId: state.loggedUser!.id, request: request);
await _changePasswordUseCase.changePassword(userId: user.id, request: request);
state = state.copyWith(
isLoading: false,
isComplete: true
);
ref.invalidate(userInfoProvider);
return true;
} catch (e) {
if (!ref.mounted) return false;
if (!ref.mounted) return;
_finishWithError(message: e.toString());
return false;
return;
}
}
void _finishWithError({required String message}) {
state = state.copyWith(
isLoading: false,
isComplete: false,
errorMessage: message,
);
}
void disposeControllers() {
currentPasswordController.removeListener(_onCurrentPasswordChanged);
currentPasswordController.dispose();
newPasswordController.removeListener(_onNewPasswordChanged);
newPasswordController.dispose();
repeatPasswordController.removeListener(_onRepeatPasswordController);
repeatPasswordController.removeListener(_onRepeatPasswordChanged);
repeatPasswordController.dispose();
}

View File

@@ -1,14 +1,14 @@
import 'package:freezed_annotation/freezed_annotation.dart';
import 'package:sf_shared/sf_shared.dart';
part 'change_password_view_state.freezed.dart';
@freezed
abstract class ChangePasswordViewState with _$ChangePasswordViewState {
const factory ChangePasswordViewState({
UserEntity? loggedUser,
@Default(false) bool isLoading,
@Default('') String currentPassword,
@Default(false) bool isComplete,
@Default(false) bool showNewPassword,
@Default(false) bool showRepeatedPassword,
@Default('') String newPassword,
@Default('') String repeatPassword,
@Default('') String errorMessage

View File

@@ -14,7 +14,7 @@ T _$identity<T>(T value) => value;
/// @nodoc
mixin _$ChangePasswordViewState {
UserEntity? get loggedUser; bool get isLoading; String get currentPassword; String get newPassword; String get repeatPassword; String get errorMessage;
bool get isLoading; bool get isComplete; bool get showCurrentPassword; bool get showNewPassword; bool get showRepeatedPassword; String get currentPassword; String get newPassword; String get repeatPassword; String get errorMessage;
/// Create a copy of ChangePasswordViewState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@@ -25,16 +25,16 @@ $ChangePasswordViewStateCopyWith<ChangePasswordViewState> get copyWith => _$Chan
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is ChangePasswordViewState&&(identical(other.loggedUser, loggedUser) || other.loggedUser == loggedUser)&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.currentPassword, currentPassword) || other.currentPassword == currentPassword)&&(identical(other.newPassword, newPassword) || other.newPassword == newPassword)&&(identical(other.repeatPassword, repeatPassword) || other.repeatPassword == repeatPassword)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
return identical(this, other) || (other.runtimeType == runtimeType&&other is ChangePasswordViewState&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.isComplete, isComplete) || other.isComplete == isComplete)&&(identical(other.showCurrentPassword, showCurrentPassword) || other.showCurrentPassword == showCurrentPassword)&&(identical(other.showNewPassword, showNewPassword) || other.showNewPassword == showNewPassword)&&(identical(other.showRepeatedPassword, showRepeatedPassword) || other.showRepeatedPassword == showRepeatedPassword)&&(identical(other.currentPassword, currentPassword) || other.currentPassword == currentPassword)&&(identical(other.newPassword, newPassword) || other.newPassword == newPassword)&&(identical(other.repeatPassword, repeatPassword) || other.repeatPassword == repeatPassword)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
}
@override
int get hashCode => Object.hash(runtimeType,loggedUser,isLoading,currentPassword,newPassword,repeatPassword,errorMessage);
int get hashCode => Object.hash(runtimeType,isLoading,isComplete,showCurrentPassword,showNewPassword,showRepeatedPassword,currentPassword,newPassword,repeatPassword,errorMessage);
@override
String toString() {
return 'ChangePasswordViewState(loggedUser: $loggedUser, isLoading: $isLoading, currentPassword: $currentPassword, newPassword: $newPassword, repeatPassword: $repeatPassword, errorMessage: $errorMessage)';
return 'ChangePasswordViewState(isLoading: $isLoading, isComplete: $isComplete, showCurrentPassword: $showCurrentPassword, showNewPassword: $showNewPassword, showRepeatedPassword: $showRepeatedPassword, currentPassword: $currentPassword, newPassword: $newPassword, repeatPassword: $repeatPassword, errorMessage: $errorMessage)';
}
@@ -45,11 +45,11 @@ abstract mixin class $ChangePasswordViewStateCopyWith<$Res> {
factory $ChangePasswordViewStateCopyWith(ChangePasswordViewState value, $Res Function(ChangePasswordViewState) _then) = _$ChangePasswordViewStateCopyWithImpl;
@useResult
$Res call({
UserEntity? loggedUser, bool isLoading, String currentPassword, String newPassword, String repeatPassword, String errorMessage
bool isLoading, bool isComplete, bool showCurrentPassword, bool showNewPassword, bool showRepeatedPassword, String currentPassword, String newPassword, String repeatPassword, String errorMessage
});
$UserEntityCopyWith<$Res>? get loggedUser;
}
/// @nodoc
@@ -62,10 +62,13 @@ class _$ChangePasswordViewStateCopyWithImpl<$Res>
/// Create a copy of ChangePasswordViewState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? loggedUser = freezed,Object? isLoading = null,Object? currentPassword = null,Object? newPassword = null,Object? repeatPassword = null,Object? errorMessage = null,}) {
@pragma('vm:prefer-inline') @override $Res call({Object? isLoading = null,Object? isComplete = null,Object? showCurrentPassword = null,Object? showNewPassword = null,Object? showRepeatedPassword = null,Object? currentPassword = null,Object? newPassword = null,Object? repeatPassword = null,Object? errorMessage = null,}) {
return _then(_self.copyWith(
loggedUser: freezed == loggedUser ? _self.loggedUser : loggedUser // ignore: cast_nullable_to_non_nullable
as UserEntity?,isLoading: null == isLoading ? _self.isLoading : isLoading // ignore: cast_nullable_to_non_nullable
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,showCurrentPassword: null == showCurrentPassword ? _self.showCurrentPassword : showCurrentPassword // ignore: cast_nullable_to_non_nullable
as bool,showNewPassword: null == showNewPassword ? _self.showNewPassword : showNewPassword // ignore: cast_nullable_to_non_nullable
as bool,showRepeatedPassword: null == showRepeatedPassword ? _self.showRepeatedPassword : showRepeatedPassword // ignore: cast_nullable_to_non_nullable
as bool,currentPassword: null == currentPassword ? _self.currentPassword : currentPassword // ignore: cast_nullable_to_non_nullable
as String,newPassword: null == newPassword ? _self.newPassword : newPassword // ignore: cast_nullable_to_non_nullable
as String,repeatPassword: null == repeatPassword ? _self.repeatPassword : repeatPassword // ignore: cast_nullable_to_non_nullable
@@ -73,19 +76,7 @@ as String,errorMessage: null == errorMessage ? _self.errorMessage : errorMessage
as String,
));
}
/// Create a copy of ChangePasswordViewState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$UserEntityCopyWith<$Res>? get loggedUser {
if (_self.loggedUser == null) {
return null;
}
return $UserEntityCopyWith<$Res>(_self.loggedUser!, (value) {
return _then(_self.copyWith(loggedUser: value));
});
}
}
@@ -167,10 +158,10 @@ return $default(_that);case _:
/// }
/// ```
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( UserEntity? loggedUser, bool isLoading, String currentPassword, String newPassword, String repeatPassword, String errorMessage)? $default,{required TResult orElse(),}) {final _that = this;
@optionalTypeArgs TResult maybeWhen<TResult extends Object?>(TResult Function( bool isLoading, bool isComplete, bool showCurrentPassword, bool showNewPassword, bool showRepeatedPassword, String currentPassword, String newPassword, String repeatPassword, String errorMessage)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _ChangePasswordViewState() when $default != null:
return $default(_that.loggedUser,_that.isLoading,_that.currentPassword,_that.newPassword,_that.repeatPassword,_that.errorMessage);case _:
return $default(_that.isLoading,_that.isComplete,_that.showCurrentPassword,_that.showNewPassword,_that.showRepeatedPassword,_that.currentPassword,_that.newPassword,_that.repeatPassword,_that.errorMessage);case _:
return orElse();
}
@@ -188,10 +179,10 @@ return $default(_that.loggedUser,_that.isLoading,_that.currentPassword,_that.new
/// }
/// ```
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( UserEntity? loggedUser, bool isLoading, String currentPassword, String newPassword, String repeatPassword, String errorMessage) $default,) {final _that = this;
@optionalTypeArgs TResult when<TResult extends Object?>(TResult Function( bool isLoading, bool isComplete, bool showCurrentPassword, bool showNewPassword, bool showRepeatedPassword, String currentPassword, String newPassword, String repeatPassword, String errorMessage) $default,) {final _that = this;
switch (_that) {
case _ChangePasswordViewState():
return $default(_that.loggedUser,_that.isLoading,_that.currentPassword,_that.newPassword,_that.repeatPassword,_that.errorMessage);case _:
return $default(_that.isLoading,_that.isComplete,_that.showCurrentPassword,_that.showNewPassword,_that.showRepeatedPassword,_that.currentPassword,_that.newPassword,_that.repeatPassword,_that.errorMessage);case _:
throw StateError('Unexpected subclass');
}
@@ -208,10 +199,10 @@ return $default(_that.loggedUser,_that.isLoading,_that.currentPassword,_that.new
/// }
/// ```
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( UserEntity? loggedUser, bool isLoading, String currentPassword, String newPassword, String repeatPassword, String errorMessage)? $default,) {final _that = this;
@optionalTypeArgs TResult? whenOrNull<TResult extends Object?>(TResult? Function( bool isLoading, bool isComplete, bool showCurrentPassword, bool showNewPassword, bool showRepeatedPassword, String currentPassword, String newPassword, String repeatPassword, String errorMessage)? $default,) {final _that = this;
switch (_that) {
case _ChangePasswordViewState() when $default != null:
return $default(_that.loggedUser,_that.isLoading,_that.currentPassword,_that.newPassword,_that.repeatPassword,_that.errorMessage);case _:
return $default(_that.isLoading,_that.isComplete,_that.showCurrentPassword,_that.showNewPassword,_that.showRepeatedPassword,_that.currentPassword,_that.newPassword,_that.repeatPassword,_that.errorMessage);case _:
return null;
}
@@ -223,11 +214,14 @@ return $default(_that.loggedUser,_that.isLoading,_that.currentPassword,_that.new
class _ChangePasswordViewState implements ChangePasswordViewState {
const _ChangePasswordViewState({this.loggedUser, this.isLoading = false, this.currentPassword = '', this.newPassword = '', this.repeatPassword = '', this.errorMessage = ''});
const _ChangePasswordViewState({this.isLoading = false, this.isComplete = false, this.showCurrentPassword = false, this.showNewPassword = false, this.showRepeatedPassword = false, this.currentPassword = '', this.newPassword = '', this.repeatPassword = '', this.errorMessage = ''});
@override final UserEntity? loggedUser;
@override@JsonKey() final bool isLoading;
@override@JsonKey() final bool isComplete;
@override@JsonKey() final bool showCurrentPassword;
@override@JsonKey() final bool showNewPassword;
@override@JsonKey() final bool showRepeatedPassword;
@override@JsonKey() final String currentPassword;
@override@JsonKey() final String newPassword;
@override@JsonKey() final String repeatPassword;
@@ -243,16 +237,16 @@ _$ChangePasswordViewStateCopyWith<_ChangePasswordViewState> get copyWith => __$C
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _ChangePasswordViewState&&(identical(other.loggedUser, loggedUser) || other.loggedUser == loggedUser)&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.currentPassword, currentPassword) || other.currentPassword == currentPassword)&&(identical(other.newPassword, newPassword) || other.newPassword == newPassword)&&(identical(other.repeatPassword, repeatPassword) || other.repeatPassword == repeatPassword)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
return identical(this, other) || (other.runtimeType == runtimeType&&other is _ChangePasswordViewState&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.isComplete, isComplete) || other.isComplete == isComplete)&&(identical(other.showCurrentPassword, showCurrentPassword) || other.showCurrentPassword == showCurrentPassword)&&(identical(other.showNewPassword, showNewPassword) || other.showNewPassword == showNewPassword)&&(identical(other.showRepeatedPassword, showRepeatedPassword) || other.showRepeatedPassword == showRepeatedPassword)&&(identical(other.currentPassword, currentPassword) || other.currentPassword == currentPassword)&&(identical(other.newPassword, newPassword) || other.newPassword == newPassword)&&(identical(other.repeatPassword, repeatPassword) || other.repeatPassword == repeatPassword)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
}
@override
int get hashCode => Object.hash(runtimeType,loggedUser,isLoading,currentPassword,newPassword,repeatPassword,errorMessage);
int get hashCode => Object.hash(runtimeType,isLoading,isComplete,showCurrentPassword,showNewPassword,showRepeatedPassword,currentPassword,newPassword,repeatPassword,errorMessage);
@override
String toString() {
return 'ChangePasswordViewState(loggedUser: $loggedUser, isLoading: $isLoading, currentPassword: $currentPassword, newPassword: $newPassword, repeatPassword: $repeatPassword, errorMessage: $errorMessage)';
return 'ChangePasswordViewState(isLoading: $isLoading, isComplete: $isComplete, showCurrentPassword: $showCurrentPassword, showNewPassword: $showNewPassword, showRepeatedPassword: $showRepeatedPassword, currentPassword: $currentPassword, newPassword: $newPassword, repeatPassword: $repeatPassword, errorMessage: $errorMessage)';
}
@@ -263,11 +257,11 @@ abstract mixin class _$ChangePasswordViewStateCopyWith<$Res> implements $ChangeP
factory _$ChangePasswordViewStateCopyWith(_ChangePasswordViewState value, $Res Function(_ChangePasswordViewState) _then) = __$ChangePasswordViewStateCopyWithImpl;
@override @useResult
$Res call({
UserEntity? loggedUser, bool isLoading, String currentPassword, String newPassword, String repeatPassword, String errorMessage
bool isLoading, bool isComplete, bool showCurrentPassword, bool showNewPassword, bool showRepeatedPassword, String currentPassword, String newPassword, String repeatPassword, String errorMessage
});
@override $UserEntityCopyWith<$Res>? get loggedUser;
}
/// @nodoc
@@ -280,10 +274,13 @@ class __$ChangePasswordViewStateCopyWithImpl<$Res>
/// Create a copy of ChangePasswordViewState
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? loggedUser = freezed,Object? isLoading = null,Object? currentPassword = null,Object? newPassword = null,Object? repeatPassword = null,Object? errorMessage = null,}) {
@override @pragma('vm:prefer-inline') $Res call({Object? isLoading = null,Object? isComplete = null,Object? showCurrentPassword = null,Object? showNewPassword = null,Object? showRepeatedPassword = null,Object? currentPassword = null,Object? newPassword = null,Object? repeatPassword = null,Object? errorMessage = null,}) {
return _then(_ChangePasswordViewState(
loggedUser: freezed == loggedUser ? _self.loggedUser : loggedUser // ignore: cast_nullable_to_non_nullable
as UserEntity?,isLoading: null == isLoading ? _self.isLoading : isLoading // ignore: cast_nullable_to_non_nullable
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,showCurrentPassword: null == showCurrentPassword ? _self.showCurrentPassword : showCurrentPassword // ignore: cast_nullable_to_non_nullable
as bool,showNewPassword: null == showNewPassword ? _self.showNewPassword : showNewPassword // ignore: cast_nullable_to_non_nullable
as bool,showRepeatedPassword: null == showRepeatedPassword ? _self.showRepeatedPassword : showRepeatedPassword // ignore: cast_nullable_to_non_nullable
as bool,currentPassword: null == currentPassword ? _self.currentPassword : currentPassword // ignore: cast_nullable_to_non_nullable
as String,newPassword: null == newPassword ? _self.newPassword : newPassword // ignore: cast_nullable_to_non_nullable
as String,repeatPassword: null == repeatPassword ? _self.repeatPassword : repeatPassword // ignore: cast_nullable_to_non_nullable
@@ -292,19 +289,7 @@ as String,
));
}
/// Create a copy of ChangePasswordViewState
/// with the given fields replaced by the non-null parameter values.
@override
@pragma('vm:prefer-inline')
$UserEntityCopyWith<$Res>? get loggedUser {
if (_self.loggedUser == null) {
return null;
}
return $UserEntityCopyWith<$Res>(_self.loggedUser!, (value) {
return _then(_self.copyWith(loggedUser: value));
});
}
}
// dart format on

View File

@@ -3,7 +3,6 @@ import 'package:dio/dio.dart';
import 'package:control_panel/src/core/data/models/get_devices_response_model.dart';
import 'package:control_panel/src/core/data/models/latest_positions_response_model.dart';
import 'package:control_panel/src/core/domain/entities/position_entity.dart';
import 'package:control_panel/src/core/utils/dio_error_mapper.dart';
import 'package:legacy_shared/legacy_shared.dart';
import 'package:sf_infrastructure/sf_infrastructure.dart';
import 'package:sf_shared/sf_shared.dart';

View File

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

View File

@@ -1,7 +1,6 @@
import 'package:control_panel/src/core/domain/entities/position_entity.dart';
import 'package:control_panel/src/core/domain/repositories/control_panel_repository.dart';
import 'package:control_panel/src/core/providers/control_panel_repository_provider.dart';
import 'package:control_panel/src/core/utils/dio_error_mapper.dart';
import 'package:control_panel/src/features/control_panel/presentation/state/control_panel_view_state.dart';
import 'package:legacy_shared/legacy_shared.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';

View File

@@ -4,3 +4,4 @@ export 'src/features/device_management/device_management_builder.dart';
export 'src/features/contacts/contacts_builder.dart';
export 'src/features/remote_connection/remote_connection_builder.dart';
export 'src/features/locate_device/locate_device_builder.dart';
export 'src/features/rewards/rewards_builder.dart';

View File

@@ -82,7 +82,7 @@ class DeviceManagementScreen extends ConsumerWidget {
SizedBox(height: SizeUtils.getByScreen(small: 16, big: 15)),
AppMenuButton(
color: theme.getColorFor(ThemeCode.legacyPrimary),
onPressed: (){},
onPressed: (){navigationContract.pushTo(AppRoutes.rewards);},
icon: SFIcons.rewardsCircle,
negativeIcon: true,
text: context.translate(I18n.rewards)

View File

@@ -0,0 +1,125 @@
import 'package:design_system/design_system.dart';
import 'package:device_management/src/features/rewards/presentation/state/rewards_view_model.dart';
import 'package:flutter/material.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:legacy_shared/legacy_shared.dart';
import 'package:navigation/navigation.dart';
import 'package:sf_localizations/sf_localizations.dart';
class RewardsScreen extends ConsumerWidget {
final NavigationContract navigationContract;
const RewardsScreen({super.key, required this.navigationContract});
@override
Widget build(BuildContext context, WidgetRef ref) {
final theme = ref.read(themePortProvider);
return LegacyPageLayout(
theme: theme,
title: context.translate(I18n.rewards),
body: Column(
children: [
Center(
child: Icon(SFIcons.rewardsCircle,
size: 180,
color: theme.getColorFor(ThemeCode.legacyPrimary),
)
),
SizedBox(height: 32),
Text(
context.translate(I18n.rewardsMessage),
textAlign: TextAlign.start,
),
SizedBox(height: 12),
const _CounterSection(),
],
),
footer: _SaveSection(),
);
}
}
class _CounterSection extends ConsumerWidget {
const _CounterSection();
@override
Widget build(BuildContext context, WidgetRef ref) {
final theme = ref.read(themePortProvider);
final state = ref.watch(rewardsViewModelProvider);
final vm = ref.read(rewardsViewModelProvider.notifier);
return Row(
mainAxisAlignment: MainAxisAlignment.center,
children: [
IconButton(
onPressed: vm.decreaseAmount,
icon: Icon(Icons.remove),
color: theme.getColorFor(ThemeCode.legacyPrimary),
),
SizedBox(
width: 240,
child: TextField(
controller: vm.amountController,
decoration: InputDecoration(
border: OutlineInputBorder(
borderSide: BorderSide(
color: theme.getColorFor(ThemeCode.legacyPrimary),
),
borderRadius: BorderRadius.all(Radius.circular(32)),
),
),
style: TextStyle(color: theme.getColorFor(ThemeCode.legacyPrimary)),
textAlign: TextAlign.center,
keyboardType: TextInputType.number,
)
),
IconButton(
onPressed: vm.increaseAmount,
icon: Icon(Icons.add),
color: theme.getColorFor(ThemeCode.legacyPrimary),
),
],
);
}
}
class _SaveSection extends ConsumerWidget{
const _SaveSection();
@override
Widget build(BuildContext context, WidgetRef ref) {
final theme = ref.read(themePortProvider);
final vm = ref.read(rewardsViewModelProvider.notifier);
return Padding(
padding: EdgeInsets.symmetric(horizontal: 24, vertical: 10),
child: PrimaryButton(
onPressed: () async {
await vm.submit();
final errorMessage = ref.read(
rewardsViewModelProvider.select((s)=>s.errorMessage)
);
if (errorMessage.isNotEmpty) {
showTopSnackbar(
context,
message: errorMessage,
type: MessageType.error,
);
}
},
text: context.translate(I18n.sendRewards),
color: theme.getColorFor(ThemeCode.legacyPrimary)
)
);
}
}

View File

@@ -0,0 +1,109 @@
import 'package:flutter/cupertino.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:legacy_shared/legacy_shared.dart';
import 'rewards_view_state.dart';
final rewardsViewModelProvider =
NotifierProvider.autoDispose<RewardsViewModel, RewardsViewState>(
RewardsViewModel.new,
);
class RewardsViewModel extends Notifier<RewardsViewState> {
static final _min = 1;
late final TextEditingController amountController;
late final SendCommandUseCase _sendCommandUseCase;
@override
RewardsViewState build() {
_sendCommandUseCase = ref.read(sendCommandUseCaseProvider);
amountController = TextEditingController();
amountController.addListener(_onAmountChanged);
amountController.text = '1';
ref.onDispose(disposeControllers);
return const RewardsViewState();
}
void _onAmountChanged() {
final raw = amountController.text;
if (raw.isEmpty) return;
final amount = int.tryParse(raw);
if (amount == null) return;
if (amount == state.amount) return;
if (amount < _min) return;
state = state.copyWith(
amount: amount,
errorMessage: '',
);
}
void increaseAmount() {
final amount = state.amount + 1;
state = state.copyWith(
amount: amount,
errorMessage: '',
);
amountController.text = amount.toString();
}
void decreaseAmount() {
if (state.amount == _min) return;
final amount = state.amount - 1;
state = state.copyWith(
amount: amount,
errorMessage: '',
);
amountController.text = amount.toString();
}
Future<void> submit() async {
try {
state = state.copyWith(
isLoading: true,
isComplete: false,
);
final device = ref.read(selectedDeviceProvider);
final request = SendCommandRequestModel(
device: device!.identificator.toString(),
command: 'REWARDS',
data: {
'rewards': state.amount
}
);
await _sendCommandUseCase.send(request: request);
state = state.copyWith(
isLoading: false,
isComplete: true
);
} catch(e) {
state = state.copyWith(
errorMessage: e.toString(),
isLoading: false,
isComplete: false
);
}
}
void disposeControllers() {
amountController.removeListener(_onAmountChanged);
amountController.dispose();
}
}

View File

@@ -0,0 +1,15 @@
import 'package:freezed_annotation/freezed_annotation.dart';
part 'rewards_view_state.freezed.dart';
@freezed
abstract class RewardsViewState with _$RewardsViewState {
const factory RewardsViewState({
@Default(1) int amount,
@Default(false) bool isLoading,
@Default(false) bool isComplete,
@Default('') String errorMessage,
}) = _RewardsViewState;
}

View File

@@ -0,0 +1,280 @@
// 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 'rewards_view_state.dart';
// **************************************************************************
// FreezedGenerator
// **************************************************************************
// dart format off
T _$identity<T>(T value) => value;
/// @nodoc
mixin _$RewardsViewState {
int get amount; bool get isLoading; bool get isComplete; String get errorMessage;
/// Create a copy of RewardsViewState
/// with the given fields replaced by the non-null parameter values.
@JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
$RewardsViewStateCopyWith<RewardsViewState> get copyWith => _$RewardsViewStateCopyWithImpl<RewardsViewState>(this as RewardsViewState, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is RewardsViewState&&(identical(other.amount, amount) || other.amount == amount)&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.isComplete, isComplete) || other.isComplete == isComplete)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
}
@override
int get hashCode => Object.hash(runtimeType,amount,isLoading,isComplete,errorMessage);
@override
String toString() {
return 'RewardsViewState(amount: $amount, isLoading: $isLoading, isComplete: $isComplete, errorMessage: $errorMessage)';
}
}
/// @nodoc
abstract mixin class $RewardsViewStateCopyWith<$Res> {
factory $RewardsViewStateCopyWith(RewardsViewState value, $Res Function(RewardsViewState) _then) = _$RewardsViewStateCopyWithImpl;
@useResult
$Res call({
int amount, bool isLoading, bool isComplete, String errorMessage
});
}
/// @nodoc
class _$RewardsViewStateCopyWithImpl<$Res>
implements $RewardsViewStateCopyWith<$Res> {
_$RewardsViewStateCopyWithImpl(this._self, this._then);
final RewardsViewState _self;
final $Res Function(RewardsViewState) _then;
/// Create a copy of RewardsViewState
/// with the given fields replaced by the non-null parameter values.
@pragma('vm:prefer-inline') @override $Res call({Object? amount = null,Object? isLoading = null,Object? isComplete = null,Object? errorMessage = null,}) {
return _then(_self.copyWith(
amount: null == amount ? _self.amount : amount // ignore: cast_nullable_to_non_nullable
as int,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,errorMessage: null == errorMessage ? _self.errorMessage : errorMessage // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
/// Adds pattern-matching-related methods to [RewardsViewState].
extension RewardsViewStatePatterns on RewardsViewState {
/// 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( _RewardsViewState value)? $default,{required TResult orElse(),}){
final _that = this;
switch (_that) {
case _RewardsViewState() 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( _RewardsViewState value) $default,){
final _that = this;
switch (_that) {
case _RewardsViewState():
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( _RewardsViewState value)? $default,){
final _that = this;
switch (_that) {
case _RewardsViewState() 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( int amount, bool isLoading, bool isComplete, String errorMessage)? $default,{required TResult orElse(),}) {final _that = this;
switch (_that) {
case _RewardsViewState() when $default != null:
return $default(_that.amount,_that.isLoading,_that.isComplete,_that.errorMessage);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( int amount, bool isLoading, bool isComplete, String errorMessage) $default,) {final _that = this;
switch (_that) {
case _RewardsViewState():
return $default(_that.amount,_that.isLoading,_that.isComplete,_that.errorMessage);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( int amount, bool isLoading, bool isComplete, String errorMessage)? $default,) {final _that = this;
switch (_that) {
case _RewardsViewState() when $default != null:
return $default(_that.amount,_that.isLoading,_that.isComplete,_that.errorMessage);case _:
return null;
}
}
}
/// @nodoc
class _RewardsViewState implements RewardsViewState {
const _RewardsViewState({this.amount = 1, this.isLoading = false, this.isComplete = false, this.errorMessage = ''});
@override@JsonKey() final int amount;
@override@JsonKey() final bool isLoading;
@override@JsonKey() final bool isComplete;
@override@JsonKey() final String errorMessage;
/// Create a copy of RewardsViewState
/// with the given fields replaced by the non-null parameter values.
@override @JsonKey(includeFromJson: false, includeToJson: false)
@pragma('vm:prefer-inline')
_$RewardsViewStateCopyWith<_RewardsViewState> get copyWith => __$RewardsViewStateCopyWithImpl<_RewardsViewState>(this, _$identity);
@override
bool operator ==(Object other) {
return identical(this, other) || (other.runtimeType == runtimeType&&other is _RewardsViewState&&(identical(other.amount, amount) || other.amount == amount)&&(identical(other.isLoading, isLoading) || other.isLoading == isLoading)&&(identical(other.isComplete, isComplete) || other.isComplete == isComplete)&&(identical(other.errorMessage, errorMessage) || other.errorMessage == errorMessage));
}
@override
int get hashCode => Object.hash(runtimeType,amount,isLoading,isComplete,errorMessage);
@override
String toString() {
return 'RewardsViewState(amount: $amount, isLoading: $isLoading, isComplete: $isComplete, errorMessage: $errorMessage)';
}
}
/// @nodoc
abstract mixin class _$RewardsViewStateCopyWith<$Res> implements $RewardsViewStateCopyWith<$Res> {
factory _$RewardsViewStateCopyWith(_RewardsViewState value, $Res Function(_RewardsViewState) _then) = __$RewardsViewStateCopyWithImpl;
@override @useResult
$Res call({
int amount, bool isLoading, bool isComplete, String errorMessage
});
}
/// @nodoc
class __$RewardsViewStateCopyWithImpl<$Res>
implements _$RewardsViewStateCopyWith<$Res> {
__$RewardsViewStateCopyWithImpl(this._self, this._then);
final _RewardsViewState _self;
final $Res Function(_RewardsViewState) _then;
/// Create a copy of RewardsViewState
/// with the given fields replaced by the non-null parameter values.
@override @pragma('vm:prefer-inline') $Res call({Object? amount = null,Object? isLoading = null,Object? isComplete = null,Object? errorMessage = null,}) {
return _then(_RewardsViewState(
amount: null == amount ? _self.amount : amount // ignore: cast_nullable_to_non_nullable
as int,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,errorMessage: null == errorMessage ? _self.errorMessage : errorMessage // ignore: cast_nullable_to_non_nullable
as String,
));
}
}
// dart format on

View File

@@ -0,0 +1,18 @@
import 'package:device_management/src/features/rewards/presentation/rewards_screen.dart';
import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:get_it/get_it.dart';
import 'package:navigation/navigation.dart';
class RewardsBuilder {
const RewardsBuilder();
Page<void> buildPage(BuildContext context, GoRouterState state) {
final NavigationContract navigationContract = GetIt.I<NavigationContract>();
return MaterialPage<void>(
key: state.pageKey,
child: RewardsScreen(navigationContract: navigationContract),
);
}
}

View File

@@ -7,4 +7,5 @@ export 'src/components/menu_button.dart';
export 'src/data/models/device_response_model.dart';
export 'src/providers/send_command_use_case_provider.dart';
export 'src/domain/send_command_use_case.dart';
export 'src/data/models/send_command_request_model.dart';
export 'src/data/models/send_command_request_model.dart';
export 'src/utils/dio_error_mapper.dart';

View File

@@ -7,6 +7,6 @@
<versions>
<version>2.6.4</version>
</versions>
<lastUpdated>20260309000000</lastUpdated>
<lastUpdated>20260310000000</lastUpdated>
</versioning>
</metadata>

View File

@@ -1 +1 @@
efba28f7c4340264bc1e42e5d11102a8
4d748a03a80705124d1ffe8143732218

View File

@@ -1 +1 @@
33fe0a028f582b89ab719f8dafc0490e05af4ff5
626b5ba9e1320d252d7286b888d11b14552a2a38

View File

@@ -50,6 +50,7 @@ class AppRoutes {
static const contacts = '$deviceManagement/contacts';
static const remoteConnection = '$deviceManagement/remote_connection';
static const locateDevice = '$deviceManagement/locate_device';
static const rewards = '$deviceManagement/rewards';
static const legacyLogin = '$legacy/login';
static const legacySignup = '$legacy/signup';

View File

@@ -489,7 +489,6 @@
"deleteAccount": "Delete account",
"logOut": "Log out",
"loginEmail": "(Login email)",
"loginSuccess": "Login successful",
"userNameLabel": "User name",
"userPhoneLabel": "User phone number",
"contactEmailLabel": "Contact email",
@@ -498,7 +497,6 @@
"editDeviceTitle": "Edit Device",
"name": "Name",
"deleteDeviceDialog": "Are you sure you want to delete this device from the list?",
"cancel": "Cancel",
"delete": "Delete",
"userAccount": "Account: {email}",
"userRole": "Role: {role}",
@@ -544,5 +542,8 @@
"deviceSetup_weightHint": "30",
"deviceSetup_heightLabel": "Height (cm)",
"deviceSetup_heightHint": "120",
"activationKeyLabel": "Activation key"
"activationKeyLabel": "Activation key",
"rewardsMessage": "Send rewards",
"sendRewards": "Send rewards!",
"passwordRepeated": "The new password can't have been used before"
}

View File

@@ -540,5 +540,8 @@
"deviceSetup_weightHint": "30",
"deviceSetup_heightLabel": "Altura (cm)",
"deviceSetup_heightHint": "120",
"activationKeyLabel": "Clave de activación"
"activationKeyLabel": "Clave de activación",
"rewardsMessage": "Envía una recompensa",
"sendRewards": "¡Enviar recompensas!",
"passwordRepeated": "La nueva contraseña no puede haber sido usada antes."
}

View File

@@ -661,4 +661,7 @@ class I18n {
static const String deviceSetup_heightLabel = 'deviceSetup_heightLabel';
static const String deviceSetup_heightHint = 'deviceSetup_heightHint';
static const String activationKeyLabel = 'activationKeyLabel';
static const String rewardsMessage = 'rewardsMessage';
static const String sendRewards = 'sendRewards';
static const String passwordRepeated = 'passwordRepeated';
}