简体   繁体   中英

how to send function's values more than one time using flutter?

I'm new with flutter and I want to send the same function (write) for 20 times. this is the function:

         List<Widget> _buildServiceTiles(List<BluetoothService> services) {
    return services
        .map(
          (s) => ServiceTile(
            service: s,
            characteristicTiles: s.characteristics
                .map(
                  (c) => CharacteristicTile(
                    characteristic: c,
                    onWritePressed: () async {
                      await c.write(_getRandomBytes(), withoutResponse: true);
                    },
                    descriptorTiles: c.descriptors
                        .map(
                          (d) => DescriptorTile(
                            descriptor: d,
                            onWritePressed: () => d.write(_getRandomBytes()),
                          ),
                        )
                        .toList(),
                  ),
                )
                .toList(),
          ),
        )
        .toList();
  }

the function that I want to display it for 20 times is: onWritePressed: () async { await c.write(_getRandomBytes(), withoutResponse: true); }, Actually this function is for writing bytes and sending them to an stm32 card via bluetooth. Thanks in advance for your help.

If you just want to blindly send it 20 times in row you can just use a for loop.

onWritePressed: () async {
  for(int i=0; i< 20; i++)
  {
     await c.write(_getRandomBytes(), withoutResponse: true);
  }
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM