Showing
4 changed files
with
41 additions
and
0 deletions
| @@ -12,6 +12,7 @@ export 'src/enums/torch_state.dart'; | @@ -12,6 +12,7 @@ export 'src/enums/torch_state.dart'; | ||
| 12 | export 'src/mobile_scanner.dart'; | 12 | export 'src/mobile_scanner.dart'; |
| 13 | export 'src/mobile_scanner_controller.dart'; | 13 | export 'src/mobile_scanner_controller.dart'; |
| 14 | export 'src/mobile_scanner_exception.dart'; | 14 | export 'src/mobile_scanner_exception.dart'; |
| 15 | +export 'src/mobile_scanner_platform_interface.dart'; | ||
| 15 | export 'src/objects/address.dart'; | 16 | export 'src/objects/address.dart'; |
| 16 | export 'src/objects/barcode.dart'; | 17 | export 'src/objects/barcode.dart'; |
| 17 | export 'src/objects/barcode_capture.dart'; | 18 | export 'src/objects/barcode_capture.dart'; |
| 1 | +import 'package:flutter/foundation.dart'; | ||
| 2 | +import 'package:flutter/services.dart'; | ||
| 3 | +import 'package:mobile_scanner/src/mobile_scanner_platform_interface.dart'; | ||
| 4 | + | ||
| 5 | +/// An implementation of [MobileScannerPlatform] that uses method channels. | ||
| 6 | +class MethodChannelMobileScanner extends MobileScannerPlatform { | ||
| 7 | + /// The method channel used to interact with the native platform. | ||
| 8 | + @visibleForTesting | ||
| 9 | + final methodChannel = const MethodChannel('dev.steenbakker.mobile_scanner/scanner/method'); | ||
| 10 | + | ||
| 11 | + /// The event channel that sends back scanned barcode events. | ||
| 12 | + @visibleForTesting | ||
| 13 | + final eventChannel = const EventChannel('dev.steenbakker.mobile_scanner/scanner/event'); | ||
| 14 | +} |
| 1 | +import 'package:mobile_scanner/src/method_channel/mobile_scanner_method_channel.dart'; | ||
| 2 | +import 'package:plugin_platform_interface/plugin_platform_interface.dart'; | ||
| 3 | + | ||
| 4 | +/// The platform interface for the `mobile_scanner` plugin. | ||
| 5 | +abstract class MobileScannerPlatform extends PlatformInterface { | ||
| 6 | + /// Constructs a MobileScannerPlatform. | ||
| 7 | + MobileScannerPlatform() : super(token: _token); | ||
| 8 | + | ||
| 9 | + static final Object _token = Object(); | ||
| 10 | + | ||
| 11 | + static MobileScannerPlatform _instance = MethodChannelMobileScanner(); | ||
| 12 | + | ||
| 13 | + /// The default instance of [MobileScannerPlatform] to use. | ||
| 14 | + /// | ||
| 15 | + /// Defaults to [MethodChannelMobileScanner]. | ||
| 16 | + static MobileScannerPlatform get instance => _instance; | ||
| 17 | + | ||
| 18 | + /// Platform-specific implementations should set this with their own | ||
| 19 | + /// platform-specific class that extends [MobileScannerPlatform] when | ||
| 20 | + /// they register themselves. | ||
| 21 | + static set instance(MobileScannerPlatform instance) { | ||
| 22 | + PlatformInterface.verifyToken(instance, _token); | ||
| 23 | + _instance = instance; | ||
| 24 | + } | ||
| 25 | +} |
| @@ -25,6 +25,7 @@ dependencies: | @@ -25,6 +25,7 @@ dependencies: | ||
| 25 | flutter_web_plugins: | 25 | flutter_web_plugins: |
| 26 | sdk: flutter | 26 | sdk: flutter |
| 27 | js: ">=0.6.3 <0.8.0" | 27 | js: ">=0.6.3 <0.8.0" |
| 28 | + plugin_platform_interface: ^2.0.2 | ||
| 28 | 29 | ||
| 29 | dev_dependencies: | 30 | dev_dependencies: |
| 30 | flutter_test: | 31 | flutter_test: |
-
Please register or login to post a comment