Skip to content

Flutter Guide

This guide explains how to create a new Flutter app on Android and use the Abrevva Flutter plugin to scan for EVVA components.

  • Install or update Android Studio to its latest version.
  • Install or update Flutter to its latest version.
  • Set up a bluetooth capable physical device to run your app.

Use the flutter cli to setup a new Flutter app & run the App.

Terminal window
$ flutter create my_app --platforms=android && cd my_app
$ flutter run

In case you get gradle build errors you might need to exclude the META-INF files in the app’s build gradle file at the android level.

Show code
android/app/build.gradle.kts
packagingOptions {
...
resources.excludes.add("META-INF/*")
}

You should now see the example app.

New app

Execute the following commands to add the Abrevva Flutter plugin to the pubspec.yaml.

Terminal window
$ flutter pub add abrevva

Open the AndroidManifest.xml and add the required permissions and features at the manifest level.

android/app/src/main/AndroidManifest.xml
<uses-permission
android:maxSdkVersion="30"
android:name="android.permission.ACCESS_COARSE_LOCATION" />
<uses-permission
android:maxSdkVersion="30"
android:name="android.permission.ACCESS_FINE_LOCATION" />
<uses-permission
android:maxSdkVersion="30"
android:name="android.permission.BLUETOOTH" />
<uses-permission
android:maxSdkVersion="30"
android:name="android.permission.BLUETOOTH_ADMIN" />
<uses-permission
android:name="android.permission.BLUETOOTH_SCAN"
android:usesPermissionFlags="neverForLocation"
tools:targetApi="s" />
<uses-feature
android:name="android.hardware.bluetooth_le"
android:required="true" />

Open lib/main.dart to view the source of the created Demo App. To repurpose the HomePage, just replace the _MyHomePageState Class with the implementation below. Also include the two imports below.

Show code
import 'package:abrevva/abrevva.dart';
import 'package:abrevva/abrevva_param_classes.dart';
...
class _MyHomePageState extends State<MyHomePage> {
final _abrevvaBle = AbrevvaBle();
List<BleDevice> scanResultList = [];
Future<void> _scanForDevices() async {
scanResultList.clear();
return await _abrevvaBle.startScan(
onScanResult: (device) {
setState(() {
scanResultList.add(device);
});
},
);
}
@override
void initState() {
super.initState();
_abrevvaBle.initialize(false);
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(title: const Text('Ble Scanner (scroll down to scan)')),
body: Row(
children: [
RefreshIndicator(
onRefresh: _scanForDevices,
child: ListView.builder(
itemCount: scanResultList.length,
itemBuilder: (context, index) {
final result = scanResultList[index];
return ListTile(
title: Text(
"${result.advertisementData?.manufacturerData?.identifier}",
style: const TextStyle(color: Colors.blueAccent),
),
);
},
),
),
],
),
);
}
}

Scroll down to trigger the RefreshIndicator and you should see bluetooth results flying in.

Scan results

You can find the full example code on Github.