fix: atualiza o getDados ao entrar na tela de opções e refatora o processData do LocalsRemoteDataSource para somente processar a propriedade (Single Responsability) (antes o proprio método chamava para atualizar licença). E como isso precisei fazer com que ele retorna-se true e que chama processa propriedade caso retorne true chame processa licença

This commit is contained in:
J. A. Messias 2024-12-20 11:46:04 -03:00
parent cbb2dd59fc
commit 66302358b9
7 changed files with 43 additions and 13 deletions

View File

@ -124,8 +124,8 @@ class _AboutSystemPageState extends State<AboutSystemPage> {
Widget _buildLogo() { Widget _buildLogo() {
return SizedBox( return SizedBox(
height: 50, height: 100,
width: 50, width: 100,
child: Image.asset('assets/images/fre.png'), child: Image.asset('assets/images/fre.png'),
); );
} }

View File

@ -18,7 +18,7 @@ abstract class LocalsRemoteDataSource {
Future<void> linkLocal(BuildContext context); Future<void> linkLocal(BuildContext context);
Future<bool> checkLocals(BuildContext context); Future<bool> checkLocals(BuildContext context);
Future<bool> processLocals(BuildContext context); Future<bool> processLocals(BuildContext context);
Future<bool> processData(BuildContext context); Future<bool> processProperty(BuildContext context);
Future<bool> selectLocal(BuildContext context, ApiCallResponse? response); Future<bool> selectLocal(BuildContext context, ApiCallResponse? response);
Future<bool> detachLocal(BuildContext context); Future<bool> detachLocal(BuildContext context);
} }
@ -118,10 +118,16 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
return await selectLocal(context, response); return await selectLocal(context, response);
} else if (isSelected) { } else if (isSelected) {
log('() => isSelected'); log('() => isSelected');
return await processData(context); return await processProperty(context).then((v) async {
if (v == true) return await LicenseRepositoryImpl().updateLicense();
return v;
});
} else if (isAvailable) { } else if (isAvailable) {
log('() => isAvailable'); log('() => isAvailable');
return await processData(context); return await processProperty(context).then((v) async {
if (v == true) return await LicenseRepositoryImpl().updateLicense();
return v;
});
} else { } else {
if (!isUnique && !isActive) log('() => not unique and not active'); if (!isUnique && !isActive) log('() => not unique and not active');
if (!isUnique && isInactived) log('() => not unique and inactived'); if (!isUnique && isInactived) log('() => not unique and inactived');
@ -153,7 +159,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
} }
@override @override
Future<bool> processData(BuildContext context) async { Future<bool> processProperty(BuildContext context) async {
try { try {
final GetDadosCall callback = PhpGroup.getDadosCall; final GetDadosCall callback = PhpGroup.getDadosCall;
ApiCallResponse? response = await callback.call(); ApiCallResponse? response = await callback.call();
@ -178,7 +184,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
return false; return false;
} else { } else {
await LocalUtil.updateStorageUtil(response.jsonBody); await LocalUtil.updateStorageUtil(response.jsonBody);
return await LicenseRepositoryImpl().updateLicense(); return true;
} }
} catch (e, s) { } catch (e, s) {
log('() => error processData: $e', stackTrace: s); log('() => error processData: $e', stackTrace: s);
@ -209,7 +215,10 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
child: BottomArrowLinkedLocalsComponentWidget(response: response), child: BottomArrowLinkedLocalsComponentWidget(response: response),
), ),
), ),
).then((_) async => await processData(context)); ).then((_) async => await processProperty(context).then((v) async {
if (v == true) return await LicenseRepositoryImpl().updateLicense();
return v;
}));
} }
@override @override

View File

