Skip to content

Commit 9349449

Browse files
authored
sort nodes by status (#1070)
* sort nodes by status * move sorted nodes computations outside ListView.builder * fix conflict
1 parent 75f083b commit 9349449

1 file changed

Lines changed: 12 additions & 2 deletions

File tree

app/lib/screens/farm_details.dart

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -251,6 +251,16 @@ class _FarmDetailsState extends State<FarmDetails> {
251251

252252
@override
253253
Widget build(BuildContext context) {
254+
final sortedNodes = List.from(widget.farm.nodes)
255+
..sort((a, b) {
256+
if (a.status == NodeStatus.Up && b.status != NodeStatus.Up) {
257+
return -1;
258+
} else if (a.status != NodeStatus.Up && b.status == NodeStatus.Up) {
259+
return 1;
260+
} else {
261+
return 0;
262+
}
263+
});
254264
return Scaffold(
255265
appBar: AppBar(
256266
title: Text(widget.farm.name),
@@ -526,9 +536,9 @@ class _FarmDetailsState extends State<FarmDetails> {
526536
ListView.builder(
527537
shrinkWrap: true,
528538
physics: const NeverScrollableScrollPhysics(),
529-
itemCount: widget.farm.nodes.length,
539+
itemCount: sortedNodes.length,
530540
itemBuilder: (context, index) {
531-
final node = widget.farm.nodes[index];
541+
final node = sortedNodes[index];
532542
return Card(
533543
margin: const EdgeInsets.symmetric(
534544
vertical: 4.0, horizontal: 0.0),

0 commit comments

Comments
 (0)