Update code for beacon (tour list -> visit)
This commit is contained in:
parent
3815a521fa
commit
d78372e728
@ -1,5 +1,7 @@
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
import 'package:mymuseum_visitapp/Components/LanguageSelection.dart';
|
import 'package:mymuseum_visitapp/Components/LanguageSelection.dart';
|
||||||
|
import 'package:mymuseum_visitapp/Helpers/requirement_state_controller.dart';
|
||||||
import 'package:mymuseum_visitapp/Models/visitContext.dart';
|
import 'package:mymuseum_visitapp/Models/visitContext.dart';
|
||||||
import 'package:mymuseum_visitapp/Screens/Home/home.dart';
|
import 'package:mymuseum_visitapp/Screens/Home/home.dart';
|
||||||
import 'package:mymuseum_visitapp/app_context.dart';
|
import 'package:mymuseum_visitapp/app_context.dart';
|
||||||
@ -19,7 +21,8 @@ class CustomAppBar extends StatefulWidget implements PreferredSizeWidget {
|
|||||||
Size get preferredSize => Size.fromHeight(_preferredHeight);
|
Size get preferredSize => Size.fromHeight(_preferredHeight);
|
||||||
}
|
}
|
||||||
|
|
||||||
class _CustomAppBarState extends State<CustomAppBar> {
|
class _CustomAppBarState extends State<CustomAppBar> with WidgetsBindingObserver {
|
||||||
|
final controller = Get.find<RequirementStateController>();
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
@ -36,6 +39,12 @@ class _CustomAppBarState extends State<CustomAppBar> {
|
|||||||
setState(() {
|
setState(() {
|
||||||
VisitAppContext visitAppContext = appContext.getContext();
|
VisitAppContext visitAppContext = appContext.getContext();
|
||||||
visitAppContext.configuration = null;
|
visitAppContext.configuration = null;
|
||||||
|
visitAppContext.isBeaconEnabled = false;
|
||||||
|
|
||||||
|
// TODO ADD CHECK IF RUNNING
|
||||||
|
print("PAUSE SCAAAAN");
|
||||||
|
controller.pauseScanning();
|
||||||
|
|
||||||
Navigator.of(context).pop();
|
Navigator.of(context).pop();
|
||||||
/*Navigator.of(context).pushReplacement(MaterialPageRoute(
|
/*Navigator.of(context).pushReplacement(MaterialPageRoute(
|
||||||
builder: (context) => const HomePage(),
|
builder: (context) => const HomePage(),
|
||||||
|
|||||||
@ -28,6 +28,7 @@ class _ScannerBoutonState extends State<ScannerBouton> {
|
|||||||
width: 85.0,
|
width: 85.0,
|
||||||
child: FittedBox(
|
child: FittedBox(
|
||||||
child: FloatingActionButton(
|
child: FloatingActionButton(
|
||||||
|
heroTag: "scanner",
|
||||||
onPressed: _onItemTapped,
|
onPressed: _onItemTapped,
|
||||||
tooltip: 'Scanner',
|
tooltip: 'Scanner',
|
||||||
backgroundColor: kBlue1,
|
backgroundColor: kBlue1,
|
||||||
|
|||||||
@ -2,17 +2,19 @@ import 'package:manager_api/api.dart';
|
|||||||
|
|
||||||
class BeaconSection {
|
class BeaconSection {
|
||||||
String? macAddress;
|
String? macAddress;
|
||||||
|
String? configurationId;
|
||||||
String? sectionId;
|
String? sectionId;
|
||||||
int? rssi;
|
int? rssi;
|
||||||
int? accuracy;
|
int? accuracy;
|
||||||
String? proximityUUID;
|
String? proximityUUID;
|
||||||
bool? found = false;
|
bool? found = false;
|
||||||
|
|
||||||
BeaconSection({this.macAddress, this.sectionId, this.rssi, this.accuracy, this.proximityUUID, this.found});
|
BeaconSection({this.macAddress, this.configurationId, this.sectionId, this.rssi, this.accuracy, this.proximityUUID, this.found});
|
||||||
|
|
||||||
Map<String, dynamic> toMap() {
|
Map<String, dynamic> toMap() {
|
||||||
return {
|
return {
|
||||||
'macAddress': macAddress,
|
'macAddress': macAddress,
|
||||||
|
'configurationId': configurationId,
|
||||||
'sectionId': sectionId,
|
'sectionId': sectionId,
|
||||||
'rssi': rssi,
|
'rssi': rssi,
|
||||||
'accuracy': accuracy,
|
'accuracy': accuracy,
|
||||||
@ -24,6 +26,7 @@ class BeaconSection {
|
|||||||
factory BeaconSection.fromJson(Map<String, dynamic> json) {
|
factory BeaconSection.fromJson(Map<String, dynamic> json) {
|
||||||
return BeaconSection(
|
return BeaconSection(
|
||||||
macAddress: json['macAddress'] as String,
|
macAddress: json['macAddress'] as String,
|
||||||
|
configurationId: json['configurationId'] as String,
|
||||||
sectionId: json['sectionId'] as String,
|
sectionId: json['sectionId'] as String,
|
||||||
rssi: json['rssi'] as int,
|
rssi: json['rssi'] as int,
|
||||||
accuracy: json['accuracy'] as int,
|
accuracy: json['accuracy'] as int,
|
||||||
@ -34,6 +37,6 @@ class BeaconSection {
|
|||||||
|
|
||||||
@override
|
@override
|
||||||
String toString() {
|
String toString() {
|
||||||
return 'BeaconSection{macAddress: $macAddress, sectionId: $sectionId, rssi: $rssi, accuracy: $accuracy, proximityUUID: $proximityUUID, found: $found}';
|
return 'BeaconSection{macAddress: $macAddress, sectionId: $sectionId, configurationId: $configurationId, rssi: $rssi, accuracy: $accuracy, proximityUUID: $proximityUUID, found: $found}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -10,6 +10,7 @@ class VisitAppContext with ChangeNotifier{
|
|||||||
ConfigurationDTO? configuration;
|
ConfigurationDTO? configuration;
|
||||||
List<String?>? sectionIds; // Use to valid QR code found
|
List<String?>? sectionIds; // Use to valid QR code found
|
||||||
List<BeaconSection?>? beaconSections;
|
List<BeaconSection?>? beaconSections;
|
||||||
|
bool isBeaconEnabled = false;
|
||||||
|
|
||||||
VisitAppContext({this.language, this.id, this.configuration, this.instanceId});
|
VisitAppContext({this.language, this.id, this.configuration, this.instanceId});
|
||||||
|
|
||||||
|
|||||||
@ -8,7 +8,6 @@ import 'package:mymuseum_visitapp/Components/Loading.dart';
|
|||||||
import 'package:mymuseum_visitapp/Components/SearchBox.dart';
|
import 'package:mymuseum_visitapp/Components/SearchBox.dart';
|
||||||
import 'package:mymuseum_visitapp/Components/SearchNumberBox.dart';
|
import 'package:mymuseum_visitapp/Components/SearchNumberBox.dart';
|
||||||
import 'package:mymuseum_visitapp/Helpers/DatabaseHelper.dart';
|
import 'package:mymuseum_visitapp/Helpers/DatabaseHelper.dart';
|
||||||
import 'package:mymuseum_visitapp/Helpers/requirement_state_controller.dart';
|
|
||||||
import 'package:mymuseum_visitapp/Helpers/translationHelper.dart';
|
import 'package:mymuseum_visitapp/Helpers/translationHelper.dart';
|
||||||
import 'package:mymuseum_visitapp/Models/visitContext.dart';
|
import 'package:mymuseum_visitapp/Models/visitContext.dart';
|
||||||
import 'package:mymuseum_visitapp/Screens/Article/article.dart';
|
import 'package:mymuseum_visitapp/Screens/Article/article.dart';
|
||||||
@ -31,8 +30,7 @@ class ConfigurationsList extends StatefulWidget {
|
|||||||
State<ConfigurationsList> createState() => _ConfigurationsListState();
|
State<ConfigurationsList> createState() => _ConfigurationsListState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _ConfigurationsListState extends State<ConfigurationsList> with WidgetsBindingObserver {
|
class _ConfigurationsListState extends State<ConfigurationsList> {
|
||||||
final controller = Get.find<RequirementStateController>();
|
|
||||||
List<ConfigurationDTO> configurations = [];
|
List<ConfigurationDTO> configurations = [];
|
||||||
List<String?> alreadyDownloaded = [];
|
List<String?> alreadyDownloaded = [];
|
||||||
VisitAppContext? visitAppContext;
|
VisitAppContext? visitAppContext;
|
||||||
@ -69,9 +67,6 @@ class _ConfigurationsListState extends State<ConfigurationsList> with WidgetsBin
|
|||||||
visitAppContext.sectionIds = List<SectionDTO>.from(await DatabaseHelper.instance.queryWithConfigurationId(DatabaseTableType.sections, visitAppContext.configuration!.id!)).map((e) => e.id).toList();
|
visitAppContext.sectionIds = List<SectionDTO>.from(await DatabaseHelper.instance.queryWithConfigurationId(DatabaseTableType.sections, visitAppContext.configuration!.id!)).map((e) => e.id).toList();
|
||||||
appContext.setContext(visitAppContext);
|
appContext.setContext(visitAppContext);
|
||||||
|
|
||||||
print("PAUSE SCANNN");
|
|
||||||
controller.pauseScanning();
|
|
||||||
|
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
@ -98,9 +93,6 @@ class _ConfigurationsListState extends State<ConfigurationsList> with WidgetsBin
|
|||||||
visitAppContext.sectionIds = sections.map((e) => e.id).toList();
|
visitAppContext.sectionIds = sections.map((e) => e.id).toList();
|
||||||
}
|
}
|
||||||
|
|
||||||
print("PAUSE SCANNN");
|
|
||||||
controller.pauseScanning();
|
|
||||||
|
|
||||||
Navigator.push(
|
Navigator.push(
|
||||||
context,
|
context,
|
||||||
MaterialPageRoute(
|
MaterialPageRoute(
|
||||||
@ -132,14 +124,14 @@ class _ConfigurationsListState extends State<ConfigurationsList> with WidgetsBin
|
|||||||
future: ApiService.getResource(appContext, configurations[index].imageId!),
|
future: ApiService.getResource(appContext, configurations[index].imageId!),
|
||||||
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
||||||
if (snapshot.connectionState == ConnectionState.done) {
|
if (snapshot.connectionState == ConnectionState.done) {
|
||||||
return snapshot.data != null ? Container(
|
print("RESULLT DATA");
|
||||||
child: ClipRRect(
|
print(snapshot.data);
|
||||||
borderRadius: const BorderRadius.only(topLeft: Radius.circular(20), bottomLeft: Radius.circular(20)),
|
return snapshot.data != null ? ClipRRect(
|
||||||
child: Image.memory(
|
borderRadius: const BorderRadius.only(topLeft: Radius.circular(20), bottomLeft: Radius.circular(20)),
|
||||||
base64Decode(snapshot.data.data!),
|
child: snapshot.data.data != null ? Image.memory(
|
||||||
fit: BoxFit.cover
|
base64Decode(snapshot.data.data!),
|
||||||
),
|
fit: BoxFit.cover
|
||||||
),
|
) : null,
|
||||||
) : const Text("");
|
) : const Text("");
|
||||||
} else if (snapshot.connectionState == ConnectionState.none) {
|
} else if (snapshot.connectionState == ConnectionState.none) {
|
||||||
return Text(TranslationHelper.getFromLocale("noData", appContext));
|
return Text(TranslationHelper.getFromLocale("noData", appContext));
|
||||||
|
|||||||
@ -4,8 +4,6 @@ import 'dart:io';
|
|||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:auto_size_text/auto_size_text.dart';
|
import 'package:auto_size_text/auto_size_text.dart';
|
||||||
import 'package:flutter/services.dart';
|
import 'package:flutter/services.dart';
|
||||||
import 'package:flutter_beacon/flutter_beacon.dart';
|
|
||||||
import 'package:get/get.dart';
|
|
||||||
import 'package:manager_api/api.dart';
|
import 'package:manager_api/api.dart';
|
||||||
import 'package:mymuseum_visitapp/Components/CustomAppBar.dart';
|
import 'package:mymuseum_visitapp/Components/CustomAppBar.dart';
|
||||||
import 'package:mymuseum_visitapp/Components/Loading.dart';
|
import 'package:mymuseum_visitapp/Components/Loading.dart';
|
||||||
@ -21,7 +19,6 @@ import 'package:mymuseum_visitapp/Services/downloadConfiguration.dart';
|
|||||||
import 'package:mymuseum_visitapp/app_context.dart';
|
import 'package:mymuseum_visitapp/app_context.dart';
|
||||||
import 'package:mymuseum_visitapp/client.dart';
|
import 'package:mymuseum_visitapp/client.dart';
|
||||||
import 'package:mymuseum_visitapp/constants.dart';
|
import 'package:mymuseum_visitapp/constants.dart';
|
||||||
import 'package:permission_handler/permission_handler.dart';
|
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import 'configurations_list.dart';
|
import 'configurations_list.dart';
|
||||||
@ -34,279 +31,23 @@ class HomePage extends StatefulWidget {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
|
class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
|
||||||
final controller = Get.find<RequirementStateController>();
|
|
||||||
StreamSubscription<BluetoothState>? _streamBluetooth;
|
|
||||||
int currentIndex = 0;
|
int currentIndex = 0;
|
||||||
|
|
||||||
List<ConfigurationDTO> configurations = [];
|
List<ConfigurationDTO> configurations = [];
|
||||||
List<String?> alreadyDownloaded = [];
|
List<String?> alreadyDownloaded = [];
|
||||||
VisitAppContext? visitAppContext;
|
VisitAppContext? visitAppContext;
|
||||||
|
|
||||||
StreamSubscription<RangingResult>? _streamRanging;
|
|
||||||
final _regionBeacons = <Region, List<Beacon>>{};
|
|
||||||
final _beacons = <Beacon>[];
|
|
||||||
//final controller = Get.find<RequirementStateController>();
|
|
||||||
|
|
||||||
@override
|
|
||||||
void initState() {
|
|
||||||
WidgetsBinding.instance.addObserver(this);
|
|
||||||
|
|
||||||
super.initState();
|
|
||||||
|
|
||||||
listeningState();
|
|
||||||
}
|
|
||||||
|
|
||||||
listeningState() async {
|
|
||||||
print('Listening to bluetooth state');
|
|
||||||
_streamBluetooth = flutterBeacon
|
|
||||||
.bluetoothStateChanged()
|
|
||||||
.listen((BluetoothState state) async {
|
|
||||||
controller.updateBluetoothState(state);
|
|
||||||
await checkAllRequirements();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
checkAllRequirements() async {
|
|
||||||
final bluetoothState = await flutterBeacon.bluetoothState;
|
|
||||||
controller.updateBluetoothState(bluetoothState);
|
|
||||||
print('BLUETOOTH $bluetoothState');
|
|
||||||
|
|
||||||
final authorizationStatus = await flutterBeacon.authorizationStatus;
|
|
||||||
controller.updateAuthorizationStatus(authorizationStatus);
|
|
||||||
print('AUTHORIZATION $authorizationStatus');
|
|
||||||
|
|
||||||
final locationServiceEnabled =
|
|
||||||
await flutterBeacon.checkLocationServicesIfEnabled;
|
|
||||||
controller.updateLocationService(locationServiceEnabled);
|
|
||||||
print('LOCATION SERVICE $locationServiceEnabled');
|
|
||||||
|
|
||||||
if (controller.bluetoothEnabled &&
|
|
||||||
controller.authorizationStatusOk &&
|
|
||||||
controller.locationServiceEnabled) {
|
|
||||||
print('STATE READY');
|
|
||||||
//if (currentIndex == 0) {
|
|
||||||
print('SCANNING');
|
|
||||||
//controller.startScanning();
|
|
||||||
|
|
||||||
|
|
||||||
var status = await Permission.bluetoothScan.status;
|
|
||||||
|
|
||||||
if (status.isDenied) {
|
|
||||||
print("IS DENIIIED");
|
|
||||||
// We didn't ask for permission yet or the permission has been denied before but not permanently.
|
|
||||||
}
|
|
||||||
|
|
||||||
// You can request multiple permissions at once.
|
|
||||||
Map<Permission, PermissionStatus> statuses = await [
|
|
||||||
Permission.bluetoothScan,
|
|
||||||
Permission.bluetoothConnect,
|
|
||||||
].request();
|
|
||||||
print(statuses[Permission.bluetoothScan]);
|
|
||||||
print(statuses[Permission.bluetoothConnect]);
|
|
||||||
|
|
||||||
print(status);
|
|
||||||
|
|
||||||
/*controller.startStream.listen((flag) {
|
|
||||||
if (flag == true) {
|
|
||||||
initScanBeacon();
|
|
||||||
}
|
|
||||||
});*/
|
|
||||||
/*} else {
|
|
||||||
print('BROADCASTING');
|
|
||||||
controller.startBroadcasting();
|
|
||||||
}*/
|
|
||||||
} else {
|
|
||||||
print('STATE NOT READY');
|
|
||||||
controller.pauseScanning();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
initScanBeacon() async {
|
|
||||||
await flutterBeacon.initializeScanning;
|
|
||||||
if (!controller.authorizationStatusOk ||
|
|
||||||
!controller.locationServiceEnabled ||
|
|
||||||
!controller.bluetoothEnabled) {
|
|
||||||
print(
|
|
||||||
'RETURNED, authorizationStatusOk=${controller.authorizationStatusOk}, '
|
|
||||||
'locationServiceEnabled=${controller.locationServiceEnabled}, '
|
|
||||||
'bluetoothEnabled=${controller.bluetoothEnabled}');
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
final regions = <Region>[
|
|
||||||
Region(
|
|
||||||
identifier: 'MyMuseumB'
|
|
||||||
),
|
|
||||||
];
|
|
||||||
|
|
||||||
if (_streamRanging != null) {
|
|
||||||
if (_streamRanging!.isPaused) {
|
|
||||||
_streamRanging?.resume();
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
_streamRanging =
|
|
||||||
flutterBeacon.ranging(regions).listen((RangingResult result) {
|
|
||||||
print(result);
|
|
||||||
if (mounted) {
|
|
||||||
|
|
||||||
print("visitAppContext");
|
|
||||||
print(visitAppContext);
|
|
||||||
print(visitAppContext!.beaconSections);
|
|
||||||
if(result.beacons.isNotEmpty && result.beacons.any((b) => b.proximity == "immediate" && visitAppContext!.beaconSections!.any((bs) => b.macAddress == bs!.macAddress) )) {
|
|
||||||
print("GOT ONE BEACON THAT I KNOOOOOOOOW");
|
|
||||||
print(result);
|
|
||||||
|
|
||||||
ScaffoldMessenger.of(context).showSnackBar(
|
|
||||||
SnackBar(content: Text("GOT ONE BEACON THAT I KNOOOOOOOOW"), backgroundColor: kBlue2),
|
|
||||||
);
|
|
||||||
}
|
|
||||||
//setState(() {
|
|
||||||
_regionBeacons[result.region] = result.beacons;
|
|
||||||
_beacons.clear();
|
|
||||||
_regionBeacons.values.forEach((list) {
|
|
||||||
_beacons.addAll(list);
|
|
||||||
});
|
|
||||||
_beacons.sort(_compareParameters);
|
|
||||||
//});
|
|
||||||
}
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
/*pauseScanBeacon() async {
|
|
||||||
_streamRanging?.pause();
|
|
||||||
if (_beacons.isNotEmpty) {
|
|
||||||
setState(() {
|
|
||||||
_beacons.clear();
|
|
||||||
});
|
|
||||||
}
|
|
||||||
}*/
|
|
||||||
|
|
||||||
int _compareParameters(Beacon a, Beacon b) {
|
|
||||||
int compare = a.proximityUUID.compareTo(b.proximityUUID);
|
|
||||||
|
|
||||||
if (compare == 0) {
|
|
||||||
compare = a.major.compareTo(b.major);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (compare == 0) {
|
|
||||||
compare = a.minor.compareTo(b.minor);
|
|
||||||
}
|
|
||||||
|
|
||||||
return compare;
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
|
||||||
void didChangeAppLifecycleState(AppLifecycleState state) async {
|
|
||||||
print('AppLifecycleState = $state');
|
|
||||||
if (state == AppLifecycleState.resumed) {
|
|
||||||
if (_streamBluetooth != null) {
|
|
||||||
if (_streamBluetooth!.isPaused) {
|
|
||||||
_streamBluetooth?.resume();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
await checkAllRequirements();
|
|
||||||
} else if (state == AppLifecycleState.paused) {
|
|
||||||
_streamBluetooth?.pause();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
Size size = MediaQuery.of(context).size;
|
Size size = MediaQuery.of(context).size;
|
||||||
final appContext = Provider.of<AppContext>(context);
|
final appContext = Provider.of<AppContext>(context);
|
||||||
visitAppContext = appContext.getContext();
|
visitAppContext = appContext.getContext();
|
||||||
|
|
||||||
/*if (controller.bluetoothEnabled &&
|
|
||||||
controller.authorizationStatusOk &&
|
|
||||||
controller.locationServiceEnabled) {
|
|
||||||
print("START SCANNING IN BUILD");
|
|
||||||
//controller.startScanning();
|
|
||||||
}*/
|
|
||||||
return Scaffold(
|
return Scaffold(
|
||||||
appBar: CustomAppBar(
|
appBar: CustomAppBar(
|
||||||
title: TranslationHelper.getFromLocale("visitTitle", appContext),
|
title: TranslationHelper.getFromLocale("visitTitle", appContext),
|
||||||
isHomeButton: false,
|
isHomeButton: false,
|
||||||
),
|
),
|
||||||
/*AppBar(
|
|
||||||
title: const Text('Flutter Beacon'),
|
|
||||||
centerTitle: false,
|
|
||||||
actions: <Widget>[
|
|
||||||
Obx(() {
|
|
||||||
if (!controller.locationServiceEnabled)
|
|
||||||
return IconButton(
|
|
||||||
tooltip: 'Not Determined',
|
|
||||||
icon: Icon(Icons.portable_wifi_off),
|
|
||||||
color: Colors.grey,
|
|
||||||
onPressed: () {},
|
|
||||||
);
|
|
||||||
|
|
||||||
if (!controller.authorizationStatusOk)
|
|
||||||
return IconButton(
|
|
||||||
tooltip: 'Not Authorized',
|
|
||||||
icon: Icon(Icons.portable_wifi_off),
|
|
||||||
color: Colors.red,
|
|
||||||
onPressed: () async {
|
|
||||||
await flutterBeacon.requestAuthorization;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
|
|
||||||
return IconButton(
|
|
||||||
tooltip: 'Authorized',
|
|
||||||
icon: Icon(Icons.wifi_tethering),
|
|
||||||
color: Colors.blue,
|
|
||||||
onPressed: () async {
|
|
||||||
await flutterBeacon.requestAuthorization;
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
Obx(() {
|
|
||||||
return IconButton(
|
|
||||||
tooltip: controller.locationServiceEnabled
|
|
||||||
? 'Location Service ON'
|
|
||||||
: 'Location Service OFF',
|
|
||||||
icon: Icon(
|
|
||||||
controller.locationServiceEnabled
|
|
||||||
? Icons.location_on
|
|
||||||
: Icons.location_off,
|
|
||||||
),
|
|
||||||
color:
|
|
||||||
controller.locationServiceEnabled ? Colors.blue : Colors.red,
|
|
||||||
onPressed: controller.locationServiceEnabled
|
|
||||||
? () {}
|
|
||||||
: handleOpenLocationSettings,
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
Obx(() {
|
|
||||||
final state = controller.bluetoothState.value;
|
|
||||||
|
|
||||||
if (state == BluetoothState.stateOn) {
|
|
||||||
return IconButton(
|
|
||||||
tooltip: 'Bluetooth ON',
|
|
||||||
icon: Icon(Icons.bluetooth_connected),
|
|
||||||
onPressed: () {},
|
|
||||||
color: Colors.lightBlueAccent,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (state == BluetoothState.stateOff) {
|
|
||||||
return IconButton(
|
|
||||||
tooltip: 'Bluetooth OFF',
|
|
||||||
icon: Icon(Icons.bluetooth),
|
|
||||||
onPressed: handleOpenBluetooth,
|
|
||||||
color: Colors.red,
|
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
return IconButton(
|
|
||||||
icon: Icon(Icons.bluetooth_disabled),
|
|
||||||
tooltip: 'Bluetooth State Unknown',
|
|
||||||
onPressed: () {},
|
|
||||||
color: Colors.grey,
|
|
||||||
);
|
|
||||||
}),
|
|
||||||
],
|
|
||||||
),*/
|
|
||||||
body: SingleChildScrollView(
|
body: SingleChildScrollView(
|
||||||
child: SizedBox(
|
child: SizedBox(
|
||||||
width: size.width,
|
width: size.width,
|
||||||
@ -316,21 +57,6 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
|
|||||||
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
builder: (context, AsyncSnapshot<dynamic> snapshot) {
|
||||||
if (snapshot.connectionState == ConnectionState.done) {
|
if (snapshot.connectionState == ConnectionState.done) {
|
||||||
configurations = List<ConfigurationDTO>.from(snapshot.data).where((configuration) => configuration.isMobile!).toList();
|
configurations = List<ConfigurationDTO>.from(snapshot.data).where((configuration) => configuration.isMobile!).toList();
|
||||||
|
|
||||||
|
|
||||||
controller.startStream.listen((flag) async {
|
|
||||||
print(flag);
|
|
||||||
if (flag == true) {
|
|
||||||
print("FIIIIIIREEEE ---------------");
|
|
||||||
await initScanBeacon();
|
|
||||||
controller.startScanning();
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
||||||
|
|
||||||
controller.startScanning();
|
|
||||||
|
|
||||||
|
|
||||||
return RefreshIndicator (
|
return RefreshIndicator (
|
||||||
onRefresh: () {
|
onRefresh: () {
|
||||||
setState(() {});
|
setState(() {});
|
||||||
@ -389,56 +115,6 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
handleOpenLocationSettings() async {
|
|
||||||
if (Platform.isAndroid) {
|
|
||||||
await flutterBeacon.openLocationSettings;
|
|
||||||
} else if (Platform.isIOS) {
|
|
||||||
await showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (context) {
|
|
||||||
return AlertDialog(
|
|
||||||
title: Text('Location Services Off'),
|
|
||||||
content: Text(
|
|
||||||
'Please enable Location Services on Settings > Privacy > Location Services.',
|
|
||||||
),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
child: Text('OK'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
handleOpenBluetooth() async {
|
|
||||||
if (Platform.isAndroid) {
|
|
||||||
try {
|
|
||||||
await flutterBeacon.openBluetoothSettings;
|
|
||||||
} on PlatformException catch (e) {
|
|
||||||
print(e);
|
|
||||||
}
|
|
||||||
} else if (Platform.isIOS) {
|
|
||||||
await showDialog(
|
|
||||||
context: context,
|
|
||||||
builder: (context) {
|
|
||||||
return AlertDialog(
|
|
||||||
title: Text('Bluetooth is Off'),
|
|
||||||
content: Text('Please enable Bluetooth on Settings > Bluetooth.'),
|
|
||||||
actions: [
|
|
||||||
TextButton(
|
|
||||||
onPressed: () => Navigator.pop(context),
|
|
||||||
child: Text('OK'),
|
|
||||||
),
|
|
||||||
],
|
|
||||||
);
|
|
||||||
},
|
|
||||||
);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
Future<List<ConfigurationDTO>?> getConfigurationsCall(Client client, AppContext appContext) async {
|
Future<List<ConfigurationDTO>?> getConfigurationsCall(Client client, AppContext appContext) async {
|
||||||
bool isOnline = await hasNetwork();
|
bool isOnline = await hasNetwork();
|
||||||
VisitAppContext visitAppContext = appContext.getContext();
|
VisitAppContext visitAppContext = appContext.getContext();
|
||||||
@ -460,7 +136,7 @@ class _HomePageState extends State<HomePage> with WidgetsBindingObserver {
|
|||||||
if(visitAppContext.beaconSections == null) {
|
if(visitAppContext.beaconSections == null) {
|
||||||
List<SectionDTO>? sections = await ApiService.getAllBeacons(client, visitAppContext.instanceId!);
|
List<SectionDTO>? sections = await ApiService.getAllBeacons(client, visitAppContext.instanceId!);
|
||||||
if(sections != null && sections.isNotEmpty) {
|
if(sections != null && sections.isNotEmpty) {
|
||||||
List<BeaconSection> beaconSections = sections.map((e) => BeaconSection(macAddress: e.beaconId, sectionId: e.id)).toList();
|
List<BeaconSection> beaconSections = sections.map((e) => BeaconSection(macAddress: e.beaconId, configurationId: e.configurationId, sectionId: e.id)).toList();
|
||||||
visitAppContext.beaconSections = beaconSections;
|
visitAppContext.beaconSections = beaconSections;
|
||||||
print("Got some Beacons for you");
|
print("Got some Beacons for you");
|
||||||
print(beaconSections);
|
print(beaconSections);
|
||||||
|
|||||||
@ -1,11 +1,19 @@
|
|||||||
|
import 'dart:async';
|
||||||
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
|
import 'package:flutter_beacon/flutter_beacon.dart';
|
||||||
|
import 'package:get/get.dart';
|
||||||
import 'package:manager_api/api.dart';
|
import 'package:manager_api/api.dart';
|
||||||
import 'package:mymuseum_visitapp/Components/CustomAppBar.dart';
|
import 'package:mymuseum_visitapp/Components/CustomAppBar.dart';
|
||||||
import 'package:mymuseum_visitapp/Components/ScannerBouton.dart';
|
import 'package:mymuseum_visitapp/Components/ScannerBouton.dart';
|
||||||
|
import 'package:mymuseum_visitapp/Helpers/requirement_state_controller.dart';
|
||||||
import 'package:mymuseum_visitapp/Helpers/translationHelper.dart';
|
import 'package:mymuseum_visitapp/Helpers/translationHelper.dart';
|
||||||
import 'package:mymuseum_visitapp/Models/visitContext.dart';
|
import 'package:mymuseum_visitapp/Models/visitContext.dart';
|
||||||
import 'package:mymuseum_visitapp/app_context.dart';
|
import 'package:mymuseum_visitapp/app_context.dart';
|
||||||
import 'package:mymuseum_visitapp/constants.dart';
|
import 'package:mymuseum_visitapp/constants.dart';
|
||||||
|
import 'package:permission_handler/permission_handler.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
|
|
||||||
import 'components/body.dart';
|
import 'components/body.dart';
|
||||||
@ -19,9 +27,196 @@ class VisitPage extends StatefulWidget {
|
|||||||
State<VisitPage> createState() => _VisitPageState();
|
State<VisitPage> createState() => _VisitPageState();
|
||||||
}
|
}
|
||||||
|
|
||||||
class _VisitPageState extends State<VisitPage> {
|
class _VisitPageState extends State<VisitPage> with WidgetsBindingObserver {
|
||||||
ConfigurationDTO? configuration;
|
ConfigurationDTO? configuration;
|
||||||
|
|
||||||
|
// Beacon specific
|
||||||
|
final controller = Get.find<RequirementStateController>();
|
||||||
|
StreamSubscription<BluetoothState>? _streamBluetooth;
|
||||||
|
StreamSubscription<RangingResult>? _streamRanging;
|
||||||
|
final _regionBeacons = <Region, List<Beacon>>{};
|
||||||
|
final _beacons = <Beacon>[];
|
||||||
|
StreamSubscription? listener;
|
||||||
|
|
||||||
|
@override
|
||||||
|
void initState() {
|
||||||
|
WidgetsBinding.instance.addObserver(this);
|
||||||
|
|
||||||
|
super.initState();
|
||||||
|
|
||||||
|
listeningState();
|
||||||
|
}
|
||||||
|
|
||||||
|
listeningState() async {
|
||||||
|
print('Listening to bluetooth state');
|
||||||
|
_streamBluetooth = flutterBeacon
|
||||||
|
.bluetoothStateChanged()
|
||||||
|
.listen((BluetoothState state) async {
|
||||||
|
controller.updateBluetoothState(state);
|
||||||
|
await checkAllRequirements();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
checkAllRequirements() async {
|
||||||
|
final bluetoothState = await flutterBeacon.bluetoothState;
|
||||||
|
controller.updateBluetoothState(bluetoothState);
|
||||||
|
print('BLUETOOTH $bluetoothState');
|
||||||
|
|
||||||
|
final authorizationStatus = await flutterBeacon.authorizationStatus;
|
||||||
|
controller.updateAuthorizationStatus(authorizationStatus);
|
||||||
|
print('AUTHORIZATION $authorizationStatus');
|
||||||
|
|
||||||
|
final locationServiceEnabled =
|
||||||
|
await flutterBeacon.checkLocationServicesIfEnabled;
|
||||||
|
controller.updateLocationService(locationServiceEnabled);
|
||||||
|
print('LOCATION SERVICE $locationServiceEnabled');
|
||||||
|
|
||||||
|
if (controller.bluetoothEnabled &&
|
||||||
|
controller.authorizationStatusOk &&
|
||||||
|
controller.locationServiceEnabled) {
|
||||||
|
print('STATE READY');
|
||||||
|
//if (currentIndex == 0) {
|
||||||
|
print('SCANNING');
|
||||||
|
//controller.startScanning();
|
||||||
|
|
||||||
|
|
||||||
|
var status = await Permission.bluetoothScan.status;
|
||||||
|
|
||||||
|
if (status.isDenied) {
|
||||||
|
print("IS DENIIIED");
|
||||||
|
// We didn't ask for permission yet or the permission has been denied before but not permanently.
|
||||||
|
}
|
||||||
|
|
||||||
|
// You can request multiple permissions at once.
|
||||||
|
Map<Permission, PermissionStatus> statuses = await [
|
||||||
|
Permission.bluetoothScan,
|
||||||
|
Permission.bluetoothConnect,
|
||||||
|
].request();
|
||||||
|
print(statuses[Permission.bluetoothScan]);
|
||||||
|
print(statuses[Permission.bluetoothConnect]);
|
||||||
|
|
||||||
|
print(status);
|
||||||
|
|
||||||
|
/*controller.startStream.listen((flag) {
|
||||||
|
if (flag == true) {
|
||||||
|
initScanBeacon();
|
||||||
|
}
|
||||||
|
});*/
|
||||||
|
/*} else {
|
||||||
|
print('BROADCASTING');
|
||||||
|
controller.startBroadcasting();
|
||||||
|
}*/
|
||||||
|
} else {
|
||||||
|
print('STATE NOT READY');
|
||||||
|
controller.pauseScanning();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
initScanBeacon(VisitAppContext visitAppContext) async {
|
||||||
|
await flutterBeacon.initializeScanning;
|
||||||
|
if (!controller.authorizationStatusOk ||
|
||||||
|
!controller.locationServiceEnabled ||
|
||||||
|
!controller.bluetoothEnabled) {
|
||||||
|
print(
|
||||||
|
'RETURNED, authorizationStatusOk=${controller.authorizationStatusOk}, '
|
||||||
|
'locationServiceEnabled=${controller.locationServiceEnabled}, '
|
||||||
|
'bluetoothEnabled=${controller.bluetoothEnabled}');
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
final regions = <Region>[
|
||||||
|
Region(
|
||||||
|
identifier: 'MyMuseumB'
|
||||||
|
),
|
||||||
|
];
|
||||||
|
|
||||||
|
if (_streamRanging != null) {
|
||||||
|
if (_streamRanging!.isPaused) {
|
||||||
|
_streamRanging?.resume();
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
_streamRanging =
|
||||||
|
flutterBeacon.ranging(regions).listen((RangingResult result) {
|
||||||
|
//print(result);
|
||||||
|
if (mounted) {
|
||||||
|
|
||||||
|
//print("visitAppContext");
|
||||||
|
//print(visitAppContext);
|
||||||
|
//print(visitAppContext!.beaconSections);
|
||||||
|
|
||||||
|
if(result.beacons.isNotEmpty) {
|
||||||
|
print(result);
|
||||||
|
print(result.beacons.map((b) => b.macAddress));
|
||||||
|
print(visitAppContext.beaconSections!.map((bb) => bb!.macAddress));
|
||||||
|
|
||||||
|
var beaconList = visitAppContext.beaconSections!.where((bs) => result.beacons.any((element) => element.macAddress == bs!.macAddress));
|
||||||
|
if(beaconList.isNotEmpty)
|
||||||
|
{
|
||||||
|
print("GOT ONE BEACON THAT I KNOOOOOOOOW");
|
||||||
|
print(beaconList);
|
||||||
|
|
||||||
|
// TODO SORT BY COMPARE
|
||||||
|
|
||||||
|
print("BEFORE SNACKBAR");
|
||||||
|
ScaffoldMessenger.of(context).showSnackBar(
|
||||||
|
SnackBar(content: Text('BEACON - ${result.beacons.first.macAddress} - ${result.beacons.first.accuracy} - ${result.beacons.first.proximity.name}'), backgroundColor: kBlue2),
|
||||||
|
);
|
||||||
|
|
||||||
|
print("AFTER SNACKBAR");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//setState(() {
|
||||||
|
/*_regionBeacons[result.region] = result.beacons;
|
||||||
|
_beacons.clear();
|
||||||
|
_regionBeacons.values.forEach((list) {
|
||||||
|
_beacons.addAll(list);
|
||||||
|
});
|
||||||
|
_beacons.sort(_compareParameters);*/
|
||||||
|
//});
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/*pauseScanBeacon() async {
|
||||||
|
_streamRanging?.pause();
|
||||||
|
if (_beacons.isNotEmpty) {
|
||||||
|
setState(() {
|
||||||
|
_beacons.clear();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}*/
|
||||||
|
|
||||||
|
int _compareParameters(Beacon a, Beacon b) {
|
||||||
|
int compare = a.proximityUUID.compareTo(b.proximityUUID);
|
||||||
|
|
||||||
|
if (compare == 0) {
|
||||||
|
compare = a.major.compareTo(b.major);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (compare == 0) {
|
||||||
|
compare = a.minor.compareTo(b.minor);
|
||||||
|
}
|
||||||
|
|
||||||
|
return compare;
|
||||||
|
}
|
||||||
|
|
||||||
|
@override
|
||||||
|
void didChangeAppLifecycleState(AppLifecycleState state) async {
|
||||||
|
print('AppLifecycleState = $state');
|
||||||
|
if (state == AppLifecycleState.resumed) {
|
||||||
|
if (_streamBluetooth != null) {
|
||||||
|
if (_streamBluetooth!.isPaused) {
|
||||||
|
_streamBluetooth?.resume();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
await checkAllRequirements();
|
||||||
|
} else if (state == AppLifecycleState.paused) {
|
||||||
|
_streamBluetooth?.pause();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
/*Widget build(BuildContext context) {
|
/*Widget build(BuildContext context) {
|
||||||
return new WillPopScope(
|
return new WillPopScope(
|
||||||
@ -37,11 +232,30 @@ class _VisitPageState extends State<VisitPage> {
|
|||||||
),
|
),
|
||||||
);
|
);
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
@override
|
||||||
|
void onDispose() {
|
||||||
|
print("DISPOSE VISIT PAGE");
|
||||||
|
|
||||||
|
super.dispose();
|
||||||
|
}
|
||||||
|
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
final appContext = Provider.of<AppContext>(context);
|
final appContext = Provider.of<AppContext>(context);
|
||||||
VisitAppContext visitAppContext = appContext.getContext();
|
VisitAppContext visitAppContext = appContext.getContext();
|
||||||
configuration = visitAppContext.configuration;
|
configuration = visitAppContext.configuration;
|
||||||
|
|
||||||
|
//if(visitAppContext.isBeaconEnabled) {
|
||||||
|
listener = controller.startStream.listen((flag) async {
|
||||||
|
print(flag);
|
||||||
|
if (flag == true) {
|
||||||
|
print("FIIIIIIREEEE ---------------");
|
||||||
|
await initScanBeacon(visitAppContext);
|
||||||
|
controller.startScanning();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
//}
|
||||||
|
|
||||||
return /*WillPopScope(
|
return /*WillPopScope(
|
||||||
child:*/ Scaffold(
|
child:*/ Scaffold(
|
||||||
appBar: CustomAppBar(
|
appBar: CustomAppBar(
|
||||||
@ -50,9 +264,124 @@ class _VisitPageState extends State<VisitPage> {
|
|||||||
),
|
),
|
||||||
backgroundColor: kBackgroundGrey,
|
backgroundColor: kBackgroundGrey,
|
||||||
body: Body(configurationId: configuration!.id), // TODO handle error..
|
body: Body(configurationId: configuration!.id), // TODO handle error..
|
||||||
floatingActionButton: ScannerBouton(appContext: appContext),
|
floatingActionButton: Stack(
|
||||||
|
children: [
|
||||||
|
visitAppContext.beaconSections!.where((bs) => bs!.configurationId == visitAppContext.configuration!.id).isNotEmpty ? Align(
|
||||||
|
alignment: Alignment.bottomRight,
|
||||||
|
child: Padding(
|
||||||
|
padding: const EdgeInsets.only(right: 90, bottom: 1),
|
||||||
|
child: Container(
|
||||||
|
height: 65.0,
|
||||||
|
width: 65.0,
|
||||||
|
child: FittedBox(
|
||||||
|
child: FloatingActionButton(
|
||||||
|
heroTag: "beacon",
|
||||||
|
onPressed: () {
|
||||||
|
if(!visitAppContext.isBeaconEnabled) {
|
||||||
|
print("Start Scan");
|
||||||
|
controller.startScanning();
|
||||||
|
listener!.resume();
|
||||||
|
|
||||||
|
visitAppContext.isBeaconEnabled = true;
|
||||||
|
appContext.setContext(visitAppContext);
|
||||||
|
} else {
|
||||||
|
print("Pause Scan");
|
||||||
|
controller.pauseScanning(); // PAUSE OR DISPOSE ?
|
||||||
|
//controller.dispose(); // PAUSE OR DISPOSE ?
|
||||||
|
print(controller.pauseStream);
|
||||||
|
listener!.cancel();
|
||||||
|
listener!.pause();
|
||||||
|
//controller.removeListenerId(listener.i, () { });
|
||||||
|
visitAppContext.isBeaconEnabled = false;
|
||||||
|
appContext.setContext(visitAppContext);
|
||||||
|
}
|
||||||
|
},
|
||||||
|
tooltip: 'Beacon',
|
||||||
|
backgroundColor: visitAppContext.isBeaconEnabled ? kBlue1 : Colors.grey,
|
||||||
|
child: const Icon(Icons.my_location),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
) : const SizedBox(),
|
||||||
|
Align(
|
||||||
|
alignment: Alignment.bottomRight,
|
||||||
|
child: ScannerBouton(appContext: appContext),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
),/*Padding(
|
||||||
|
padding: const EdgeInsets.only(right: 10),
|
||||||
|
child: Row(
|
||||||
|
children: [
|
||||||
|
Container(
|
||||||
|
height: 65.0,
|
||||||
|
width: 65.0,
|
||||||
|
child: FittedBox(
|
||||||
|
child: FloatingActionButton(
|
||||||
|
heroTag: "beacon",
|
||||||
|
onPressed: () {},
|
||||||
|
tooltip: 'Beacon',
|
||||||
|
backgroundColor: kBlue1,
|
||||||
|
child: const Icon(Icons.qr_code_scanner),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
),
|
||||||
|
ScannerBouton(appContext: appContext),
|
||||||
|
],
|
||||||
|
),
|
||||||
|
),*/
|
||||||
);//,
|
);//,
|
||||||
//onWillPop: () async => false,
|
//onWillPop: () async => false,
|
||||||
//);
|
//);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
handleOpenLocationSettings() async {
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
await flutterBeacon.openLocationSettings;
|
||||||
|
} else if (Platform.isIOS) {
|
||||||
|
await showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text('Location Services Off'),
|
||||||
|
content: Text(
|
||||||
|
'Please enable Location Services on Settings > Privacy > Location Services.',
|
||||||
|
),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
child: Text('OK'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
handleOpenBluetooth() async {
|
||||||
|
if (Platform.isAndroid) {
|
||||||
|
try {
|
||||||
|
await flutterBeacon.openBluetoothSettings;
|
||||||
|
} on PlatformException catch (e) {
|
||||||
|
print(e);
|
||||||
|
}
|
||||||
|
} else if (Platform.isIOS) {
|
||||||
|
await showDialog(
|
||||||
|
context: context,
|
||||||
|
builder: (context) {
|
||||||
|
return AlertDialog(
|
||||||
|
title: Text('Bluetooth is Off'),
|
||||||
|
content: Text('Please enable Bluetooth on Settings > Bluetooth.'),
|
||||||
|
actions: [
|
||||||
|
TextButton(
|
||||||
|
onPressed: () => Navigator.pop(context),
|
||||||
|
child: Text('OK'),
|
||||||
|
),
|
||||||
|
],
|
||||||
|
);
|
||||||
|
},
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user