@ -27,11 +27,16 @@ class LocalsRepositoryImpl implements LocalsRepository {
@override @override
Future<bool> update(BuildContext context) async { Future<bool> update(BuildContext context) async {
LocalsRepositoryImpl.license.add(false); LocalsRepositoryImpl.license.add(false);
final bool response = await _handleReponse(context); final bool response = await _handleLocal(context);
LocalsRepositoryImpl.license.add(response); LocalsRepositoryImpl.license.add(response);
return response; return response;
} }
@override
Future<bool> fetch(BuildContext context) async {
return await _handleProperty(context);
}
Future<void> select(BuildContext context) async { Future<void> select(BuildContext context) async {
await unselect(); await unselect();
await update(context); await update(context);
@ -56,7 +61,7 @@ class LocalsRepositoryImpl implements LocalsRepository {
} }
} }
Future<bool> _handleReponse(BuildContext context) async { Future<bool> _handleLocal(BuildContext context) async {
bool response = false; bool response = false;
final bool isUnselected = await remoteDataSource.checkLocals(context); final bool isUnselected = await remoteDataSource.checkLocals(context);
if (isUnselected) { if (isUnselected) {
@ -74,6 +79,21 @@ class LocalsRepositoryImpl implements LocalsRepository {
} else { } else {
return true; return true;
} }
return response;
}
Future<bool> _handleProperty(BuildContext context) async {
bool response = false;
try {
response = await remoteDataSource.processProperty(context);
if (!response) {
await _handleUpdateError(context);
}
} catch (e, s) {
log('Error updating locals: $e', stackTrace: s);
await _handleUpdateError(context);
}
return response; return response;
} }

View File

@ -4,4 +4,5 @@ abstract class LocalsRepository {
Future<void> validateLocal(BuildContext context) async {} Future<void> validateLocal(BuildContext context) async {}
Future<bool> update(BuildContext context) async => false; Future<bool> update(BuildContext context) async => false;
Future<void> unlinkLocal(BuildContext context) async {} Future<void> unlinkLocal(BuildContext context) async {}
Future<void> fetch(BuildContext context) async {}
} }

View File

@ -63,7 +63,7 @@ class LocalUtil {
} }
if (response.jsonBody['error'] == false) if (response.jsonBody['error'] == false)
return await LocalsRemoteDataSourceImpl() return await LocalsRemoteDataSourceImpl()
.processData(context) .processProperty(context)
.then((value) => value); .then((value) => value);
} catch (e, s) { } catch (e, s) {
await DialogUtil.errorDefault(context); await DialogUtil.errorDefault(context);
@ -86,7 +86,7 @@ class LocalUtil {
.set(ProfileStorageKey.ownerName.key, local['CLU_OWNER_DSC']); .set(ProfileStorageKey.ownerName.key, local['CLU_OWNER_DSC']);
await StorageHelper() await StorageHelper()
.set(ProfileStorageKey.userName.key, local['USU_NOME']); .set(ProfileStorageKey.userName.key, local['USU_NOME']);
return await LocalsRemoteDataSourceImpl().processData(context); return await LocalsRemoteDataSourceImpl().processProperty(context);
} }
static void logLocalsStatus(List<dynamic> locals) { static void logLocalsStatus(List<dynamic> locals) {

View File

@ -22,6 +22,7 @@ class PreferencesPageModel with ChangeNotifier {
late bool isPanic = false; late bool isPanic = false;
Future<void> _initialize() async { Future<void> _initialize() async {
await LocalsRepositoryImpl().fetch(navigatorKey.currentContext!);
isFingerprint = isFingerprint =
await StorageHelper().get(LocalsStorageKey.fingerprint.key) == 'true'; await StorageHelper().get(LocalsStorageKey.fingerprint.key) == 'true';
isPerson = await StorageHelper().get(LocalsStorageKey.person.key) == 'true'; isPerson = await StorageHelper().get(LocalsStorageKey.person.key) == 'true';

View File

@ -22,7 +22,6 @@ class _PreferencesPageWidgetState extends State<PreferencesPageWidget> {
@override @override
void initState() { void initState() {
super.initState(); super.initState();
LocalsRepositoryImpl().update(context);
} }
@override @override