1

I have a ListView in Flutter shows stores location information from firebase after that a function works to calculate a distance between customer location and stores locations and show distance value in the trailing of ListView, now I want to sort this ListView based on trailing value (nearest stores):

SCREENSHOT FROM LIST VIEW

Most of solution I have tried was so complicated and want an easy a effective way.

1
  • Hi, can you share the code? Commented Nov 4, 2022 at 7:44

1 Answer 1

2

For ascending

var dataList = [1, 6, 8, 2, 16, 0] //your dynamic list
dataList.sort((a, b) => a.compareTo(b));

For descending

var dataList  = [1, 6, 8, 2, 16, 0] //your dynamic list
dataList .sort((b, a) => a.compareTo(b));

don't forgot to call setState to reload your UI again

Sign up to request clarification or add additional context in comments.

1 Comment

Thank you Harizh, I believe this is the easiest way, it 'is collecting the result in a separate list then sort it then return it back to widget.

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.