Elvis
ย ยทย Cloud Functions, APIs, OpenAI, Webapp and Mobile APP GURU,

Accessing data type struct on custom code

I have a custom code that I have added a datatype as an argument
I am trying to access the struct but I get an error

Type: InvalidType

The getter 'WaterBill' isn't defined for the type 'RentInvoiceStructStruct'.
Try importing the library that defines 'WaterBill', correcting the name to the name of an existing getter, or defining a getter or field named 'WaterBill'.dartundefined_getter


the data type is called RentInvoiceStruct and the argument is called billsStruct


here is my 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!

import 'package:pdf/pdf.dart';
import 'package:pdf/widgets.dart' as pw;
import 'package:printing/printing.dart';

Future rentInvoicePdf(
  String? title,
  String? date,
  RentInvoiceStructStruct? billsStruct,
) async {
  final pdf = pw.Document();

  // Handling null values for title and date
  final safeTitle = title ?? 'Invoice';
  final safeDate = date ?? 'No Date Provided';

  // Initialize total bill and widget list
  double totalBill = 0;
  List<pw.Widget> billWidgets = [];

  if (billsStruct != null) {
    // Directly access each bill
    if (billsStruct.WaterBill != null) {
      totalBill += billsStruct.WaterBill!;
      billWidgets.add(_createBillRow("Water Bill", billsStruct.WaterBill!));
    }
    if (billsStruct.GarbageBill != null) {
      totalBill += billsStruct.GarbageBill!;
      billWidgets.add(_createBillRow("Garbage Bill", billsStruct.GarbageBill!));
    }
    if (billsStruct.RentBill != null) {
      totalBill += billsStruct.RentBill!;
      billWidgets.add(_createBillRow("Rent Bill", billsStruct.RentBill!));
    }
  }

  pdf.addPage(
    pw.Page(
      pageFormat: PdfPageFormat.a4,
      build: (pw.Context context) => pw.Column(
        crossAxisAlignment: pw.CrossAxisAlignment.start,
        children: [
          pw.Text(safeTitle, style: pw.TextStyle(fontSize: 30)),
          pw.Text("Date: $safeDate", style: pw.TextStyle(fontSize: 18)),
          pw.Divider(),
          pw.Column(children: billWidgets),
          pw.Divider(),
          pw.Row(
            mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
            children: [
              pw.Text("Total Bill"),
              pw.Text(totalBill.toStringAsFixed(2)),
            ],
          ),
        ],
      ),
    ),
  );

  final pdfSaved = await pdf.save();
  await Printing.layoutPdf(onLayout: (PdfPageFormat format) async => pdfSaved);
}

pw.Widget _createBillRow(String billName, double amount) {
  return pw.Row(
    mainAxisAlignment: pw.MainAxisAlignment.spaceBetween,
    children: [
      pw.Text(billName),
      pw.Text("${amount.toStringAsFixed(2)}"),
    ],
  );
}


Anyone know the correct way to access the struct

5
18 replies