How to subtract a String Value from a List during Iteration? Flutter

Issue

I have a list with widget constructors which are strings, that are used in different classes. The list consists of 39 labels and these 39 labels have different text some pages will have only 7 labels, how during iteration can i show only the number of labels that the class displays as a string?

List<String> tests;
// @override
// void initState() {
// super.initState();     tests = [widget.label00, widget.label0]; }

  @override
  void initState() {
    super.initState();
    tests = [
      widget.label00,
      widget.label0,
      widget.label1,
      widget.label2,
      widget.label3,
      widget.label4,
      widget.label5,
      widget.label6,
      widget.label7,
      widget.label8,
      widget.label9,
      widget.label10,
      widget.label11,
      widget.label12,
      widget.label13,
      widget.label14,
      widget.label15,
      widget.label16,
      widget.label17,
      widget.label18,
      widget.label19,
      widget.label20,
      widget.label21,
      widget.label22,
      widget.label23,
      widget.label24,
      widget.label25,
      widget.label26,
      widget.label27,
      widget.label28,
      widget.label29,
      widget.label30,
      widget.label31,
      widget.label32,
      widget.label33,
      widget.label34,
      widget.label35,
      widget.label36,
      widget.label37,
      widget.label38,
      widget.label39
    ];

    // List<ReusableLarge> translationTextsss = [
    //   ReusableLarge(label00: "test00"),
    //   ReusableLarge(label0: "test0"),
    //   ReusableLarge(label1: 'test1'),
    //   ReusableLarge(label2: 'test2'),
    //   // ),
    // ];

    Timer.periodic(Duration(seconds: 5), (Timer timer) {
      if (widget.label7 == '') {
        setState(() {
          tests.length - 1;
        });

        if (_currentPage < tests.length) {
          _currentPage++;
        } else {
          _currentPage = 0;
        }

        _pageController.animateToPage(
          _currentPage,
          duration: Duration(milliseconds: 350),
          curve: Curves.easeIn,
        );
      }
    });
  }

and one of the classes that show the strings:
how can i do it so the cards that have label: ” to not display?? I tried tests.length-1 but its showing a swiggly lines i want the tests.length to change based on whether that label contains a string or not.

label00: 'Surah Fatiha' + '\n' + 'The Opening',
      label0: 'In the name of God, the Lord of Mercy, the Giver of Mercy!',
      label1: 'AYAH 1: Praise belongs to God, Lord of the Worlds,',
      label2: 'AYAH 2: the Lord of Mercy, the Giver of Mercy,',
      label3: 'AYAH 3: Master of the Day of Judgement.',
      label4: 'AYAH 4: It is You we worship; it is You we ask for help.',
      label5: 'AYAH 5: Guide us to the straight path:',
      label6:
          'AYAH 6: the path of those You have blessed, those who incur no anger and who have not gone astray.',
      label7: '',
      label8: 'label8',
      label9: '',
      label10: '',
      label11: '',
      label12: '',
      label13: '',
      label14: '',
      label15: '',
      label16: "",
      label17: '',
      label18: '',
      label19: '',
      label20: '',
      label21: '',
      label22: '',
      label23: '',
      label24: '',
      label25: '',
      label26: '',
      label27: "",
      label28: '',
      label29: '',
      label30: '',
      label31: '',
      label32: '',
      label33: '',
      label34: '',
      label35: '',
      label36: '',
      label37: '',
      label38: '',
      label39: '',

Solution

I was able to get through this road block by having one list with all the widgets looping them and adding it to another list which worked wonders for what i was looking for:
results = [];

for (int i = 0; i < tests.length; i++) {
  if (widget.label00 != '') {
    results.add(widget.label00);
  }
  if (widget.label0 != '') {
    results.add(widget.label0);
  }
  if (widget.label1 != '') {
    results.add(widget.label1);
  }
  if (widget.label2 != '') {
    results.add(widget.label2);
  }
  if (widget.label3 != '') {
    results.add(widget.label3);
  }
  if (widget.label4 != '') {
    results.add(widget.label4);
  }
  if (widget.label5 != '') {
    results.add(widget.label5);
  }
  if (widget.label6 != '') {
    results.add(widget.label6);
  }
  if (widget.label7 != '') {
    results.add(widget.label7);
  }
  if (widget.label8 != '') {
    results.add(widget.label8);
  }
  if (widget.label9 != '') {
    results.add(widget.label9);
  }
  if (widget.label10 != '') {
    results.add(widget.label10);
  }
  if (widget.label11 != '') {
    results.add(widget.label11);
  }
  if (widget.label12 != '') {
    results.add(widget.label12);
  }
  if (widget.label13 != '') {
    results.add(widget.label13);
  }
  if (widget.label14 != '') {
    results.add(widget.label14);
  }
  if (widget.label15 != '') {
    results.add(widget.label15);
  }
  if (widget.label16 != '') {
    results.add(widget.label16);
  }
  if (widget.label17 != '') {
    results.add(widget.label17);
  }
  if (widget.label18 != '') {
    results.add(widget.label18);
  }
  if (widget.label19 != '') {
    results.add(widget.label19);
  }
  if (widget.label20 != '') {
    results.add(widget.label20);
  }
  if (widget.label21 != '') {
    results.add(widget.label21);
  }
  if (widget.label22 != '') {
    results.add(widget.label22);
  }
  if (widget.label23 != '') {
    results.add(widget.label23);
  }
  if (widget.label24 != '') {
    results.add(widget.label24);
  }
  if (widget.label25 != '') {
    results.add(widget.label25);
  }

  if (widget.label26 != '') {
    results.add(widget.label26);
  }
  if (widget.label27 != '') {
    results.add(widget.label27);
  }
  if (widget.label28 != '') {
    results.add(widget.label28);
  }
  if (widget.label29 != '') {
    results.add(widget.label29);
  }
  if (widget.label30 != '') {
    results.add(widget.label30);
  }
  if (widget.label31 != '') {
    results.add(widget.label31);
  }
  if (widget.label32 != '') {
    results.add(widget.label32);
  }
  if (widget.label33 != '') {
    results.add(widget.label33);
  }
  if (widget.label34 != '') {
    results.add(widget.label34);
  }
  if (widget.label35 != '') {
    results.add(widget.label35);
  }
  if (widget.label36 != '') {
    results.add(widget.label36);
  }
  if (widget.label37 != '') {
    results.add(widget.label37);
  }

Answered By – shahbaz

Answer Checked By – Mildred Charles (FlutterFixes Admin)

Leave a Reply

Your email address will not be published.