dependent_details_screen.dart fix

wala_plus
FaizHashmi 12 hours ago
parent 771b16c519
commit 269a1a4da8

@ -64,13 +64,14 @@ class _ShieldIconPainter extends CustomPainter {
class DependentDetailsScreen extends StatefulWidget {
final GetEmployeeContactsList? contact;
// True when this screen is being opened right after a successful grant (e.g. from the
// dependents list's inline "Allow Mazaya Access" link), so the success badge shows on
// first build. Granting from within this screen itself (_performToggleAccess) sets the
// Null = just viewing (arrived by tapping the card, no top badge). True/false = this screen
// is being opened right after a successful grant/revoke performed elsewhere (e.g. the
// dependents list's inline "Allow/Revoke Mazaya Access" link), so the matching badge shows
// on first build. Toggling from within this screen itself (_performToggleAccess) sets the
// equivalent local state directly instead of needing this.
final bool justGranted;
final bool? recentAction;
const DependentDetailsScreen({Key? key, this.contact, this.justGranted = false}) : super(key: key);
const DependentDetailsScreen({Key? key, this.contact, this.recentAction}) : super(key: key);
@override
_DependentDetailsScreenState createState() => _DependentDetailsScreenState();
@ -79,7 +80,11 @@ class DependentDetailsScreen extends StatefulWidget {
class _DependentDetailsScreenState extends State<DependentDetailsScreen> {
GetEmployeeContactsList? _contact;
bool _argsLoaded = false;
bool _justGranted = false;
// null = just viewing (arrived by tapping the card, no badge) - true = just granted here,
// false = just revoked here. Set once per toggle in _performToggleAccess; a tap-only visit
// never sets it, so the top badge only ever reflects an action just taken on this screen.
bool? _recentAction;
@override
void didChangeDependencies() {
@ -95,7 +100,7 @@ class _DependentDetailsScreenState extends State<DependentDetailsScreen> {
_contact = args['contact'] as GetEmployeeContactsList;
}
}
_justGranted = widget.justGranted;
_recentAction = widget.recentAction;
_argsLoaded = true;
}
}
@ -210,20 +215,18 @@ class _DependentDetailsScreenState extends State<DependentDetailsScreen> {
setState(() {
_contact!.mAZAYAACCESSFLG = action == "Grant" ? "Y" : "N";
_contact!.mazayaAccess = _contact!.mAZAYAACCESSFLG;
// Tick badge reflects the most recent action, not just "was granted at some point" -
// a later revoke clears it so a stale grant doesn't linger in state.
_justGranted = action == "Grant";
// Top badge reflects whichever action was just taken on this screen, not just "was
// granted at some point" - a later revoke flips it so a stale grant badge never lingers.
_recentAction = action == "Grant";
});
Utils.hideLoading(context);
// Stay on this same screen either way - it already reflects the new access state via
// setState above (status badge, action button, and the share-link section all update
// in place), so tapping a dependent card and successfully granting access both land on
// the exact same screen instead of a separate "success" screen.
if (mounted) {
Utils.showToast(action == "Grant" ? LocaleKeys.mazayaAccessGranted.tr() : LocaleKeys.revokeMazayaAccess.tr());
}
// setState above (status badge, top banner, action button, and the share-link section
// all update in place), so tapping a dependent card and successfully toggling access
// both land on the exact same screen instead of a separate "success" screen. The top
// badge itself is the confirmation now, so no toast on top of it.
} catch (ex) {
Utils.hideLoading(context);
Utils.handleException(ex, context, null);
@ -321,19 +324,30 @@ class _DependentDetailsScreenState extends State<DependentDetailsScreen> {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
// Shown only right after a successful grant (not when just viewing an
// already-granted dependent by tapping into this screen).
if (_justGranted && isAllowed) ...<Widget>[
// Shown only right after a grant/revoke action taken on this screen - not
// when just viewing a dependent by tapping into this screen (_recentAction
// is null in that case).
if (_recentAction != null) ...<Widget>[
Center(
child: Container(
width: 72,
height: 72,
decoration: const BoxDecoration(color: Color(0xFFE6F7F2), shape: BoxShape.circle),
child: Center(child: CustomPaint(size: const Size(36, 36), painter: _ShieldIconPainter(color: const Color(0xFF168A89), isGranted: true))),
decoration: BoxDecoration(color: _recentAction! ? const Color(0xFFE6F7F2) : const Color(0xFFFEECEB), shape: BoxShape.circle),
child: Center(
child: CustomPaint(
size: const Size(36, 36),
painter: _ShieldIconPainter(color: _recentAction! ? const Color(0xFF168A89) : const Color(0xFFED1C24), isGranted: _recentAction!),
),
),
),
),
const SizedBox(height: 10),
Center(child: LocaleKeys.mazayaAccessGranted.tr().toText16(weight: FontWeight.w500, color: const Color(0xFF168A89))),
Center(
child: (_recentAction! ? LocaleKeys.mazayaAccessGranted.tr() : LocaleKeys.mazayaAccessRevoked.tr()).toText16(
weight: FontWeight.w500,
color: _recentAction! ? const Color(0xFF168A89) : const Color(0xFFED1C24),
),
),
const SizedBox(height: 16),
],

@ -94,6 +94,13 @@ class _FamilyMembersState extends State<FamilyMembers> {
personId: contact.pERSONID,
);
// Keep this exact `contact` instance in sync too - it's what gets handed to
// DependentDetailsScreen below, and that's a different object than whatever the fresh
// list refetch returns, so without this it would show the old (pre-toggle) access state
// even though the screen's own "just granted/revoked" badge is correct.
contact.mAZAYAACCESSFLG = action == "Grant" ? "Y" : "N";
contact.mazayaAccess = contact.mAZAYAACCESSFLG;
List<GetEmployeeContactsList> rawList = await ProfileApiClient().getEmployeeContacts();
getEmployeeContactsList = rawList;
@ -101,14 +108,11 @@ class _FamilyMembersState extends State<FamilyMembers> {
if (mounted) {
setState(() {});
if (action == "Grant") {
// Same destination as tapping the card itself, so granting from either entry
// point lands on the exact same screen (which now includes the share-link section).
await Navigator.push(context, MaterialPageRoute<dynamic>(builder: (BuildContext cxt) => DependentDetailsScreen(contact: contact, justGranted: true)));
getEmployeeContacts();
} else {
Utils.showToast(LocaleKeys.revokeMazayaAccess.tr());
}
// Same destination as tapping the card itself, so toggling from either entry point
// lands on the exact same screen (grant/revoke badge, button, and share-link section
// all reflect the new state there) - no toast on top of it.
await Navigator.push(context, MaterialPageRoute<dynamic>(builder: (BuildContext cxt) => DependentDetailsScreen(contact: contact, recentAction: action == "Grant")));
getEmployeeContacts();
}
} catch (ex) {
Utils.hideLoading(context);

Loading…
Cancel
Save