Sorting a list

18 views
Skip to first unread message

Russ Brewer

unread,
Aug 9, 2020, 11:55:57 PM8/9/20
to Flutter Development (flutter-dev)
This should be simple. I am trying to sort a list that contains many BeerStat objects by a parameter. In this case I want accedingUntitled.jpg and descending percent change.
Capture.JPG

I have this code, that I don't think is referencing my data corrector to perform a sort. The data is loaded into productsData.

                    ToggleSwitch(
                        initialLabelIndex: 0,
                        labels: ['ASC', 'DESC'],
                        minHeight: 30.0,
                        fontSize: 12.0,
                        cornerRadius: 20.0,
                        onToggle: (index) {
                          print('switched to : $index');
                          setState(() {
                            productsData.items.sort((a,b) => a.ptcchg.compareTo(b.ptcchg));
                          });
                        },
                      ),

I think it has something to do with my data having integers 0-251, as keys. I'm not sure how to sort my data now that it is in a list.

Thank you


Suzuki Tomohiro

unread,
Aug 10, 2020, 8:15:53 AM8/10/20
to Russ Brewer, Flutter Development (flutter-dev)
Your ToggleSwitch sorts the data by “ptcchg“ property regardless of the “index” variable. You want to change sort field based on the value of the variable. I guess one if-statement would solve this.

--
You received this message because you are subscribed to the Google Groups "Flutter Development (flutter-dev)" group.
To unsubscribe from this group and stop receiving emails from it, send an email to flutter-dev...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/flutter-dev/96d85c34-81f9-4300-b972-94fdd5ad2fefn%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages