添加打印机筛选,删除权限插件

master
章文轩 2 years ago
parent 0094f481f3
commit da66b76e8d

@ -2,7 +2,6 @@
<library name="Flutter Plugins" type="FlutterPluginsLibraryType"> <library name="Flutter Plugins" type="FlutterPluginsLibraryType">
<CLASSES> <CLASSES>
<root url="file://$PROJECT_DIR$" /> <root url="file://$PROJECT_DIR$" />
<root url="file://$PROJECT_DIR$/../.pub-cache/hosted/pub.dartlang.org/permission_handler-7.0.0" />
</CLASSES> </CLASSES>
<JAVADOC /> <JAVADOC />
<SOURCES /> <SOURCES />

@ -104,7 +104,8 @@ public class Bluetooth {
String name = remoteDevice.getName(); String name = remoteDevice.getName();
System.out.println(name); System.out.println(name);
System.out.println(remoteDevice.getAddress()); System.out.println(remoteDevice.getAddress());
if (remoteDevice != null && name != null) { System.out.println(remoteDevice.getBluetoothClass().getMajorDeviceClass());
if (remoteDevice != null && name != null&&remoteDevice.getBluetoothClass().getMajorDeviceClass()==1536) {
if (remoteDevice.getBondState() != BluetoothDevice.BOND_BONDED) { if (remoteDevice.getBondState() != BluetoothDevice.BOND_BONDED) {
key = "{" + "\"name\":" + "\"" + name + "\"" + "," key = "{" + "\"name\":" + "\"" + name + "\"" + ","
+ "\"address\":" + "\"" + remoteDevice.getAddress() + "\"" + "," + "\"address\":" + "\"" + remoteDevice.getAddress() + "\"" + ","

@ -6,7 +6,7 @@ import 'package:hy_printer/device.dart';
import 'package:hy_printer/dj_printer.dart'; import 'package:hy_printer/dj_printer.dart';
import 'package:hy_printer/hy_printer.dart'; import 'package:hy_printer/hy_printer.dart';
import 'package:hy_printer_example/scan_page.dart'; import 'package:hy_printer_example/scan_page.dart';
import 'package:permission_handler/permission_handler.dart'; // import 'package:permission_handler/permission_handler.dart';
void main() { void main() {
runApp(const MyApp()); runApp(const MyApp());
@ -32,22 +32,22 @@ class _MyAppState extends State<MyApp> {
// setState(() {}); // setState(() {});
// } // }
Future<void> initPlatformState() async { Future<void> initPlatformState() async {
var per = await Permission.bluetooth.isGranted; // var per = await Permission.bluetooth.isGranted;
if (!per) { // if (!per) {
Permission.bluetooth.request(); // Permission.bluetooth.request();
} // }
var pers = await Permission.locationWhenInUse.isGranted; // var pers = await Permission.locationWhenInUse.isGranted;
if (!pers) { // if (!pers) {
Permission.locationWhenInUse.request(); // Permission.locationWhenInUse.request();
} // }
var per1 = await Permission.bluetoothScan.isGranted; // var per1 = await Permission.bluetoothScan.isGranted;
if (!per1) { // if (!per1) {
Permission.bluetoothScan.request(); // Permission.bluetoothScan.request();
} // }
var per2 = await Permission.bluetoothConnect.isGranted; // var per2 = await Permission.bluetoothConnect.isGranted;
if (!per2) { // if (!per2) {
Permission.bluetoothConnect.request(); // Permission.bluetoothConnect.request();
} // }
DjPrinter().init(); DjPrinter().init();
DjPrinter().addDiscoveryListen(onReceive: (data) { DjPrinter().addDiscoveryListen(onReceive: (data) {
@ -99,13 +99,14 @@ class _MyAppState extends State<MyApp> {
), ),
...devices ...devices
.map((e) => TextButton( .map((e) => TextButton(
onPressed: () { onPressed: ()async {
[Permission.bluetoothConnect,].request().then((value) async { // [Permission.bluetoothConnect,].request().then((value) async {
print("===============${value[Permission.bluetoothConnect]}"); // print("===============${value[Permission.bluetoothConnect]}");
if(value[Permission.bluetoothConnect]!=PermissionStatus.denied){ // if(value[Permission.bluetoothConnect]!=PermissionStatus.denied){
await DjPrinter().connect(e.address); //
} // }
}); // });
await DjPrinter().connect(e.address);
// //
}, },

@ -116,27 +116,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.1" version: "1.8.1"
permission_handler:
dependency: "direct main"
description:
name: permission_handler
url: "https://pub.dartlang.org"
source: hosted
version: "7.0.0"
permission_handler_platform_interface:
dependency: transitive
description:
name: permission_handler_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "3.7.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
@ -193,4 +172,4 @@ packages:
version: "2.1.2" version: "2.1.2"
sdks: sdks:
dart: ">=2.17.0-0 <3.0.0" dart: ">=2.17.0-0 <3.0.0"
flutter: ">=2.5.0" flutter: ">=1.20.0"

@ -17,7 +17,7 @@ environment:
dependencies: dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
permission_handler: 7.0.0 # permission_handler: 10.0.0
hy_printer: hy_printer:
# When depending on this package from a real application you should use: # When depending on this package from a real application you should use:
# hy_printer: ^x.y.z # hy_printer: ^x.y.z

@ -102,27 +102,6 @@ packages:
url: "https://pub.dartlang.org" url: "https://pub.dartlang.org"
source: hosted source: hosted
version: "1.8.1" version: "1.8.1"
permission_handler:
dependency: "direct main"
description:
name: permission_handler
url: "https://pub.dartlang.org"
source: hosted
version: "7.0.0"
permission_handler_platform_interface:
dependency: transitive
description:
name: permission_handler_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "3.7.0"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "2.1.2"
sky_engine: sky_engine:
dependency: transitive dependency: transitive
description: flutter description: flutter
@ -179,4 +158,4 @@ packages:
version: "2.1.2" version: "2.1.2"
sdks: sdks:
dart: ">=2.17.0-0 <3.0.0" dart: ">=2.17.0-0 <3.0.0"
flutter: ">=2.5.0" flutter: ">=1.20.0"

@ -11,7 +11,7 @@ dependencies:
flutter: flutter:
sdk: flutter sdk: flutter
# flutter_blue_plus: ^1.3.1 # flutter_blue_plus: ^1.3.1
permission_handler: 7.0.0 # permission_handler: 10.0.0
dev_dependencies: dev_dependencies:
flutter_test: flutter_test:
sdk: flutter sdk: flutter

Loading…
Cancel
Save