0

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

1 Answer 1

2

You might be missing a bracket

var sortedFixtures = fixtures.sorted((a, b) =>
    (a.fixtureDetails?.timestamp ?? 0).compareTo(b.fixtureDetails?.timestamp ?? 0));
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.