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 :

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

return items.take(240).toList();

Leave a Reply