Skip to the content.

Conditional Compilation Implementation Summary

✅ Successfully Implemented

The Brother Printer functionality now supports conditional compilation, allowing the app to run on iOS Simulator while maintaining full functionality on physical devices.

Architecture

File Structure

lib/utils/
├── brother_printer_util.dart          # Main entry point with export control
├── brother_printer_util_device.dart   # Full implementation with another_brother SDK
└── brother_printer_util_stub.dart     # Stub implementation for unsupported platforms

Implementation Strategy

1. Conditional Export (brother_printer_util.dart)

2. Device Implementation (brother_printer_util_device.dart)

3. Stub Implementation (brother_printer_util_stub.dart)

Usage

For iOS Simulator Testing

# 1. Disable Brother printer
./toggle_brother_printer.sh disable

# 2. Clean and rebuild
flutter clean && flutter pub get && cd ios && pod install

# 3. Run on simulator
flutter run --flavor dev -d "iPhone Air"

Result: App runs successfully on simulator with printer features gracefully disabled.

For Physical Device Testing

# 1. Re-enable Brother printer
./toggle_brother_printer.sh enable

# 2. Clean and rebuild  
flutter clean && flutter pub get && cd ios && pod install

# 3. Run on device
./run.sh dev ios 00008112-001C20911E68A01E

Result: App runs with full Brother printer functionality.

Benefits

✅ Simulator Testing: Can test all other features without printer hardware ✅ Clean Separation: Device and stub implementations completely isolated ✅ Type Safety: Both implementations export identical public API ✅ User Experience: Graceful fallbacks with informative messages ✅ No Runtime Overhead: Conditional compilation happens at build time ✅ Easy Toggle: Simple script to switch between modes

Testing Checklist

✅ Simulator Build (Verified)

🔲 Device Build (To Test)

Technical Notes

Why Toggle Script Is Needed

The another_brother plugin has hard dependencies on Brother SDK native frameworks in its podspec:

s.dependency 'BRLMPrinterKit_AB'
s.dependency 'BROTHERSDK'

These frameworks are device-only (no simulator support). Even with conditional Dart imports, CocoaPods will still try to link the frameworks, causing build failures.

Solution: Temporarily comment out the dependency in pubspec.yaml for simulator builds.

Future Improvements

If Brother releases simulator-compatible frameworks:

  1. Remove the toggle script requirement
  2. Update brother_printer_util.dart to use conditional exports
  3. Use runtime platform detection instead of build-time toggling

Alternative Considered

Weak Linking: Attempted to make frameworks optional via Podfile, but CocoaPods doesn’t support partial weak linking of plugin dependencies.

Files Modified