fluttersupabasesupabase-databasesupabase-flutter

Cannot upload data to database in supabase


I am using Flutter and learning Supabase. It is now getting frustrating as there is no response or exception mechanism. I am using the following code, Note: The user is being signed up and signed in successfully, and the auth policy of the users table is also set to public but nothing in logs and no exception is being caught as well

try {
        _user = UserModel(id: authResponse.user!.id, name: name, email: email);
        final response = await _supabase.from("users").insert(_user!.toJson());
        log(response.toString());
        log(_user!.toJson());
      } catch (e) {
        log(e.toString());
        return false;
      }

Solution

  • I had to hardcode the map a bit to solve the problem

    try {
            _user = UserModel(id: authResponse.user!.id, name: name, email: email);
            final response = await _supabase.from("users").insert({
              "id": _user!.id,
              "email": _user!.email,
              "name": _user!.name
            }).select();
            log(response.toString());
            log(_user!.toJson());
          } catch (e) {
            log(e.toString());
            return false;
          }