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:
parent
cbb2dd59fc
commit
66302358b9
|
@ -124,8 +124,8 @@ class _AboutSystemPageState extends State<AboutSystemPage> {
|
|||
|
||||
Widget _buildLogo() {
|
||||
return SizedBox(
|
||||
height: 50,
|
||||
width: 50,
|
||||
height: 100,
|
||||
width: 100,
|
||||
child: Image.asset('assets/images/fre.png'),
|
||||
);
|
||||
}
|
||||
|
|
|
@ -18,7 +18,7 @@ abstract class LocalsRemoteDataSource {
|
|||
Future<void> linkLocal(BuildContext context);
|
||||
Future<bool> checkLocals(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> detachLocal(BuildContext context);
|
||||
}
|
||||
|
@ -118,10 +118,16 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
|
|||
return await selectLocal(context, response);
|
||||
} else if (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) {
|
||||
log('() => isAvailable');
|
||||
return await processData(context);
|
||||
return await processProperty(context).then((v) async {
|
||||
if (v == true) return await LicenseRepositoryImpl().updateLicense();
|
||||
return v;
|
||||
});
|
||||
} else {
|
||||
if (!isUnique && !isActive) log('() => not unique and not active');
|
||||
if (!isUnique && isInactived) log('() => not unique and inactived');
|
||||
|
@ -153,7 +159,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
|
|||
}
|
||||
|
||||
@override
|
||||
Future<bool> processData(BuildContext context) async {
|
||||
Future<bool> processProperty(BuildContext context) async {
|
||||
try {
|
||||
final GetDadosCall callback = PhpGroup.getDadosCall;
|
||||
ApiCallResponse? response = await callback.call();
|
||||
|
@ -178,7 +184,7 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
|
|||
return false;
|
||||
} else {
|
||||
await LocalUtil.updateStorageUtil(response.jsonBody);
|
||||
return await LicenseRepositoryImpl().updateLicense();
|
||||
return true;
|
||||
}
|
||||
} catch (e, s) {
|
||||
log('() => error processData: $e', stackTrace: s);
|
||||
|
@ -209,7 +215,10 @@ class LocalsRemoteDataSourceImpl implements LocalsRemoteDataSource {
|
|||
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
|
||||
|
|
|
@ -27,11 +27,16 @@ class LocalsRepositoryImpl implements LocalsRepository {
|
|||
@override
|
||||
Future<bool> update(BuildContext context) async {
|
||||
LocalsRepositoryImpl.license.add(false);
|
||||
final bool response = await _handleReponse(context);
|
||||
final bool response = await _handleLocal(context);
|
||||
LocalsRepositoryImpl.license.add(response);
|
||||
return response;
|
||||
}
|
||||
|
||||
@override
|
||||
Future<bool> fetch(BuildContext context) async {
|
||||
return await _handleProperty(context);
|
||||
}
|
||||
|
||||
Future<void> select(BuildContext context) async {
|
||||
await unselect();
|
||||
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;
|
||||
final bool isUnselected = await remoteDataSource.checkLocals(context);
|
||||
if (isUnselected) {
|
||||
|
@ -74,6 +79,21 @@ class LocalsRepositoryImpl implements LocalsRepository {
|
|||
} else {
|
||||
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;
|
||||
}
|
||||
|
||||
|
|
|
@ -4,4 +4,5 @@ abstract class LocalsRepository {
|
|||
Future<void> validateLocal(BuildContext context) async {}
|
||||
Future<bool> update(BuildContext context) async => false;
|
||||
Future<void> unlinkLocal(BuildContext context) async {}
|
||||
Future<void> fetch(BuildContext context) async {}
|
||||
}
|
||||
|
|
|
@ -63,7 +63,7 @@ class LocalUtil {
|
|||
}
|
||||
if (response.jsonBody['error'] == false)
|
||||
return await LocalsRemoteDataSourceImpl()
|
||||
.processData(context)
|
||||
.processProperty(context)
|
||||
.then((value) => value);
|
||||
} catch (e, s) {
|
||||
await DialogUtil.errorDefault(context);
|
||||
|
@ -86,7 +86,7 @@ class LocalUtil {
|
|||
.set(ProfileStorageKey.ownerName.key, local['CLU_OWNER_DSC']);
|
||||
await StorageHelper()
|
||||
.set(ProfileStorageKey.userName.key, local['USU_NOME']);
|
||||
return await LocalsRemoteDataSourceImpl().processData(context);
|
||||
return await LocalsRemoteDataSourceImpl().processProperty(context);
|
||||
}
|
||||
|
||||
static void logLocalsStatus(List<dynamic> locals) {
|
||||
|
|
|
@ -22,6 +22,7 @@ class PreferencesPageModel with ChangeNotifier {
|
|||
late bool isPanic = false;
|
||||
|
||||
Future<void> _initialize() async {
|
||||
await LocalsRepositoryImpl().fetch(navigatorKey.currentContext!);
|
||||
isFingerprint =
|
||||
await StorageHelper().get(LocalsStorageKey.fingerprint.key) == 'true';
|
||||
isPerson = await StorageHelper().get(LocalsStorageKey.person.key) == 'true';
|
||||
|
|
|
@ -22,7 +22,6 @@ class _PreferencesPageWidgetState extends State<PreferencesPageWidget> {
|
|||
@override
|
||||
void initState() {
|
||||
super.initState();
|
||||
LocalsRepositoryImpl().update(context);
|
||||
}
|
||||
|
||||
@override
|
||||
|
|
Loading…
Reference in New Issue