btprinter 0.0.7

  • Readme
  • Changelog
  • Example
  • Installing
  • 77

btprinter #

A new flutter plugin project.

Getting Started #

This project is a starting point for a Flutter plug-in package, a specialized package that includes platform-specific implementation code for Android and/or iOS.

For help getting started with Flutter, view our online documentation, which offers tutorials, samples, guidance on mobile development, and a full API reference.

0.0.1 #

  • TODO: Describe initial release.

example/lib/main.dart

import 'package:flutter/material.dart';
import 'dart:async';
import 'package:flutter/services.dart';
import 'package:btprinter/btprinter.dart';

void main() {
  runApp(TestApp());
}

class TestApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Welcome to Flutter',
      debugShowCheckedModeBanner: false,
      home: MyApp(),
    );
  }
}

class MyApp extends StatefulWidget {
  @override
  _MyAppState createState() => _MyAppState();
}

class _MyAppState extends State<MyApp> {
  String _result = 'failed';
  String _resultConnect = 'failed';
  Stream<int> _connectListener;

  @override
  void initState() {
    super.initState();
  }

  Future<void> setDevice(String _address) async {
    String result;

    try {
      result = await Btprinter.connectDevices(_address);
    } on PlatformException {
      result = "Failed";
    }

    setState(() {
      _result = result;
    });
  }

  void _onLoading() {
    showDialog(
      context: context,
      barrierDismissible: false,
      builder: (BuildContext context) {
        return Dialog(
          child: Container(
            padding: EdgeInsets.all(10.0),
            child: new Row(
              mainAxisSize: MainAxisSize.min,
              children: [
                new CircularProgressIndicator(),
                Text('กำลังส่งเชื่อมต่อ')
              ],
            ),
          ),
        );
      },
    );
  }

  void connect() {
    setDevice('66:22:3E:0E:24:03');
    _connectListener = Btprinter.getBtPrinterStream_returnStream('functionA')
      ..listen((result) {
        print('result from test-returnStream=$result');
        if (result == 0) {
          printData('เชื่อมต่อสำเร็จ');
          printBarcode('2800099058214');
          Btprinter.fujunClosePort();
        } else if (result == 7) {
          print('try again');
        }
      });
  }

  void connectZenpert() {
    setDevice('DC:0D:30:F5:73:8A');
    _connectListener =
        Btprinter.getZenpertBtPrinterStream_returnStream('functionA')
          ..listen((result) {
            print('result from test-returnStream=$result');
            if (result == 0) {
              printZenpertText('เชื่อมต่อสำเร็จ');
              Btprinter.zenpertClosePort();
            } else if (result == 7) {
              print('try again');
            }
          });
  }

  Future<void> printData(String _data) async {
    String result;
    _data = _data + '\n';
    try {
      result = await Btprinter.printString(_data);
    } on PlatformException {}
  }

  Future<void> printBarcode(String _data) async {
    String result;
    try {
      result = await Btprinter.printBarcode(_data);
    } on PlatformException {}
  }

  Future<void> printQrCode(String _data) async {
    String result;
    try {
      result = await Btprinter.printQrCode(_data);
    } on PlatformException {}
  }

  Future<void> printZenpertText(String _data) async {
    String result;
    try {
      result = await Btprinter.zenpertPrintString(_data);
    } on PlatformException {}
  }

  Future<void> printZenpertBarcode(String _data) async {
    String result;
    try {
      result = await Btprinter.zenpertPrintBarcode(_data);
    } on PlatformException {}
  }

  Future<void> printZenpertQrCode(String _data) async {
    String result;
    try {
      result = await Btprinter.zenpertPrintQrCode(_data);
    } on PlatformException {}
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: AppBar(
          title: Text('Bluetooth Fujun'),
        ),
        body: Column(
          children: <Widget>[
//            StreamBuilder(
//                stream: _connectListener,
//                builder: (context, snapshot) {
//                  return Text('${_resultConnect}');
//                }),
            Center(
              child: RaisedButton(
                onPressed: () {
                  connect();
                },
                child: Text('connect fujun'),
              ),
            ),
            Center(
              child: RaisedButton(
                onPressed: () {
                  connectZenpert();
                },
                child: Text('connect zenpert'),
              ),
            ),
          ],
        ),
      ),
    );
  }
}

Use this package as a library

1. Depend on it

Add this to your package's pubspec.yaml file:


dependencies:
  btprinter: ^0.0.7

2. Install it

You can install packages from the command line:

with Flutter:


$ flutter pub get

Alternatively, your editor might support flutter pub get. Check the docs for your editor to learn more.

3. Import it

Now in your Dart code, you can use:


import 'package:btprinter/btprinter.dart';
  
Popularity:
Describes how popular the package is relative to other packages. [more]
68
Health:
Code health derived from static analysis. [more]
97
Maintenance:
Reflects how tidy and up-to-date the package is. [more]
70
Overall:
Weighted score of the above. [more]
77
Learn more about scoring.

We analyzed this package on Jul 11, 2020, and provided a score, details, and suggestions below. Analysis was completed with status completed using:

  • Dart: 2.8.4
  • pana: 0.13.15
  • Flutter: 1.17.5

Analysis suggestions

Package does not support Flutter platform Linux

Because:

  • package:btprinter/btprinter.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Web

Because:

  • package:btprinter/btprinter.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform Windows

Because:

  • package:btprinter/btprinter.dart that declares support for platforms: Android, iOS

Package does not support Flutter platform macOS

Because:

  • package:btprinter/btprinter.dart that declares support for platforms: Android, iOS

Package not compatible with SDK dart

Because:

  • btprinter that is a package requiring null.

Health issues and suggestions

Document public APIs. (-1 points)

18 out of 18 API elements have no dartdoc comment.Providing good documentation for libraries, classes, functions, and other API elements improves code readability and helps developers find and use your API.

Fix lib/btprinter.dart. (-1.99 points)

Analysis of lib/btprinter.dart reported 4 hints:

line 15 col 25: Name non-constant identifiers using lowerCamelCase.

line 17 col 24: Name non-constant identifiers using lowerCamelCase.

line 103 col 22: Name non-constant identifiers using lowerCamelCase.

line 119 col 22: Name non-constant identifiers using lowerCamelCase.

Maintenance suggestions

The package description is too short. (-20 points)

Add more detail to the description field of pubspec.yaml. Use 60 to 180 characters to describe the package, what it does, and its target use case.

Package is pre-v0.1 release. (-10 points)

While nothing is inherently wrong with versions of 0.0.*, it might mean that the author is still experimenting with the general direction of the API.

Dependencies

Package Constraint Resolved Available
Direct dependencies
Dart SDK >=2.7.0 <3.0.0
flutter 0.0.0
streams_channel ^0.3.0 0.3.0
Transitive dependencies
collection 1.14.12 1.14.13
meta 1.1.8 1.2.2
sky_engine 0.0.99
typed_data 1.1.6 1.2.0
vector_math 2.0.8 2.1.0-nullsafety
Dev dependencies
flutter_test