showMessageFromModal method

void showMessageFromModal(
  1. BuildContext context,
  2. dynamic result, {
  3. Function? afterCallback,
})

The parameter afterCallback is used as an optional parameter A use-case is refreshing feed in pro after adding contact details

Implementation

void showMessageFromModal(BuildContext context, dynamic result,
    {Function? afterCallback}) {
  if (result == null) {
    final ContactProvider? provider = ContactProvider.of(context);
    // flags used to show loading indicator
    final List<String> flags = <String>['set_to_primary', 'add_contact_info'];

    void clearFlag(String flag) {
      if (provider!.checkWaitingFor(flag: flag) as bool) {
        toggleLoadingIndicator(context: context, flag: flag, show: false);
        return;
      }
    }

    for (final String flag in flags) {
      clearFlag(flag);
    }

    return;
  }

  /// Show message to user
  ScaffoldMessenger.of(context).showSnackBar(
    SnackBar(
      content: Text(result['message'].toString()),
      duration: const Duration(seconds: kLongSnackBarDuration),
      action: SnackBarAction(
        label: 'Ok, thanks',
        textColor: white,
        onPressed: () {
          ScaffoldMessenger.of(context).hideCurrentSnackBar();
        },
      ),
    ),
  );

  if (afterCallback != null) {
    afterCallback();
  }
}