uploadUserFeedbackToFirebase method

Future<bool> uploadUserFeedbackToFirebase({
  1. required FeedbackModel feedback,
  2. required AndroidDeviceInfo? androidDeviceInfo,
  3. required IosDeviceInfo? iosDeviceInfo,
})

uploadUserFeedbackToFirebase is the function which takes the user feedback and all the system information and uploads it to the Cloud Firestore. This function is Platform dependent. Which means it automatically submits the appropriate system information based on the Platform on which app is running. Currently supports only Android & iOS

Implementation

Future<bool> uploadUserFeedbackToFirebase({
  required FeedbackModel feedback,
  required AndroidDeviceInfo? androidDeviceInfo,
  required IosDeviceInfo? iosDeviceInfo,
}) async {
  try {
    if (Platform.isAndroid) {
      final feedbackData = {
        'appName': feedback.appName,
        'packageName': feedback.packageName,
        'appVersion': feedback.appVersion,
        'buildVersion': feedback.buildVersionNumber,
        'userFeedbackData': feedback.userFeedbackData,
        'currentStateScreenShotUrl': feedback.currentStateScreenShotUrl,
        'feedbackSubmittedOn': FieldValue.serverTimestamp(),
        'reportType': feedback.reportType,
        'userInformation': {
          'userId': feedback.userId,
          'email': feedback.userEmail,
        },
        'systemInformation': {
          'device': androidDeviceInfo!.device,
          'isPhysicalDevice': androidDeviceInfo.isPhysicalDevice,
          'buildFingerprint': androidDeviceInfo.fingerprint,
          'model': androidDeviceInfo.model,
          'product': androidDeviceInfo.product,
          'sdkVersion': androidDeviceInfo.version.sdkInt,
          'release': androidDeviceInfo.version.release,
          'incrementalVersion': androidDeviceInfo.version.incremental,
          'codename': androidDeviceInfo.version.codename,
          'board': androidDeviceInfo.board,
          'brand': androidDeviceInfo.brand,
        }
      };

      await _firestore
          .collection(feedbackCollectionPath!)
          .doc('android')
          .collection('feedbacks')
          .doc()
          .set(feedbackData);

      return true;
    }
    if (Platform.isIOS) {
      final feedbackData = {
        'appName': feedback.appName,
        'packageName': feedback.packageName,
        'appVersion': feedback.appVersion,
        'buildVersion': feedback.buildVersionNumber,
        'userFeedbackData': feedback.userFeedbackData,
        'currentStateScreenShotUrl': feedback.currentStateScreenShotUrl,
        'feedbackSubmittedOn': FieldValue.serverTimestamp(),
        'reportType': feedback.reportType,
        'userInformation': {
          'userId': feedback.userId,
          'email': feedback.userEmail,
        },
        'systemInformation': {
          'name': iosDeviceInfo!.name,
          'systemVersion': iosDeviceInfo.systemVersion,
          'model': iosDeviceInfo.model,
          'utsName': {
            'version': iosDeviceInfo.utsname.version,
            'release': iosDeviceInfo.utsname.release,
            'machine': iosDeviceInfo.utsname.machine,
            'nodeName': iosDeviceInfo.utsname.nodename,
            'sysName': iosDeviceInfo.utsname.sysname,
          },
          'identifierForVendor': iosDeviceInfo.identifierForVendor,
          'isPhysicalDevice': iosDeviceInfo.isPhysicalDevice,
        }
      };

      await _firestore
          .collection(feedbackCollectionPath!)
          .doc('ios')
          .collection('feedbacks')
          .doc()
          .set(feedbackData);

      return true;
    }
    return false;
  } catch (error) {
    return false;
  }
}