The function is empty or cannot be parsed. Make sure not to modify code outside of the designated area.

Custom Code

i want to add a custom function of inserting data but i can't get what's the problem of this platform.Always showing this error "The function is empty or cannot be parsed. Make sure not to modify code outside of the designated area." every time i try to save the function no matter i do This is the code

import 'dart:convert'; 
import 'dart:math' as math; 
import 'package:http/http.dart' as http; 
import 'package:flutter/material.dart'; 
import 'package:google_fonts/google_fonts.dart'; 
import 'package:intl/intl.dart'; 
import 'package:timeago/timeago.dart' as timeago; 
import '/flutter_flow/lat_lng.dart'; 
import '/flutter_flow/place.dart'; 
import '/flutter_flow/uploaded_file.dart'; 
import '/flutter_flow/custom_functions.dart'; 
import '/backend/supabase/supabase.dart'; 
import '/auth/supabase_auth/auth_util.dart'; 

Future<String> insertDemandDetails( 
String? quantity, String? observation, 
) { /// MODIFY CODE ONLY BELOW THIS LINE // I need custom function for inserting data in table demandDetails 
try { 
final url = 'https://xgwxjlnamnvzgdjxdoeh.supabase.co/rest/v1/demandDetails'; // Ensure this is the correct endpoint for your table 
final data = { 'quantity': quantity, 'observation': observation, }; // Perform HTTP POST request to insert data into demandDetails table
 // Making the HTTP POST request and returning the Future 
return http.post( Uri.parse(url), 
headers: { 
'Content-Type': 'application/json', 
'apikey': 'YOUR_SUPABASE_ANON_KEY', 
// Replace with your actual Supabase Anon Key 
'Authorization': 'Bearer YOUR_SUPABASE_ANON_KEY', // Replace with your actual Supabase Anon Key 
}, 
body: json.encode(data), ).then((response) { // Handling the response 
if (response.statusCode == 201) { 
final responseBody = json.decode(response.body); 
return 'Data inserted successfully: ${responseBody['id']}'; // Assuming id is returned upon successful insertion 
} else { 
print('Failed to insert data into demandDetails table: 
${response.statusCode} - ${response.body}'); 
return 'Failed to insert data into demandDetails table'; 
} })
.catchError((error) { 
print('Error inserting data into demandDetails table: $error'); 
return 'Error inserting data into demandDetails table'; }); 
} 
catch (error) { 
print('Error inserting data into demandDetails table: $error'); 
return Future.value('Error inserting data into demandDetails table'); 
} 
/// MODIFY CODE ONLY ABOVE THIS LINE 
}
What have you tried so far?

i tried to delete some parts of the code when i delete the part of HTTP it work

Did you check FlutterFlow's Documentation for this topic?
No
2 replies