Skip to content

Commit

Permalink
support androidx
Browse files Browse the repository at this point in the history
  • Loading branch information
thon-ju committed Mar 24, 2020
1 parent 21c22e9 commit 28892b5
Show file tree
Hide file tree
Showing 33 changed files with 267 additions and 596 deletions.
2 changes: 1 addition & 1 deletion .metadata
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
# This file should be version controlled and should not be manually edited.

version:
revision: 68587a0916366e9512a78df22c44163d041dd5f3
revision: 9f5ff2306bb3e30b2b98eee79cd231b1336f41f4
channel: stable

project_type: plugin
52 changes: 1 addition & 51 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,53 +1,3 @@
## 2.0.0

* adaptation flutter 1.23.13.

## 1.2.0

* fix ios library auto import bug.

## 1.1.0

* opt ios config.


## 1.0.1

* opt log.


## 1.0.0

* support ios print label(tsc command) and receipt(esc command).

## 0.1.2

* support print label(tsc command).

## 0.1.1

* support more gprinter devices.

## 0.1.0

* finished android features.

## 0.0.5

* fixed some bugs, opt readme.

## 0.0.4

* fixed some bugs.

## 0.0.3

* opt android print, add status display.

## 0.0.2

* add android print support.

## 0.0.1

* initial release.
* TODO: Describe initial release.
22 changes: 1 addition & 21 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -1,21 +1 @@
MIT License

