fixed bluetooth for android and refactored some files
This commit is contained in:
parent
5d4f45d4d6
commit
dca02824b9
|
@ -58,6 +58,9 @@ android {
|
|||
// TODO: Add your own signing config for the release build.
|
||||
// Signing with the debug keys for now, so `flutter run --release` works.
|
||||
signingConfig signingConfigs.debug
|
||||
// needed to fix bluetooth scan
|
||||
shrinkResources false
|
||||
minifyEnabled false
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -67,5 +70,5 @@ flutter {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
|
||||
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk8:$kotlin_version"
|
||||
}
|
||||
|
|
|
@ -3,8 +3,11 @@
|
|||
package="com.example.flutter_provisioning_for_iot">
|
||||
<uses-permission android:name="android.permission.INTERNET"/>
|
||||
<uses-permission android:name="android.permission.BLUETOOTH" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_SCAN" />
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_ADMIN" />
|
||||
<uses-permission android:name="android.permission.ACCESS_FINE_LOCATION"/>
|
||||
<!-- Needed to communicate with already-paired Bluetooth devices. (Android 12 upwards)-->
|
||||
<uses-permission android:name="android.permission.BLUETOOTH_CONNECT" />
|
||||
<application
|
||||
android:label="flutter_provisioning_for_iot"
|
||||
android:name="${applicationName}"
|
||||
|
|
|
@ -1,44 +0,0 @@
|
|||
import 'package:flutter_blue/flutter_blue.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
import 'dart:async';
|
||||
import 'dart:math';
|
||||
|
||||
import 'Sidebar.dart';
|
||||
|
||||
class BluetoothTest extends StatefulWidget {
|
||||
const BluetoothTest({super.key});
|
||||
|
||||
@override
|
||||
State<BluetoothTest> createState() => _BluetoothTest();
|
||||
}
|
||||
|
||||
class _BluetoothTest extends State<BluetoothTest> {
|
||||
FlutterBlue flutterBlue = FlutterBlue.instance;
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Bluetooth Test"),
|
||||
),
|
||||
body: Center(
|
||||
child: TextButton(
|
||||
onPressed: () {
|
||||
var subscription = flutterBlue.scanResults.listen((results) {
|
||||
// do something with scan results
|
||||
for (ScanResult r in results) {
|
||||
String scan = '"${r.device.name} found! rssi: ${r.rssi}"';
|
||||
debugPrint(scan);
|
||||
}
|
||||
});
|
||||
// Stop scanning
|
||||
flutterBlue.stopScan();
|
||||
|
||||
}, child: const Text("Scan Devices"),
|
||||
),
|
||||
),
|
||||
drawer: const Sidebar(),// This trailing comma makes auto-formatting nicer for build methods.
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
import 'package:flutter_blue/flutter_blue.dart';
|
||||
import 'package:flutter/material.dart';
|
||||
|
||||
import 'sidebar.dart';
|
||||
|
||||
class BluetoothTest extends StatefulWidget {
|
||||
const BluetoothTest({super.key});
|
||||
|
||||
@override
|
||||
State<BluetoothTest> createState() => _BluetoothTest();
|
||||
}
|
||||
|
||||
class _BluetoothTest extends State<BluetoothTest> {
|
||||
@override
|
||||
Widget build(BuildContext context) {
|
||||
return Scaffold(
|
||||
appBar: AppBar(
|
||||
title: const Text("Bluetooth Test"),
|
||||
),
|
||||
body: Center(
|
||||
child: TextButton(
|
||||
onPressed: () async {
|
||||
|
||||
FlutterBlue flutterBlue = FlutterBlue.instance;
|
||||
flutterBlue.startScan(timeout: const Duration(seconds: 4));
|
||||
|
||||
flutterBlue.scanResults.listen((results) async {
|
||||
// do something with scan results
|
||||
for (ScanResult r in results) {
|
||||
String scan = '"scan: ${r.device.name} found! rssi: ${r
|
||||
.rssi}"';
|
||||
debugPrint(scan);
|
||||
if(r.device.name == "Crusher ANC") {
|
||||
await r.device.connect();
|
||||
}
|
||||
}
|
||||
});
|
||||
// Stop scanning
|
||||
flutterBlue.stopScan();
|
||||
|
||||
}, child: const Text("Scan Devices"),
|
||||
),
|
||||
),
|
||||
drawer: const Sidebar(),// This trailing comma makes auto-formatting nicer for build methods.
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1,6 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_blue/flutter_blue.dart';
|
||||
import 'package:flutter_provisioning_for_iot/MainPage.dart';
|
||||
import 'package:flutter_provisioning_for_iot/main_page.dart';
|
||||
|
||||
void main() {
|
||||
runApp(const MainPage());
|
||||
|
|
|
@ -1,6 +1,5 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_provisioning_for_iot/Sidebar.dart';
|
||||
import 'package:flutter_blue/flutter_blue.dart';
|
||||
import 'package:flutter_provisioning_for_iot/sidebar.dart';
|
||||
|
||||
class MainPage extends StatelessWidget {
|
||||
const MainPage({super.key});
|
||||
|
@ -59,7 +58,7 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
),
|
||||
Text(
|
||||
'$_counter',
|
||||
style: Theme.of(context).textTheme.headline4,
|
||||
style: Theme.of(context).textTheme.headlineMedium,
|
||||
),
|
||||
],
|
||||
),
|
|
@ -2,7 +2,7 @@ import 'package:flutter/material.dart';
|
|||
import 'package:flutter/services.dart';
|
||||
import 'package:shared_preferences/shared_preferences.dart';
|
||||
|
||||
import 'Sidebar.dart';
|
||||
import 'sidebar.dart';
|
||||
|
||||
class Settings extends StatefulWidget {
|
||||
const Settings({Key? key}) : super(key: key);
|
|
@ -1,7 +1,7 @@
|
|||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_provisioning_for_iot/BluetoothTest.dart';
|
||||
import 'MainPage.dart';
|
||||
import 'Settings.dart';
|
||||
import 'package:flutter_provisioning_for_iot/bluetooth_test.dart';
|
||||
import 'main_page.dart';
|
||||
import 'settings.dart';
|
||||
|
||||
class Sidebar extends StatelessWidget {
|
||||
const Sidebar({Key? key}) : super(key: key);
|
Loading…
Reference in New Issue