fix navigation and show local selector
This commit is contained in:
parent
94775efee4
commit
3be97a85e7
|
@ -7,6 +7,7 @@ import 'package:hub/backend/api_requests/api_calls.dart';
|
|||
import 'package:hub/components/organism_components/bottom_arrow_linked_locals_component/bottom_arrow_linked_locals_component_widget.dart';
|
||||
import 'package:hub/flutter_flow/nav/nav.dart';
|
||||
import 'package:hub/shared/utils/dialog_util.dart';
|
||||
import 'package:hub/shared/utils/log_util.dart';
|
||||
import 'package:hub/shared/utils/storage_util.dart';
|
||||
|
||||
import '/flutter_flow/custom_functions.dart' as functions;
|
||||
|
@ -85,8 +86,8 @@ class _LocalProfileComponentWidgetState
|
|||
}
|
||||
|
||||
return;
|
||||
} catch (e) {
|
||||
log('() => error: $e');
|
||||
} catch (e, s) {
|
||||
log('() => error: $e', stackTrace: s);
|
||||
DialogUtil.warningDefault(context).whenComplete(() => processLocals());
|
||||
}
|
||||
}
|
||||
|
@ -99,32 +100,72 @@ class _LocalProfileComponentWidgetState
|
|||
|
||||
final List<dynamic> locals = response.jsonBody['locais'].toList() ?? [];
|
||||
|
||||
for (var local in locals) {
|
||||
final String status = local['CLU_STATUS'];
|
||||
log('() => CLU_STATUS: $status');
|
||||
}
|
||||
|
||||
final bool isActive = response.jsonBody['locais']
|
||||
.where((local) => local['CLU_STATUS'] == 'A')
|
||||
.toList()
|
||||
.isNotEmpty;
|
||||
final bool isInactived = response.jsonBody['locais']
|
||||
.where((local) =>
|
||||
local['CLU_STATUS'] != 'B' && local['CLU_STATUS'] != 'A')
|
||||
.toList()
|
||||
.isNotEmpty;
|
||||
final bool isUnique = locals.length == 1;
|
||||
final bool isBlocked = locals[0]['CLU_STATUS'] == 'B';
|
||||
final bool isEnabled = isUnique && isActive;
|
||||
|
||||
final bool isDisabled = isUnique && isBlocked;
|
||||
final bool isUnselected = StorageUtil().cliUUID.isEmpty &&
|
||||
StorageUtil().cliName.isEmpty & StorageUtil().ownerUUID.isEmpty;
|
||||
final bool isSelected =
|
||||
StorageUtil().cliUUID.isEmpty && StorageUtil().cliName.isEmpty;
|
||||
StorageUtil().cliUUID.isNotEmpty && StorageUtil().cliName.isNotEmpty;
|
||||
final bool isUnavailable = isInactived && isUnselected && isUnique;
|
||||
|
||||
if (!mounted) return;
|
||||
|
||||
if (isDisabled) {
|
||||
if (mounted) context.go('/welcomePage');
|
||||
} else if (isUnavailable) {
|
||||
log('() => isUnavailable');
|
||||
try {
|
||||
StorageUtil().cliName = locals[0]['CLI_NOME'];
|
||||
StorageUtil().cliUUID = locals[0]['CLI_ID'];
|
||||
StorageUtil().ownerUUID = locals[0]['CLU_OWNER_ID'];
|
||||
var response = await PhpGroup.resopndeVinculo.call(tarefa: 'A');
|
||||
if (response.jsonBody['error'] == true) {
|
||||
StorageUtil().cliUUID = '';
|
||||
StorageUtil().cliName = '';
|
||||
StorageUtil().ownerUUID = '';
|
||||
}
|
||||
if (response.jsonBody['error'] == false) await processData();
|
||||
} catch (e, s) {
|
||||
DialogUtil.errorDefault(context);
|
||||
LogUtil.requestAPIFailed(
|
||||
'responderVinculo.php', '', 'Responder Vínculo', e, s);
|
||||
}
|
||||
} else if (isEnabled) {
|
||||
log('() => isEnabled');
|
||||
StorageUtil().cliName = locals[0]['CLI_NOME'];
|
||||
StorageUtil().cliUUID = locals[0]['CLI_ID'];
|
||||
StorageUtil().ownerUUID = locals[0]['CLU_OWNER_ID'];
|
||||
} else if (isSelected) {
|
||||
await showModalSelectLocal();
|
||||
} else {
|
||||
|
||||
await processData();
|
||||
} else if (isUnselected) {
|
||||
log('() => isUnselected');
|
||||
await showModalSelectLocal();
|
||||
} else if (isSelected) {
|
||||
log('() => isSelected');
|
||||
await processData();
|
||||
} else {
|
||||
log('() => else');
|
||||
await showModalSelectLocal();
|
||||
}
|
||||
} catch (e) {
|
||||
log('() => error: $e');
|
||||
log('() => catch: $e');
|
||||
if (mounted) await showModalSelectLocal();
|
||||
}
|
||||
}
|
||||
|
|
|
@ -260,7 +260,7 @@ class PreferencesPageModel with ChangeNotifier {
|
|||
if (value.jsonBody['error'] == false) {
|
||||
StorageUtil().cliName = '';
|
||||
StorageUtil().cliUUID = '';
|
||||
StorageUtil().ownerUUID = '';
|
||||
// StorageUtil().ownerUUID = '';
|
||||
|
||||
context.pop();
|
||||
|
||||
|
|
|
@ -66,7 +66,9 @@ class _ReceptionPageWidgetState extends State<ReceptionPageWidget>
|
|||
StorageUtil().haveLocal = true;
|
||||
StorageUtil().isLogged = true;
|
||||
await WidgetsBinding.instance.endOfFrame;
|
||||
dispose();
|
||||
// dispose();
|
||||
StorageUtil().cliUUID = '';
|
||||
StorageUtil().ownerUUID = '';
|
||||
StorageUtil().context?.go('/homePage');
|
||||
}
|
||||
}
|
||||
|
@ -75,73 +77,6 @@ class _ReceptionPageWidgetState extends State<ReceptionPageWidget>
|
|||
}
|
||||
}
|
||||
|
||||
Future<void> processData() async {
|
||||
try {
|
||||
final GetDadosCall callback = PhpGroup.getDadosCall;
|
||||
|
||||
var response = await callback.call();
|
||||
|
||||
final error = response.jsonBody['error'];
|
||||
// final errorMsg = response.jsonBody['error_msg'];
|
||||
|
||||
if (error == false) {
|
||||
final bool whatsapp = response.jsonBody['whatsapp'] ?? false;
|
||||
final bool provisional = response.jsonBody['provisional'] ?? false;
|
||||
final bool pets = response.jsonBody['pet'] ?? false;
|
||||
final String petAmountRegister =
|
||||
response.jsonBody['petAmountRegister'].toString().isEmpty
|
||||
? '0'
|
||||
: response.jsonBody['petAmountRegister'].toString();
|
||||
final String name = response.jsonBody['visitado']['VDO_NOME'];
|
||||
|
||||
StorageUtil().whatsapp = whatsapp;
|
||||
StorageUtil().provisional = provisional;
|
||||
StorageUtil().pets = pets;
|
||||
StorageUtil().petAmountRegister = petAmountRegister;
|
||||
StorageUtil().userName = name;
|
||||
|
||||
safeSetState(() {});
|
||||
return;
|
||||
} else if (error == true) {
|
||||
final BuildContext? context = StorageUtil().context;
|
||||
if (context != null) {
|
||||
DialogUtil.warningDefault(context)
|
||||
.whenComplete(() => processLocals());
|
||||
}
|
||||
safeSetState(() {});
|
||||
}
|
||||
|
||||
return;
|
||||
} catch (e) {
|
||||
log('() => error: $e');
|
||||
final BuildContext? context = StorageUtil().context;
|
||||
if (context != null) {
|
||||
DialogUtil.warningDefault(context).whenComplete(() => processLocals());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Future<void> showModalSelectLocal() async {
|
||||
StorageUtil().context?.go('/homePage');
|
||||
await showModalBottomSheet(
|
||||
isScrollControlled: true,
|
||||
backgroundColor: Colors.transparent,
|
||||
enableDrag: false,
|
||||
isDismissible: false,
|
||||
context: context,
|
||||
builder: (context) => PopScope(
|
||||
canPop: false,
|
||||
child: Padding(
|
||||
padding: MediaQuery.viewInsetsOf(context),
|
||||
child: const BottomArrowLinkedLocalsComponentWidget(),
|
||||
),
|
||||
),
|
||||
).then((_) async {
|
||||
StorageUtil().haveLocal = true;
|
||||
await processData();
|
||||
});
|
||||
}
|
||||
|
||||
@override
|
||||
void didChangeAppLifecycleState(AppLifecycleState state) {
|
||||
log('() => state: $state');
|
||||
|
|
Loading…
Reference in New Issue