Copyright (c) 2019 thon-ju

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
TODO: Add your license here.
196 changes: 10 additions & 186 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,190 +1,14 @@
[![pub package](https://img.shields.io/pub/v/bluetooth_print.svg)](https://pub.dartlang.org/packages/bluetooth_print)
# bluetooth_print

A new flutter plugin project.

## Introduction
## Getting Started

BluetoothPrint is a bluetooth plugin for [Flutter](http://www.flutter.io), a new mobile SDK to help developers build bluetooth thermal printer apps for both iOS and Android.(for example, Gprinter pt-280、pt-380、gp-1324、gp-2120 eg.)
This project is a starting point for a Flutter
[plug-in package](https://flutter.dev/developing-packages/),
a specialized package that includes platform-specific implementation code for
Android and/or iOS.

### Underway(please suggest)
[ ] print x,y positions
[ ] set paper size
[ ] more print examples

### verison
2.0.0(flutter 1.12)
1.2.0(flutter 1.9)

## Features

| | Android | iOS | Description |
| :--------------- | :----------------: | :------------------: | :-------------------------------- |
| scan | :white_check_mark: | :white_check_mark: | Starts a scan for Bluetooth Low Energy devices. |
| connect | :white_check_mark: | :white_check_mark: | Establishes a connection to the device. |
| disconnect | :white_check_mark: | :white_check_mark: | Cancels an active or pending connection to the device. |
| state | :white_check_mark: | :white_check_mark: | Stream of state changes for the Bluetooth Device. |
| print test message | :white_check_mark: | :white_check_mark: | print device test message. |
| print text | :white_check_mark: | :white_check_mark: | print custom text, support layout. |
| print image | :white_check_mark: | :white_check_mark: | print image. |
| print qrcode | :white_check_mark: | :white_check_mark: | print qrcode,support change size. |
| print barcode | :white_check_mark: | :white_check_mark: | print barcode |


## Usage

[Example](https://github.com/thon-ju/bluetooth_print/blob/master/example/lib/main.dart)

To use this plugin :

- add the dependency to your [pubspec.yaml](https://github.com/thon-ju/bluetooth_print/blob/master/example/pubspec.yaml) file.

```yaml
dependencies:
flutter:
sdk: flutter
bluetooth_print:
```
- init a BluetoothPrint instance
```dart
import 'package:bluetooth_print/bluetooth_print.dart';
import 'package:bluetooth_print/bluetooth_print_model.dart';


BluetoothPrint bluetoothPrint = BluetoothPrint.instance;
```

### scan
```dart
// begin scan
bluetoothPrint.startScan(timeout: Duration(seconds: 4));
// get devices
StreamBuilder<List<BluetoothDevice>>(
stream: bluetoothPrint.scanResults,
initialData: [],
builder: (c, snapshot) => Column(
children: snapshot.data.map((d) => ListTile(
title: Text(d.name??''),
subtitle: Text(d.address),
onTap: () async {
setState(() {
_device = d;
});
},
trailing: _device!=null && _device.address == d.address?Icon(
Icons.check,
color: Colors.green,
):null,
)).toList(),
),
),
```

### connect
```dart
await bluetoothPrint.connect(_device);
```

### disconnect
```dart
await bluetoothPrint.disconnect();
```

### listen state
```dart
bluetoothPrint.state.listen((state) {
print('cur device status: $state');
switch (state) {
case BluetoothPrint.CONNECTED:
setState(() {
_connected = true;
});
break;
case BluetoothPrint.DISCONNECTED:
setState(() {
_connected = false;
});
break;
default:
break;
}
});
```

### print (esc command, receipt mode)
```dart
Map<String, dynamic> config = Map();
List<LineText> list = List();
list.add(LineText(type: LineText.TYPE_TEXT, content: 'A Title', weight: 1, align: LineText.ALIGN_CENTER,linefeed: 1));
list.add(LineText(type: LineText.TYPE_TEXT, content: 'this is conent left', weight: 0, align: LineText.ALIGN_LEFT,linefeed: 1));
list.add(LineText(type: LineText.TYPE_TEXT, content: 'this is conent right', align: LineText.ALIGN_RIGHT,linefeed: 1));
list.add(LineText(linefeed: 1));
list.add(LineText(type: LineText.TYPE_BARCODE, content: 'A12312112', size:10, align: LineText.ALIGN_CENTER, linefeed: 1));
list.add(LineText(linefeed: 1));
list.add(LineText(type: LineText.TYPE_QRCODE, content: 'qrcode i', size:10, align: LineText.ALIGN_CENTER, linefeed: 1));
list.add(LineText(linefeed: 1));
ByteData data = await rootBundle.load("assets/images/guide3.png");
List<int> imageBytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
String base64Image = base64Encode(imageBytes);
list.add(LineText(type: LineText.TYPE_IMAGE, content: base64Image, align: LineText.ALIGN_CENTER, linefeed: 1));
await bluetoothPrint.printReceipt(config, list);
```

### print (tsc command, label mode)
```dart
Map<String, dynamic> config = Map();
config['width'] = 40; // 标签宽度,单位mm
config['height'] = 70; // 标签高度,单位mm
config['gap'] = 2; // 标签间隔,单位mm
// x、y坐标位置,单位dpi,1mm=8dpi
List<LineText> list = List();
list.add(LineText(type: LineText.TYPE_TEXT, x:10, y:10, content: 'A Title'));
list.add(LineText(type: LineText.TYPE_TEXT, x:10, y:40, content: 'this is content'));
list.add(LineText(type: LineText.TYPE_QRCODE, x:10, y:70, content: 'qrcode i\n'));
list.add(LineText(type: LineText.TYPE_BARCODE, x:10, y:190, content: 'qrcode i\n'));
List<LineText> list1 = List();
ByteData data = await rootBundle.load("assets/images/guide3.png");
List<int> imageBytes = data.buffer.asUint8List(data.offsetInBytes, data.lengthInBytes);
String base64Image = base64Encode(imageBytes);
list1.add(LineText(type: LineText.TYPE_IMAGE, x:10, y:10, content: base64Image,));
await bluetoothPrint.printLabel(config, list);
await bluetoothPrint.printLabel(config, list1);
```


## Troubleshooting
#### ios import third party library
[Please Read link: https://stackoverflow.com/questions/19189463/cocoapods-podspec-issue)
*.podspec add:
```
# .a filename must begin with lib, eg. 'libXXX.a'
s.vendored_libraries = '**/*.a'
```

#### error:'State restoration of CBCentralManager is only allowed for applications that have specified the "bluetooth-central" background mode'
info.plist add:
```
<key>NSBluetoothAlwaysUsageDescription</key>
<string>Allow App use bluetooth?</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>Allow App use bluetooth?</string>
<key>UIBackgroundModes</key>
<array>
<string>bluetooth-central</string>
<string>bluetooth-peripheral</string>
</array>
```

## FAQ Support
you can join this [QQ](https://im.qq.com/index.shtml) group, feedback your problem
<img src="assets/bluetooth_print.png">

## Thanks For
- [flutter_blue](https://github.com/pauldemarco/flutter_blue)
For help getting started with Flutter, view our
[online documentation](https://flutter.dev/docs), which offers tutorials,
samples, guidance on mobile development, and a full API reference.
1 change: 0 additions & 1 deletion android/.gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
*.iml
.gradle
.idea
/local.properties
/.idea/workspace.xml
/.idea/libraries
Expand Down
24 changes: 5 additions & 19 deletions android/build.gradle
Original file line number Diff line number Diff line change
@@ -1,27 +1,14 @@
group 'com.xingcyun.bluetooth_print'
group 'com.example.bluetooth_print'
version '1.0'

def localProperties = new Properties()
def localPropertiesFile = rootProject.file('local.properties')
if (localPropertiesFile.exists()) {
localPropertiesFile.withReader('UTF-8') { reader ->
localProperties.load(reader)
}
}

def flutterRoot = localProperties.getProperty('flutter.sdk')
if (flutterRoot == null) {
throw new GradleException("Flutter SDK not found. Define location with flutter.sdk in the local.properties file.")
}

buildscript {
repositories {
google()
jcenter()
}

dependencies {
classpath 'com.android.tools.build:gradle:3.2.1'
classpath 'com.android.tools.build:gradle:3.5.0'
}
}

Expand All @@ -38,8 +25,8 @@ android {
compileSdkVersion 28

defaultConfig {
minSdkVersion 21
testInstrumentationRunner "android.support.test.runner.AndroidJUnitRunner"
minSdkVersion 16
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
}
lintOptions {
disable 'InvalidPackage'
Expand All @@ -49,6 +36,5 @@ android {
dependencies {
compile files('libs/gprintersdkv2.jar')
implementation files('libs/gprintersdkv2.jar')
implementation "androidx.core:core:1.1.0"
//implementation files("$flutterRoot/bin/cache/artifacts/engine/android-x64/flutter.jar")
}
}
4 changes: 3 additions & 1 deletion android/gradle.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,4 @@
org.gradle.jvmargs=-Xmx1536M

android.enableR8=true
android.useAndroidX=true
android.enableJetifier=true
1 change: 0 additions & 1 deletion bluetooth_print.iml
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
<excludeFolder url="file://$MODULE_DIR$/example/.dart_tool" />
<excludeFolder url="file://$MODULE_DIR$/example/.pub" />
<excludeFolder url="file://$MODULE_DIR$/example/build" />
<excludeFolder url="file://$MODULE_DIR$/example/ios/Flutter/App.framework/flutter_assets/packages" />
</content>
<orderEntry type="sourceFolder" forTests="false" />
<orderEntry type="library" name="Dart SDK" level="project" />
Expand Down
2 changes: 1 addition & 1 deletion example/.flutter-plugins-dependencies
Original file line number Diff line number Diff line change
@@ -1 +1 @@
{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"bluetooth_print","dependencies":[]},{"name":"path_provider","dependencies":[]}]}
{"_info":"// This is a generated file; do not edit or check into version control.","dependencyGraph":[{"name":"bluetooth_print","dependencies":[]}]}
Loading

0 comments on commit 28892b5

Please sign in to comment.