Line data Source code
1 : import 'package:flutter/services.dart'; 2 : import 'package:unico_check/src/unico/abstractions/interfaces/open.camera.listener.dart'; 3 : import 'package:unico_check/src/unico/adapter/repository/channel.result.listener.dart'; 4 : import 'package:unico_check/src/unico/adapter/repository/plugin/channel.unico.dart'; 5 : import 'package:unico_check/src/unico/domain/entities/unico.error.channel.dart'; 6 : 7 : class ChannelUnicoDefault extends ChannelUnico { 8 : static const String _resultName = 'call_result'; 9 : 10 : ChannelResultListener? _listener; 11 : final MethodChannel _channel; 12 : 13 2 : ChannelUnicoDefault(this._channel); 14 : 15 : @override 16 1 : void callMethod({ 17 : required String method, 18 : required Map<dynamic, dynamic> request, 19 : required ChannelResultListener listener, 20 : }) async { 21 : try { 22 1 : _listener = listener; 23 3 : _channel.setMethodCallHandler(_fromNative); 24 1 : _channel 25 1 : .invokeMethod( 26 : method, 27 : request, 28 : ) 29 4 : .then((value) => {_listener?.onChannelResult(value)}) 30 1 : .catchError((error) => { 31 0 : listener.onChannelResult(<dynamic, dynamic>{ 32 : IOpenCameraeListener.response: false, 33 0 : UnicoErrorChannel.errorMethod: error.code, 34 0 : UnicoErrorChannel.unicoError: error.details, 35 : }) 36 : }); 37 1 : } on PlatformException catch (e) { 38 3 : _listener?.onChannelResult(<dynamic, dynamic>{ 39 : IOpenCameraeListener.response: false, 40 1 : UnicoErrorChannel.errorMethod: e.code, 41 1 : UnicoErrorChannel.unicoError: e.details, 42 : }); 43 : } 44 : } 45 : 46 0 : Future<void> _fromNative(MethodCall call) async { 47 0 : if (call.method == _resultName) { 48 0 : _listener?.onChannelResult(<dynamic, dynamic>{ 49 : IOpenCameraeListener.response: false, 50 : UnicoErrorChannel.errorMethod: 51 0 : call.arguments[UnicoErrorChannel.errorMethod], 52 : }); 53 : } 54 : } 55 : }