I am trying to create a custom function to add records to the Firebase table.
Firebase collection creation using custom function
import 'dart:convert';
import 'dart:math' as math;
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/backend.dart';
import 'package:cloud_firestore/cloud_firestore.dart';
String? newCustomFunction() {
/// MODIFY CODE ONLY BELOW THIS LINE
// create a function which create a table in firebase
// Create a function to create a table in Firebase
void createFirebaseTable() {
// Access Firestore instance
FirebaseFirestore firestore = FirebaseFirestore.instance;
// Create a new collection in Firestore
CollectionReference tableRef = firestore.collection('tableName');
// Add a document to the collection
tableRef.add({
'field1': 'value1',
'field2': 'value2',
'field3': 'value3',
});
}
// Call the function to create the table
createFirebaseTable();
return 'Table created successfully';
/// MODIFY CODE ONLY ABOVE THIS LINE
}