Skip to content

Commit

Permalink
Write random bytes in example app.
Browse files Browse the repository at this point in the history
pauldemarco committed Oct 18, 2019
1 parent 55705b9 commit 5a56ede
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions example/lib/main.dart
Original file line number Diff line number Diff line change
@@ -3,6 +3,7 @@
// BSD-style license that can be found in the LICENSE file.

import 'dart:async';
import 'dart:math';

import 'package:flutter/material.dart';
import 'package:flutter_blue/flutter_blue.dart';
@@ -155,6 +156,16 @@ class DeviceScreen extends StatelessWidget {

final BluetoothDevice device;

List<int> _getRandomBytes() {
final math = Random();
return [
math.nextInt(255),
math.nextInt(255),
math.nextInt(255),
math.nextInt(255)
];
}

List<Widget> _buildServiceTiles(List<BluetoothService> services) {
return services
.map(
@@ -165,15 +176,15 @@ class DeviceScreen extends StatelessWidget {
(c) => CharacteristicTile(
characteristic: c,
onReadPressed: () => c.read(),
onWritePressed: () => c.write([13, 24]),
onWritePressed: () => c.write(_getRandomBytes()),
onNotificationPressed: () =>
c.setNotifyValue(!c.isNotifying),
descriptorTiles: c.descriptors
.map(
(d) => DescriptorTile(
descriptor: d,
onReadPressed: () => d.read(),
onWritePressed: () => d.write([11, 12]),
onWritePressed: () => d.write(_getRandomBytes()),
),
)
.toList(),

0 comments on commit 5a56ede

Please sign in to comment.