login method Null safety

void login(
  1. String username,
  2. String password,
  3. Function loginCallback
)

Login a user.

Implementation

void login(String username, String password, Function loginCallback) async {
  // Link to server.
  final HttpLink httpLink = HttpLink(statementDatabaseUrl, defaultHeaders: {
    'X-Parse-Application-Id': statementDatabaseApplicationID,
    'X-Parse-Client-Key': statementDatabaseClientKey,
    //'X-Parse-REST-API-Key' : kParseRestApiKey,
  });

  // Provides data from server and facilitates requests.
  GraphQLClient client = GraphQLClient(
    cache: GraphQLCache(),
    link: httpLink,
  );

  // The result returned from the query.
  var loginResult = await client.mutate(
    MutationOptions(
      document: gql(Queries.login(username, password)),
    ),
  );
  // If login result has any exceptions.
  if (loginResult.hasException) {
    loginCallback(false, "Login fehlgeschlagen.");
    return;
  }
  // Safe the new token.
  safeStorage.write(
      key: "token",
      value: loginResult.data?["logIn"]["viewer"]["sessionToken"]);
  loginCallback(true, null);
}