i am creating a custom function to write data in firebase i.e "data entry" . when i add data through app, the data is successfully added but at same time the app goes in loading. but when i reopen app then it is running normal. means every time add data the app is on loading phase until close and reopen. if anyone has a solution, please help as soon as possible.
custom action to add data into firebase by a form fields.
Custom Code
// Automatic FlutterFlow imports
import '/backend/backend.dart';
import '/backend/schema/structs/index.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 sendVoterData(
String? acname,
int? acnumber,
int? serialnumber,
String? name,
String? guardianName,
String? epicNumber,
String? gender,
String? status,
int? mobileNumber,
int? age,
String? caste,
String? occupation,
String? address,
String? sentiment,
String? influencer,
String? religion,
String? fulladdress,
String? feedback,
String? boothNumber,
String? category,
DateTime? dob,
String? boothAgent,
String? boothAgentTask,
String? boothAgentVehicle) async {
// Add your function code here!
try {
FirebaseFirestore.instance.settings = Settings(persistenceEnabled: true);
final CollectionReference users =
FirebaseFirestore.instance.collection('Peopledatabase');
await FirebaseFirestore.instance.disableNetwork();
users.add({
'AC_name': acname ?? '',
'AC_number': acnumber ?? 1,
'Serial_number': serialnumber ?? 1,
'Voter_status': status ?? '',
'Name': name ?? '',
'Guardianname': guardianName ?? '',
'Epicnumber': epicNumber ?? '',
'Gender': gender ?? '',
'Mobilenumber': mobileNumber ?? 1,
'Age': age ?? 1,
'Caste': caste ?? '',
'Occupation': occupation ?? '',
'Address': address ?? '',
'Sentiment': sentiment ?? '',
'Influencer': influencer ?? '',
'Religion': religion ?? '',
'Feedback': feedback ?? '',
'Full_Address': fulladdress ?? '',
'Boothnumber': boothNumber ?? '',
'Category': category ?? '',
'Date_of_Birth': dob ?? '',
'Booth_Agent': boothAgent ?? '',
'Booth_Agent_Vehicle': boothAgentVehicle ?? '',
'Booth_Agent_Task': boothAgentTask ?? ''
});
} catch (e) {
print("Error: $e");
}
}
// Set your action name, define your arguments and return parameter,
// and then add the boilerplate code using the green button on the right!Yes
1
2 replies