popeyelau / wiki

📒Wiki for many useful notes, source, commands and snippets.
2 stars 0 forks source link

Dart Collection #32

Open popeyelau opened 3 years ago

popeyelau commented 3 years ago

spread

Widget buildItems() {
  List<Widget> sectionA = [Text("A")];
  List<Widget> sectionB = [Text("B")];
  return Column(
    children: [
      ...sectionA,
      ...sectionB,
    ],
  );
}

if

Widget buildItems() {
  List<Widget> sectionA = [Text("A")];
  List<Widget> sectionB = [Text("B")];
  bool showSectionB = false;
  return Column(
    children: [
      ...sectionA,
      if (showSectionB) ...sectionB,
    ],
  );
}

for in

  Widget buildItems() {
    List<Widget> sectionA = [Text("A")];
    List<Widget> sectionB = [Text("B")];
    List<int> sectionC = [1, 2, 3, 4, 5];

    bool showSectionB = false;
    return Column(
      children: [
        ...sectionA,
        if (showSectionB) ...sectionB,
        for (var number in sectionC)
          if (number.isEven) Text(number.toString())
      ],
    );
  }