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

how to return specific size of list using flutter?

I have a list that I extract it from a txt file then I splitted this list into sublists. now I want to return just 240 items of this list.
this is my code:

static Future<List> localPath() async {
    File textAsset = File('/storage/emulated/0/RPSApp/assets/bluetooth.txt');
    final text = await textAsset.readAsString();
    final bytes =
        text.split(',').map((s) => s.trim()).map((s) => int.parse(s)).toList();

    int chunkSize = 20;

    List<int> padTo(List<int> input, int count) {
      return [...input, ...List.filled(count - input.length, 255)];
    }

    List<int> padToChunksize(List<int> input) => padTo(input, chunkSize);

    final items = bytes.slices(chunkSize).map(padToChunksize).toList();

    return items;
  }
```
I want something like:
```
for(int i=0; i<240; i+=chunksize){
return items
}
```
thanks in advance for your help

>Solution :

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

List.take(count) can be used for this:

return items.take(240).toList();
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