Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Flutter sorted function doesn't sort correctly

I’m trying to sort a list of objects by their timestamp, but as you can see below from the timestamps the list that gets returned is just randomized. Does anyone know what issue im facing here?

var sortedFixtures = fixtures.sorted((a, b) =>
    a.fixtureDetails?.timestamp ??
    0.compareTo(b.fixtureDetails?.timestamp ?? 0));

This produces the following (the timestamp for each team is underneath the name):

I/flutter (30585): West Ham
I/flutter (30585): 1664641800
I/flutter (30585): Southampton
I/flutter (30585): 1664632800
I/flutter (30585): Manchester City
I/flutter (30585): 1664715600
I/flutter (30585): Liverpool
I/flutter (30585): 1664632800
I/flutter (30585): Leicester
I/flutter (30585): 1664823600
I/flutter (30585): Leeds
I/flutter (30585): 1664724600
I/flutter (30585): Fulham
I/flutter (30585): 1664632800
I/flutter (30585): Crystal Palace
I/flutter (30585): 1664632800
I/flutter (30585): Arsenal
I/flutter (30585): 1664623800
I/flutter (30585): Bournemouth
I/flutter (30585): 1664632800

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

>Solution :

You might be missing a bracket

var sortedFixtures = fixtures.sorted((a, b) =>
    (a.fixtureDetails?.timestamp ?? 0).compareTo(b.fixtureDetails?.timestamp ?? 0));
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading