Trouble Using Custom Code To Writing To A Collection In FireBase

Custom Code

I am trying to create code to get data from an existing table and write it to a new one. The code generated by AI does not seem to have any errors and successfully creates a new document in the new table but no values appear in the table......Can you help please as I don't know Dart

// Automatic FlutterFlow imports
import '/backend/backend.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!

Future write(
  String? country,
  List<String>? stateList,
) async {
  // Create a new document in the TestCountry-StateData collection. Write the Country name in the country field. For each value in the Statelist add it as an item in state field
  // Create a new document in the TestCountry-StateData collection
  final docRef =
      FirebaseFirestore.instance.collection('TestCountry-StateData').doc();

  // Prepare the data to be written
  final data = {
    'country': country,
    'state': stateList,
  };

  // Write the data to Firestore
  await docRef.set(data);
What have you tried so far?

Watched the video on how to implement custom code

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