Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add FlutterBlue.name to get the human readable device name #1085

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -230,6 +230,15 @@ public void onMethodCall(MethodCall call, Result result) {
break;
}

case "name":
{
String name = mBluetoothAdapter.getName();
if (name == null)
name = "";
result.success(name);
break;
}

case "isOn":
{
result.success(mBluetoothAdapter.isEnabled());
Expand Down
2 changes: 2 additions & 0 deletions ios/Classes/FlutterBluePlugin.m
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,8 @@ - (void)handleMethodCall:(FlutterMethodCall*)call result:(FlutterResult)result {
} else {
result(@(NO));
}
} else if([@"name" isEqualToString:call.method]) {
result([[UIDevice currentDevice] name]);
} else if([@"startScan" isEqualToString:call.method]) {
// Clear any existing scan results
[self.scannedPeripherals removeAllObjects];
Expand Down
4 changes: 4 additions & 0 deletions lib/src/flutter_blue.dart
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@ class FlutterBlue {
Future<bool> get isAvailable =>
_channel.invokeMethod('isAvailable').then<bool>((d) => d);

/// Return the friendly Bluetooth name of the local Bluetooth adapter
Future<String> get name =>
_channel.invokeMethod('name').then<String>((d) => d);

/// Checks if Bluetooth functionality is turned on
Future<bool> get isOn => _channel.invokeMethod('isOn').then<bool>((d) => d);

Expand Down