79443289

Date: 2025-02-16 14:24:13
Score: 0.5
Natty:
Report link

Here's how I ended up getting this to work...

int? switchValue = 0;  // initial segmented control value
...
onValueChanged: (int? newValue) {
  setState(() { switchValue = newValue; }); }
...
// inside ListView.builder...
  itemCount: snapshot.data!.length,
  builder: (context, index) {
    if (switchValue == 0) { // 0 = "show Active only"
      switch (snapshot.data![index]['archived']) {
        case false:
          return ListTile(...  // build full listTile
        default:
          return SizedBox.shrink(); // zero-size/empty
    } else { // switchValue is 1, so "show all"
      return ListTile(...
    }

Seemed like the simplest solution. Thanks to the answers above, though - I learned all about the .where functionality, and about SizedBox.shrink(), which I'd never seen before.

Now if I can just figure out a way to smoothly animate the transition between Active only / Show all (instead of the abrupt change), I'll be rolling.

Reasons:
  • Blacklisted phrase (0.5): Thanks
  • Long answer (-0.5):
  • Has code block (-0.5):
  • Self-answer (0.5):
  • Low reputation (0.5):
Posted by: Andy