Skip to content

zh4dev/Niimbot-Printer

Repository files navigation

Niimbot Printer Flutter Plugin

📖 Introduction

Niimbot-Printer is a Flutter plugin that integrates with Niimbot Hardware Printers, allowing you to print text labels directly from your Flutter application.


⚙️ Setup

iOS Permissions

Add the following permissions to your Info.plist (located in ios/Runner/Info.plist):

<key>NSBluetoothAlwaysUsageDescription</key>
<string>This app requires Bluetooth access to connect to Niimbot printers.</string>
<key>NSBluetoothPeripheralUsageDescription</key>
<string>This app requires Bluetooth access to communicate with Niimbot printers.</string>

🚀 Getting Started

1. Add the niimbot_print dependency

In your pubspec.yaml file, add the following dependency:

dependencies:
  niimbot_print:
    git: https://github.com/zh4dev/Niimbot-Printer.git

This will pull the plugin directly from GitHub.

2. Scan for nearby Niimbot printers

var value = await niimbotPrint.onStartScan(
  whiteListDevices: [NiimbotModelEnum.b1],
  onError: (errorMessage) {
    LogHelper.error(errorMessage, event: 'initializeData');
  },
);

3. Connect to a scanned device

if (blueDeviceInfoModel.value.connectionState != null) {
  await niimbotPrint.onDisconnect();
  blueDeviceInfoModel.value = BlueDeviceInfoModel();
} else {
  await niimbotPrint.onStartConnect(
    model: device,
    onResult: (isSuccess, message) {
      if (isSuccess) {
        blueDeviceInfoModel.value = device;
      } else {
        LogHelper.error(message, event: 'onConnectDevice');
        blueDeviceInfoModel.value = BlueDeviceInfoModel();
      }
    },
  );
}

4. Start printing

await niimbotPrint.onStartPrintText(
  printLabelModelList: [
    PrintLabelModel(text: 'Gerzha Hayat Prakarsha', fontSize: 16),
    PrintLabelModel(
      text: 'https://www.linkedin.com/in/gerzha-hayat-prakarsha-09974899/',
      fontSize: 14,
    ),
  ],
  onResult: (isSuccess, message) async {
    await Future.delayed(const Duration(seconds: 2));
    isLoadingPrinting.value = false;

    if (isSuccess) {
      Get.snackbar(
        MessageConstant.printSucceed,
        message,
        snackPosition: SnackPosition.BOTTOM,
        colorText: Colors.white,
        borderRadius: BorderRadiusConstant.low,
        backgroundColor: Get.theme.primaryColor,
        margin: const EdgeInsets.only(
          left: MarginSizeConstant.medium,
          right: MarginSizeConstant.medium,
          bottom: MarginSizeConstant.medium,
        ),
      );
    } else {
      LogHelper.error(message, event: 'onStartPrint');
    }
  },
);

📦 About this project

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


👤 Author


Notes:

  • iOS Configuration: Ensure that you’ve added the necessary Bluetooth permissions in the Info.plist file.
  • Android Setup: The Android setup, including dependencies like .aar files, will be handled automatically by the plugin.
  • iOS Testing: Make sure that your iOS project has the necessary capabilities (e.g., Bluetooth) enabled in Xcode, and test the plugin on a real device, as Bluetooth features may not work in the iOS simulator.

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published