sunmi_flutter_plugin_printer

logo

Sunmi has launched a Flutter plugin that greatly simplifies and accelerates the developer adaptation process for Sunmi printers. By calling the Flutter SDK, third-party software developers can conveniently access the built-in printer on Sunmi devices, easily implementing printing functionality, effectively improving development efficiency and reducing integration costs.

Installation

dependencies:
  sunmi_flutter_plugin_printer: ^1.0.8
import 'package:sunmi_flutter_plugin_printer/printer_sdk.dart';

Compatibility

The plugin follows the Android Gradle Plugin (AGP) version configured by your application. You do not need to change your AGP version to use it.

Plugin version AGP Gradle Flutter Notes
<= 1.0.7 8.x 8.9+ >= 3.3 Not compatible with AGP 9
1.0.8 8.7 - 8.13.x 8.10+ >= 3.3 Same behaviour as 1.0.7
1.0.8 9.0.x - 9.1.x 9.1+ >= 3.44 (built-in Kotlin recommended on 3.47+) Kotlin mode is selected automatically

AGP 9

Starting with AGP 9, Kotlin support is built into AGP and applying the org.jetbrains.kotlin.android (KGP) plugin is no longer allowed. Since 1.0.8 the plugin detects your AGP version at configuration time and picks the matching Kotlin mode:

Your project What the plugin does
AGP < 9 Applies KGP, exactly like 1.0.7
AGP >= 9, built-in Kotlin enabled Uses AGP built-in Kotlin (android.builtInKotlin=true)
AGP >= 9, android.builtInKotlin=false Falls back to KGP (Flutter 3.44+ transition mode)

No Dart code change is required. The selected mode is printed in the Gradle output as [sunmi_printer] AGP=..., kotlinMode=... — use it when reporting build issues.

If your Kotlin Gradle Plugin rejects AGP 9, enable built-in Kotlin (android.builtInKotlin=true and android.newDsl=false in android/gradle.properties, requires Flutter 3.47+ and all plugins migrated), or stay on AGP 8.x with plugin 1.0.8.

Testing the Android side

# baseline: AGP 8.7 / Gradle 8.10.2 / KGP 1.8.22 (default)
./scripts/set_agp.sh --agp 8.7.0

# AGP 8.13 / Gradle 8.13 / KGP 2.1.20
./scripts/set_agp.sh --agp 8.13.2

# AGP 9.0.1 / Gradle 9.1 / built-in Kotlin (app module migrated automatically)
./scripts/set_agp.sh --agp 9.0.1

# AGP 9.0.1 with android.builtInKotlin=false (KGP fallback)
./scripts/set_agp.sh --agp 9.0.1 --builtin false

Windows PowerShell equivalent: ./scripts/set_agp.ps1 9.0.1 (add -BuiltInKotlin false for the fallback mode). After switching, run flutter clean && flutter pub get && flutter build apk.

Check the Gradle output for the selected mode:

[sunmi_printer] AGP=9.0.1, kotlinMode=built-in, android.builtInKotlin=true

The scripts rewrite example/android files. Restore the baseline with ./scripts/set_agp.sh --agp 8.7.0 before committing.

Migration from flutter_plugin_printer

This plugin was published earlier as flutter_plugin_printer (last version 1.0.7+7). New releases, including AGP 9 support, are only published under sunmi_flutter_plugin_printer. To migrate, change the dependency and the import prefix:

 dependencies:
-  flutter_plugin_printer: ^1.0.7
+  sunmi_flutter_plugin_printer: ^1.0.8
-import 'package:flutter_plugin_printer/printer_sdk.dart';
+import 'package:sunmi_flutter_plugin_printer/printer_sdk.dart';

The two packages share the same Android package / pluginClass, so they must not be used at the same time in one project. Replace, don't add.

Example

See the example app for printer, label, cash drawer and query usage.

Development

flutter pub get
cd example && flutter pub get && flutter run

The plugin Android module supports both Kotlin modes; see docs/agp9-compatibility-plan.md for the verification matrix and scripts/set_agp.ps1 (Windows) / scripts/set_agp.sh (macOS/Linux) for switching the example project between AGP versions.

License

MIT