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.