0

I'm writing a custom action in FlutterFlow, i keep receiving errors trying to compile the code but without any information about the error itself.

The action is this:

// Automatic FlutterFlow imports
import '/backend/schema/structs/index.dart';
import '/flutter_flow/flutter_flow_theme.dart';
import '/flutter_flow/flutter_flow_util.dart';
import '/custom_code/actions/index.dart'; // Imports other custom actions
import '/flutter_flow/custom_functions.dart'; // Imports custom functions
import 'package:flutter/material.dart';
// Begin custom action code
// DO NOT REMOVE OR MODIFY THE CODE ABOVE!

import 'dart:convert';

// Set your action name, define your arguments and return parameter,
// and then add the boilerplate code using the button on the right!
UserStruct decodeToken(String token) {
  UserStruct user = UserStruct();
  // Add your function code here!
  final parts = token.split('.');
  if (parts.length != 3) {
    return user;
  }

  final encodedPayload = parts[1];
  final normalizedPayload = base64Url.normalize(encodedPayload);
  final decodedPayload = utf8.decode(base64Url.decode(normalizedPayload));
  final payloadData = json.decode(decodedPayload);

  if (payloadData is! Map<String, dynamic>) {
    return user;
  }

  if (payloadData.containsKey("sub")) {
    user.sub = payloadData["sub"];
  }
  if (payloadData.containsKey("auth0")) {
    user.sub = payloadData["auth0"];
  }

  return user;
}

Could someone help me understanding what's wrong with this? Am i doing something wrong or the problem is in FlutterFlow?

Thanks

I've tried moving the code to a custom function and it works well, but i still can't compile the action.

Andrew
  • 1

0 Answers0