How to iterate a DataType List using a text file?

Hello, I need help with my project. The function of the app is:

create code that opened a .txt file;

Remove unwanted characters;

turn it into a List<String>;

transform each String in the list into a DataType and;

return a List<DataStructure>.

File:

DataType:

AppState:

Custom code:

Add to the appState variable:

I add appState to ListView:

but...

After opening the text file nothing happens...

can anybody help me?

My code:

// Automatic FlutterFlow imports
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 'dart:convert';

Future<List<SampleDataTypeStruct>> customAction(FFUploadedFile uploadedFile) async {
  List<int>? bytes = uploadedFile.bytes; // capturing the bytes of the file

  String textFile = utf8.decode(bytes!); // transforming bytes into string

  List<String> lines = textFile.split('\n'); // transforming the text file into a list of strings

  List<SampleDataTypeStruct> samples = [];

  for (int i = 0; i < lines.length; i++) 
  {
    samples.add(createDataStruct(lines[
        i])); // calling the createDataStruct method and passing all the strings in the list
  }

  return samples;
}

// creating a method that will create the DataType structure from a line
SampleDataTypeStruct createDataStruct(String line) 
{
  List<String> cells = []; // storing the subStrings in a list

  for (int i = 0; i <= 4 /* number of cells = 5 */; i++) 
  {
    if (line.contains(';')) // separating the subStrings from the delimiter ';'
    {
      cells[i] = line.substring(0, line.indexOf(';'));
    } else // the last cell does not have the delimiter
    {
      cells[i] = line.substring(0, line.length);
    }
    line = line.substring(line.indexOf(';') + 1); // removing already used substring from string
  }

  //feeding the DataType with the captured substrings
  SampleDataTypeStruct sample = SampleDataTypeStruct(
      cell01: cells[0],
      cell02: cells[1],
      cell03: cells[2],
      cell04: cells[3],
      cell05: cells[4]);

  return sample;
}

The txt file:

"cell01_line01";"cell02_line01";"cell_03_line01";"cell_04_line01";"cell05_line01"

"cell01_line02";"cell02_line02";"cell_03_line02";"cell_04_line02";"cell05_line02"

"cell01_line03";"cell02_line03";"cell_03_line03";"cell_04_line03";"cell05_line03"

"cell01_line04";"cell02_line04";"cell_03_line04";"cell_04_line04";"cell05_line04"

"cell01_line05";"cell02_line05";"cell_03_line05";"cell_04_line05";"cell05_line05"

2
1 reply