{"id":390181,"date":"2024-06-29T09:04:46","date_gmt":"2024-06-29T09:04:46","guid":{"rendered":"http:\/\/savepearlharbor.com\/?p=390181"},"modified":"-0001-11-30T00:00:00","modified_gmt":"-0001-11-29T21:00:00","slug":"","status":"publish","type":"post","link":"https:\/\/savepearlharbor.com\/?p=390181","title":{"rendered":"<span>Flutter: PlatformView + QR code reader<\/span>"},"content":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0418\u0437 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0445 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 qr \u043a\u043e\u0434\u0430\u043c\u0438 \u0432 Android \u0441\u0430\u043c\u043e\u0439 \u043b\u0443\u0447\u0448\u0435\u0439 (\u043d\u0430 \u043c\u043e\u0439 \u043b\u0438\u0447\u043d\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434) \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f zxing-android-embedded. \u0427\u0430\u0441\u0442\u043e, UI \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u0442\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043d\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u043b\u0438 \u043d\u0443\u0436\u0435\u043d \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0438\u043d\u043e\u0439.\u00a0<strong>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e\u0439\u0434\u0435\u0442 \u0440\u0435\u0447\u044c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a\u00a0<\/strong>\u00ab<strong>\u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c<\/strong>\u00bb<strong>\u00a0UI \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 zxing-android-embedded \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f QR \u043a\u043e\u0434\u043e\u0432 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0451 Flutter \u043f\u0440\u043e\u0435\u043a\u0442\u0435.<\/strong><\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0438 \u043a\u043e\u0434 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043d\u0435\u0439, \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u00ab\u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0446\u0438\u0438\u00bb\u00a0<a href=\"https:\/\/github.com\/journeyapps\/zxing-android-embedded\" rel=\"noopener noreferrer nofollow\"><u>zxing-android<\/u><\/a>\u00a0\u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0435\u0439 \u0432\u043e flutter. \u0421\u0442\u0430\u0442\u044c\u044f \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e Android \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043d\u0435 \u043a\u0430\u0441\u0430\u044f\u0441\u044c IOS.<\/p>\n<p>\u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0440\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u044d\u0442\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u0438\u0437 flutter \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f:<\/p>\n<ul>\n<li>\n<p>PlatformViewLink<\/p>\n<\/li>\n<li>\n<p>MethodChannel<\/p>\n<\/li>\n<li>\n<p>EventChannel<\/p>\n<\/li>\n<\/ul>\n<h3>PlatformViewLink:<\/h3>\n<p>\u0414\u0430\u0451\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u00ab\u043f\u0440\u043e\u043a\u0438\u043d\u0443\u0442\u044c\u00bb \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 android \u044d\u043a\u0440\u0430\u043d(View) \u0432 \u0432\u0430\u0448\u0435 fluttter \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u042d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0432 \u0442\u0435\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043a\u043e\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u043e\u0435, \u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u0434 \u043d\u0430\u0442\u0438\u0432\u043d\u0443\u044e \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0443, \u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0434 flutter \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0438 \u043b\u0435\u0433\u0447\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c android activity \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432 \u0432\u0430\u0448\u0435\u043c flutter \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438. \u041f\u043e \u0442\u0430\u043a\u043e\u043c\u0443 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 google maps \u0432\u043e flutter \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0447\u0435\u0440\u0435\u0437 PlatformViewLink \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u044d\u043a\u0440\u0430\u043d \u0441\u043e \u0441\u0442\u0440\u0438\u043c\u043e\u043c \u0444\u043e\u0442\u043e\u043a\u0430\u043c\u0435\u0440\u044b.<\/p>\n<h3>MethodChannel:<\/h3>\n<p>\u0414\u0430\u0451\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b(android \u0438\u043b\u0438 ios \u0438 \u0442.\u0434.) \u0438\u0437 flutter \u0441\u0440\u0435\u0434\u044b \u0432 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 . \u041d\u0430\u0434\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0447\u0442\u043e \u0432\u0441\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 MethodChannel \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0447\u0442\u043e\u0431\u044b \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0438 \u0432\u044b\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u043f\u043e\u0434\u0441\u0432\u0435\u0442\u043a\u0443 \u0444\u043e\u0442\u043e\u043a\u0430\u043c\u0435\u0440\u044b.<\/p>\n<h3>EventChannel:<\/h3>\n<p>\u041f\u043e\u0447\u0442\u0438 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0447\u0442\u043e \u0438 MethodChannel, \u0441 \u0442\u0435\u043c \u043b\u0438\u0448\u044c \u043e\u0442\u043b\u0438\u0447\u0438\u0435\u043c, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043f\u043e\u0442\u043e\u043a \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0432 \u043d\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435. \u0421\u0430\u043c\u044b\u0439 \u0447\u0430\u0441\u0442\u044b \u043a\u0435\u0439\u0441 \u044d\u0442\u043e \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u00ab\u0441\u043b\u0443\u0448\u0430\u0442\u044c\u00bb gps \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u043e\u0442 \u043d\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 EventChannel \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u043d\u043d\u043e\u0433\u043e QR \u043a\u043e\u0434\u0430 \u0438\u0437 android \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0432 \u043d\u0430\u0448\u0435 flutter \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c MethodChannel, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043a\u0430\u0436\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0435 10 \u0441\u0435\u043a\u0443\u043d\u0434. \u041d\u043e \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e\u0433\u0434\u0430 \u043a\u043e\u0433\u0434\u0430 \u043e\u043d \u0433\u043e\u0442\u043e\u0432.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0443\u0441\u0442\u043e\u0439 flutter \u043f\u0440\u043e\u0435\u043a\u0442. \u0412 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0430 \u0432\u044b\u0448\u0435\u0439 \u043b\u044e\u0431\u0438\u043c\u043e\u0439 \u041e\u0421 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<figure class=\"\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/1cd\/04a\/3e0\/1cd04a3e052bbbbda1d086e154aa8c74.png\" width=\"466\" height=\"147\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/1cd\/04a\/3e0\/1cd04a3e052bbbbda1d086e154aa8c74.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041e\u0442\u043a\u0440\u043e\u0435\u043c\u00a0<strong>main.dart<\/strong>. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 home \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u00a0<strong>MaterialApp\u00a0<\/strong>\u0432\u0438\u0434\u0436\u0435\u0442\u0430, QrCodePage &#8212; \u0432\u0438\u0434\u0436\u0435\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0435\u0440\u043d\u0451\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u044d\u043a\u0440\u0430\u043d \u0432\u00a0<strong>Scaffold\u00a0<\/strong>\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442 AppBar \u0434\u043b\u044f \u043d\u0435\u0433\u043e:<\/p>\n<pre><code class=\"dart\">class MyApp extends StatelessWidget {   @override   Widget build(BuildContext context) {     return MaterialApp(       title: 'Flutter Demo',       theme: ThemeData(         primarySwatch: Colors.blue,       ),       home: QrCodePage(),     );   } }  class QrCodePage extends StatelessWidget {   QrCodePage({Key? key}) : super(key: key);    @override   Widget build(BuildContext context) {     return Scaffold(       appBar: AppBar(         title: Text(\"QR code App\"),       ),       body: PlatformView(),     );   } }<\/code><\/pre>\n<p><strong>PlatformView\u00a0<\/strong>&#8212; \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439\u00a0<strong>StatefulWidge<\/strong>\u00a0\u0432\u0438\u0434\u0436\u0435\u0442. \u041e\u043d \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0451\u0440\u0442\u043a\u043e\u0439 \u043d\u0430\u0434\u00a0<strong>PlatformViewLink\u00a0<\/strong>\u0438 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0438\u0434\u0435\u043e \u0441 \u043a\u0430\u043c\u0435\u0440\u044b:<\/p>\n<pre><code class=\"dart\">class _PlatformViewState extends State&lt;PlatformView> {   final MethodChannel platformMethodChannel = MethodChannel('flashlight');   bool isFlashOn = false;   bool permissionIsGranted = false;   String result = '';    void _handleQRcodeResult() {     const EventChannel _stream = EventChannel('qrcodeResultStream');     _stream.receiveBroadcastStream().listen((onData) {       print('EventChannel onData = $onData');       result = onData;       setState(() {});     });   }    Future&lt;void> _onFlash() async {     try {       dynamic result = await platformMethodChannel.invokeMethod('onFlash');       setState(() {         isFlashOn = true;       });     } on PlatformException catch (e) {       debugPrint('PlatformException ${e.message}');     }   }    Future&lt;void> _offFlash() async {     try {       dynamic result = await platformMethodChannel.invokeMethod('offFlash');       setState(() {         isFlashOn = false;       });     } on PlatformException catch (e) {       debugPrint('PlatformException ${e.message}');     }   }    @override   void initState() {     super.initState();     _handleQRcodeResult();     _checkPermissions();   }    _requestAppPermissions() {     showDialog(         context: context,         builder: (BuildContext context) => AlertDialog(               title: const Text('Permission required'),               content: const Text('Allow camera permissions'),               actions: &lt;Widget>[                 TextButton(                   onPressed: () {                     _checkPermissions();                     Navigator.pop(context, 'OK');                   },                   child: const Text('OK'),                 ),               ],             ));   }    _checkPermissions() async {     var status = await Permission.camera.status;     if (!status.isGranted) {       final PermissionStatus permissionStatus = await Permission.camera.request();       if (!permissionStatus.isGranted) {         _requestAppPermissions();       }     }   }    @override   Widget build(BuildContext context) {     final String viewType = '&lt;platform-view-type>';     final Map&lt;String, dynamic> creationParams = &lt;String, dynamic>{};     return result.isEmpty         ? Stack(             alignment: Alignment.center,             children: [               PlatformViewLink(                 viewType: viewType,                 surfaceFactory: (BuildContext context, PlatformViewController controller) {                   return Container(                     child: AndroidViewSurface(                       controller: controller as AndroidViewController,                       gestureRecognizers: const &lt;Factory&lt;OneSequenceGestureRecognizer>>{},                       hitTestBehavior: PlatformViewHitTestBehavior.opaque,                     ),                   );                 },                 onCreatePlatformView: (PlatformViewCreationParams params) {                   return PlatformViewsService.initSurfaceAndroidView(                     id: params.id,                     viewType: viewType,                     layoutDirection: TextDirection.ltr,                     creationParams: creationParams,                     creationParamsCodec: StandardMessageCodec(),                   )                     ..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)                     ..create();                 },               ),               Align(                   alignment: Alignment.topCenter,                   child: ElevatedButton(                       onPressed: () {                         if (!isFlashOn) {                           _onFlash();                         } else {                           _offFlash();                         }                       },                       child: isFlashOn ? Text('off flashlight') : Text('on flashlight'))),               Align(                 alignment: Alignment.center,                 child: Container(                   height: 200,                   width: 200,                   decoration: BoxDecoration(                       color: Colors.transparent,                       border: Border.all(                         color: Colors.blueAccent,                         width: 5,                       )),                 ),               )             ],           )         : Container(             child: Center(child: Text('QR code result:\\n$result')),           );   } }<\/code><\/pre>\n<p>\u041f\u0430\u0440\u0443 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432 \u043a \u043a\u043e\u0434\u0443 \u0432\u0430\u0448\u0435:<\/p>\n<ul>\n<li>\n<p>\u0417\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043a\u0430\u043c\u0435\u0440\u043e\u0439:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/c09\/25d\/642\/c0925d6428588f8c0a83a02746245dad.png\" alt=\"\" title=\"\" width=\"560\" height=\"181\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/c09\/25d\/642\/c0925d6428588f8c0a83a02746245dad.png\"\/><figcaption><\/figcaption><\/figure>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p>\u0412 \u043f\u043e\u043b\u0435 \u043a\u043b\u0430\u0441\u0441\u0430, \u0441\u043e\u0437\u0434\u0430\u0451\u043c\u00a0<strong>platformMethodChannel &#8212;\u00a0<\/strong>\u0447\u0435\u0440\u0435\u0437 \u044d\u0442\u043e\u0442 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b (\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435) \u0432 android \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438. \u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u2018flashlight\u2019 \u044d\u0442\u043e \u0441\u0432\u043e\u0435\u0433\u043e \u0440\u043e\u0434\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 ID, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b\u0439 \u0432\u043e flutter \u0438 \u043d\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/439\/78b\/2a8\/43978b2a822a8ecc9be3d930fa0c8513.png\" width=\"560\" height=\"77\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/439\/78b\/2a8\/43978b2a822a8ecc9be3d930fa0c8513.png\"\/><figcaption><\/figcaption><\/figure>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p>\u041c\u0435\u0442\u043e\u0434\u00a0<strong>_handleQRcodeResult()<\/strong>\u00a0&#8212; \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043e\u0442\u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e qr \u043a\u043e\u0434\u0430:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/42d\/8d0\/93e\/42d8d093e88888172a7ff2f2ec7a0aec.png\" width=\"560\" height=\"215\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/42d\/8d0\/93e\/42d8d093e88888172a7ff2f2ec7a0aec.png\"\/><figcaption><\/figcaption><\/figure>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b<strong>\u00a0_onFlash()<\/strong>\u00a0\u0438\u00a0<strong>_offFlash<em>()<\/em><\/strong><em>\u00a0\u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 Android \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430.<\/em><\/p>\n<\/li>\n<li>\n<p>\u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432 \u043d\u0430\u0442\u0438\u0432\u043d\u0443\u044e \u0441\u0440\u0435\u0434\u0443. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u00a0<strong>creationParams<\/strong>. \u041d\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0443 \u043d\u0430\u0441 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442:<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/fda\/94d\/0cb\/fda94d0cbc4532f7ee649e3ca64d3e2e.png\" width=\"560\" height=\"89\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fda\/94d\/0cb\/fda94d0cbc4532f7ee649e3ca64d3e2e.png\"\/><figcaption><\/figcaption><\/figure>\n<ul>\n<li>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u00a0<strong>ViewGroup\u00a0<\/strong>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u00a0<strong>Stack\u00a0<\/strong>\u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 UI \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b. \u0412 \u043c\u043e\u0451\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044d\u0442\u043e \u0440\u0430\u043c\u043a\u0430 \u0432 \u0446\u0435\u043d\u0442\u0440 \u044d\u043a\u0440\u0430\u043d\u0430(<strong>Container<\/strong>\u00a0\u0441 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u043c \u0444\u043e\u043d\u043e\u043c \u0438\u00a0<strong>BoxDecoration<\/strong>) \u0438\u00a0<strong>ElevatedButton<\/strong>\u00a0\u043d\u0430\u0434 \u043d\u0435\u0439 \u0434\u043b\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u0441\u0432\u0435\u0442\u043a\u0438.<\/p>\n<\/li>\n<\/ul>\n<h2>\u0412\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 Android \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e:<\/h2>\n<p>\u0412\u00a0<strong>build.gradle<\/strong>\u00a0\u043c\u043e\u0434\u0443\u043b\u044f app (android\/app\/build.gradle) \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443. \u0412 \u0440\u0430\u0437\u0434\u0435\u043b dependencies \u0434\u043e\u0431\u0430\u0432\u0438\u043c:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/98b\/404\/5dd\/98b4045dd894f86a481f1896e2f64189.png\" width=\"560\" height=\"108\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/98b\/404\/5dd\/98b4045dd894f86a481f1896e2f64189.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412 MainActivity, \u0432 \u043c\u0435\u0442\u043e\u0434\u0435\u00a0<strong>configureFlutterEngine, EventChannel<\/strong><\/p>\n<pre><code class=\"dart\">class MainActivity : FlutterFragmentActivity(), LifecycleOwner, ResultCallback {     var myEvents: EventChannel.EventSink? = null      override fun configureFlutterEngine(flutterEngine: FlutterEngine) {         super.configureFlutterEngine(flutterEngine)         EventChannel(flutterEngine.dartExecutor.binaryMessenger, \"qrcodeResultStream\")                 .setStreamHandler(object : EventChannel.StreamHandler {                     override fun onListen(arguments: Any?, events: EventChannel.EventSink?) {                         myEvents = events                     }                      override fun onCancel(arguments: Any?) {                         myEvents = null                     }                 })          flutterEngine                 .platformViewsController                 .registry                 .registerViewFactory(\"&lt;platform-view-type>\", NativeViewFactory())     }      override fun result(result: String) {         myEvents?.success(result)     }      override fun getMyFlutterEngine(): FlutterEngine? = flutterEngine }<\/code><\/pre>\n<p><strong>EventChannel.StreamHandler<\/strong> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0430\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u00a0<strong>EventChannel.EventSink\u00a0<\/strong>\u0432\u044b\u0437\u044b\u0432\u0430\u044f \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u00a0<strong>.success(result)<\/strong>\u00a0\u2014 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0432\u043e flutter \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0430 \u0441 QR \u043a\u043e\u0434\u043e\u043c.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/e4c\/846\/2ad\/e4c8462ad363a8c3e6e34ca8e9e67d5a.png\" width=\"560\" height=\"87\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/e4c\/846\/2ad\/e4c8462ad363a8c3e6e34ca8e9e67d5a.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u043c\u0435\u0442\u043e\u0434\u0435 \u0432\u044b\u0448\u0435 \u043c\u044b \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u0444\u0430\u0431\u0440\u0438\u043a\u0443 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 View \u0432 \u0437\u0430\u0432\u0438\u0441\u0438\u043c\u043e\u0441\u0442\u0438 \u043e\u0442 \u043f\u0435\u0440\u0435\u0434\u0430\u043d\u043d\u044b\u0445 \u0430\u0440\u0433\u0443\u043c\u0435\u043d\u0442\u043e\u0432, \u043d\u043e \u043c\u044b \u043d\u0435 \u0431\u0443\u0434\u0435\u043c \u0443\u0441\u043b\u043e\u0436\u043d\u044f\u0442\u044c \u043f\u0440\u0438\u043c\u0435\u0440 \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u043d\u0430\u0448 \u0435\u0434\u0438\u043d\u0441\u0442\u0432\u0435\u043d\u043d\u043e\u0435\u00a0<strong>NativeView<\/strong>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/ef3\/17b\/b27\/ef317bb276bc169341fbf3ba08f6b3fb.png\" width=\"560\" height=\"139\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/ef3\/17b\/b27\/ef317bb276bc169341fbf3ba08f6b3fb.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u00a0<strong>ResultCallback<\/strong>, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0438\u043c\u043f\u043b\u0435\u043c\u0435\u043d\u0442\u0438\u0440\u0443\u0435\u0442\u00a0<strong>MainActivity<\/strong>:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/492\/4c3\/306\/4924c3306ccb7a705633e5c7585ce430.png\" width=\"560\" height=\"199\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/492\/4c3\/306\/4924c3306ccb7a705633e5c7585ce430.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041c\u0435\u0442\u043e\u0434 <strong>result<em>(<\/em>result: String<em>)<\/em><\/strong><em> \u043d\u0443\u0436\u0435\u043d \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 (\u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u043d\u043d\u043e\u0433\u043e qr \u043a\u043e\u0434\u0430) \u0432\u00a0<\/em><strong>MainActivity<\/strong>.<\/p>\n<p>\u043c\u0435\u0442\u043e\u0434 <strong>getMyFlutterEngine()<\/strong> &#8212; \u0432\u0435\u0440\u043d\u0451\u0442 \u043d\u0430\u043c FlutterEngine \u0432 \u043d\u0430\u0448\u0435\u043c <strong>NativeView<\/strong>.<\/p>\n<p>\u041e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u043a\u043e\u0434 \u0431\u0443\u0434\u0435\u0442 \u0432 <strong>NativeView<\/strong>:<\/p>\n<pre><code class=\"dart\">class NativeView(context: Context, id: Int, creationParams: Map&lt;String?, Any?>?) : PlatformView {     private val textView: TextView     private val CHANNEL = \"flashlight\"      private val rootView: View     private var barcodeView: DecoratedBarcodeView? = null     override fun getView(): View {         return rootView     }      override fun dispose() {}      init {         (context as LifecycleOwner).lifecycle.addObserver(object : LifecycleObserver {             @OnLifecycleEvent(Lifecycle.Event.ON_RESUME)             fun connectListener() {                 barcodeView?.resume()             }              @OnLifecycleEvent(Lifecycle.Event.ON_PAUSE)             fun disconnectListener() {                 barcodeView?.pause()             }         })          rootView = LayoutInflater.from(context.applicationContext).inflate(R.layout.layout, null)          barcodeView = rootView.findViewById&lt;DecoratedBarcodeView>(R.id.barcode_scanner)         val formats: Collection&lt;BarcodeFormat> = Arrays.asList(BarcodeFormat.QR_CODE, BarcodeFormat.CODE_39)         barcodeView?.barcodeView?.decoderFactory = DefaultDecoderFactory(formats)         barcodeView?.setStatusText(\"\")         barcodeView?.viewFinder?.visibility = View.INVISIBLE          barcodeView?.initializeFromIntent(Intent())         barcodeView?.decodeContinuous(object : BarcodeCallback {             override fun possibleResultPoints(resultPoints: MutableList&lt;ResultPoint>?) {                 super.possibleResultPoints(resultPoints)             }              override fun barcodeResult(result: BarcodeResult?) {                 (context as ResultCallback).result(result?.result?.text ?: \"no result\")                 barcodeView?.setStatusText(result?.text)             }         })          barcodeView?.resume()         textView = TextView(context)         textView.textSize = 36f         textView.setBackgroundColor(Color.rgb(255, 255, 255))         textView.text = \"Rendered on a native Android view (id: $id) ${creationParams?.entries}\"          val flutterEngine = (context as ResultCallback).getMyFlutterEngine()         MethodChannel(flutterEngine?.dartExecutor?.binaryMessenger, CHANNEL)                 .setMethodCallHandler { call, result ->                     when (call.method) {                         \"onFlash\" -> {                             barcodeView?.setTorchOn()                             result.success(\"setTorchOn\")                         }                          \"offFlash\" -> {                             barcodeView?.setTorchOff()                             result.success(\"setTorchOff\")                         }                         else -> {                             result.notImplemented()                         }                     }                 }     } }<\/code><\/pre>\n<p>\u0412 <strong>init<\/strong> \u0431\u043b\u043e\u043a\u0435 \u043f\u043e\u0434\u043f\u0438\u0441\u044b\u0432\u0430\u0435\u043c\u0441\u044f \u043d\u0430 \u0436\u0438\u0437\u043d\u0435\u043d\u043d\u044b\u0439 \u0446\u0438\u043a\u043b activiti \u0438 \u0432 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u0430\u0445 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c\u00a0<strong>resume<\/strong>\u00a0\/\u00a0<strong>pause\u00a0<\/strong>\u0443\u00a0<strong>barcodeView<\/strong>.\u00a0\u0412\u0430\u0436\u043d\u043e<strong>:<\/strong>\u00a0\u0447\u0442\u043e \u0431\u0435\u0437 \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u0438 \u044d\u0442\u0438\u0445 \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0432\u044b \u0432\u043c\u0435\u0441\u0442\u043e \u0432\u0438\u0434\u0435\u043e\u043f\u043e\u0442\u043e\u043a\u0430 \u0441 \u043a\u0430\u043c\u0435\u0440\u044b \u0431\u0443\u0434\u0435\u0442 \u0443\u0432\u0438\u0434\u0438\u0442\u0435 \u0447\u0435\u0440\u043d\u044b\u0439 \u044d\u043a\u0440\u0430\u043d:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/038\/b4f\/e9e\/038b4fe9eeecaa0dbc75b6a5cc24c352.png\" width=\"560\" height=\"218\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/038\/b4f\/e9e\/038b4fe9eeecaa0dbc75b6a5cc24c352.png\"\/><figcaption><\/figcaption><\/figure>\n<p><strong>NativeView<\/strong> \u043d\u0430\u0441\u043b\u0435\u0434\u0443\u0435\u0442\u0441\u044f \u043e\u0442 \u0438\u043d\u0442\u0435\u0440\u0444\u0435\u0439\u0441\u0430 <strong>PlatformView<\/strong> \u044d\u0442\u043e \u043e\u0431\u044f\u0437\u044b\u0432\u0430\u0435\u0442 \u043d\u0430\u0441 \u0440\u0435\u0430\u043b\u0438\u0437\u043e\u0432\u0430\u0442\u044c \u0434\u0432\u0430 \u043c\u0435\u0442\u043e\u0434\u0430:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/b05\/292\/056\/b052920563403f662bd3388c99092494.png\" width=\"560\" height=\"257\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/b05\/292\/056\/b052920563403f662bd3388c99092494.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0412 <strong>getView<\/strong> \u043c\u044b \u0434\u043e\u043b\u0436\u043d\u044b \u0432\u0435\u0440\u043d\u0443\u0442\u044c <strong>View<\/strong> \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u0433\u043b\u0430\u0432\u043d\u044b\u043c \u044d\u043a\u0440\u0430\u043d\u043e\u043c. \u041d\u0443\u0436\u043d\u043e \u0441\u043e\u0437\u0434\u0430\u0442\u044c <strong>layout.xml<\/strong> \u0441 \u0441\u043b\u0435\u0434\u0443\u044e\u0449\u0435\u0433\u043e \u0441\u043e\u0434\u0435\u0440\u0436\u0430\u043d\u0438\u044f:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/fef\/fc1\/866\/feffc1866d31013ddd61fc67a1d06b1f.png\" width=\"560\" height=\"381\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/fef\/fc1\/866\/feffc1866d31013ddd61fc67a1d06b1f.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0418\u0437 \u043d\u0435\u0433\u043e \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <strong>LayoutInflater<\/strong> \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0451\u043c <strong>view<\/strong> \u0438 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u043c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043d\u0435\u0433\u043e \u0432 \u043c\u0435\u0442\u043e\u0434\u0435 <strong>getView<em>()<\/em><\/strong><em>:<\/em><\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/978\/fcd\/7d5\/978fcd7d50ea551de06fd0019922bec2.png\" width=\"560\" height=\"97\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/978\/fcd\/7d5\/978fcd7d50ea551de06fd0019922bec2.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041f\u043e\u0441\u043a\u043e\u043b\u044c\u043a\u0443 \u043d\u0430\u0448 layout \u0441\u043e\u0434\u0435\u0440\u0436\u0438\u0442 <strong>DecoratedBarcodeView<\/strong> \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043d\u0430\u0439\u0442\u0438 \u0435\u0433\u043e(\u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430 \u043d\u0435\u0433\u043e) \u0441 \u043f\u043e\u043c\u043e\u0449\u044c\u044e <strong>findViewById<\/strong> \u0438 \u043d\u0430\u0441\u0442\u0440\u043e\u0438\u0442\u044c \u043a\u0430\u043a \u043d\u0430 \u043d\u0443\u0436\u043d\u043e:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/34b\/1a8\/45c\/34b1a845c0ca1cd1ea80427b37c38978.png\" width=\"560\" height=\"392\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/34b\/1a8\/45c\/34b1a845c0ca1cd1ea80427b37c38978.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u0422\u0443\u0442 \u043c\u044b \u0443\u0441\u0442\u0430\u043d\u0430\u0432\u043b\u0438\u0432\u0430\u0435\u043c \u043f\u043e\u0434\u0434\u0435\u0440\u0436\u0438\u0432\u0430\u0435\u043c\u044b\u0439 \u0444\u043e\u0440\u043c\u0430\u0442 qr \u043a\u043e\u0434\u043e\u0432, \u0434\u0435\u0444\u043e\u043b\u0442\u043d\u0443\u044e \u0441\u0442\u0440\u043e\u043a\u0443 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u00ab\u0441\u0435\u0442\u0442\u0438\u043c\u00bb \u043a\u0430\u043a \u043f\u0443\u0441\u0442\u0443\u044e, \u0443\u0431\u0438\u0440\u0430\u0435\u043c \u0441\u0442\u0430\u043d\u0434\u0430\u0440\u0442\u043d\u0443\u044e \u0440\u0430\u043c\u043a\u0443 \u0432 \u0446\u0435\u043d\u0442\u0440\u0435 \u044d\u043a\u0440\u0430\u043d\u0430. \u041e\u0442\u0434\u0435\u043b\u044c\u043d\u043e \u0441\u0442\u043e\u0438\u0442 \u043e\u0441\u0442\u0430\u043d\u043e\u0432\u0438\u0442\u044c\u0441\u044f \u043d\u0430 \u044d\u0442\u043e\u043c \u043a\u0443\u0441\u043a\u0435 \u043a\u043e\u0434\u0430:<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/4f3\/086\/243\/4f3086243762854a573f99277c17c333.png\" width=\"560\" height=\"114\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/4f3\/086\/243\/4f3086243762854a573f99277c17c333.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041a\u043e\u0433\u0434\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0451\u0442 qr \u043a\u043e\u0434, \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u044d\u0442\u043e\u0433\u043e \u043e\u043d\u0430 \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u0442 \u0432 callback &#8212;<strong>\u00a0barcodeResult<em>(<\/em>result: BarcodeResult?<em>)<\/em><\/strong><em>. \u0412 \u043d\u0435\u043c \u0438\u043c\u0435\u044f \u0441\u0441\u044b\u043b\u043a\u0443 \u043d\u0430\u00a0<\/em><strong>MainActivity\u00a0<\/strong>\u0447\u0435\u0440\u0435\u0437 \u043e\u0431\u0449\u0438\u0439 \u043a\u043e\u043d\u0442\u0435\u043a\u0441\u0442, \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u043c \u043c\u0435\u0442\u043e\u0434\u00a0<strong>result\u00a0<\/strong>\u043d\u0430\u0448\u0435\u0433\u043e\u00a0<strong>ResultCallback\u00a0<\/strong>\u0438 \u0447\u0435\u0440\u0435\u0437 \u043d\u0435\u0433\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0441\u0442\u0440\u043e\u043a\u0443 \u0441 \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u043e\u043c. \u0418 \u0443\u0436\u0435 \u0432 \u0441\u0430\u043c\u043e\u043c\u00a0<strong>MainActivity\u00a0<\/strong>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f\u00a0<strong>EventChannel\u00a0<\/strong>\u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0434\u0430\u043b\u044c\u0448\u0435 \u2014 \u0432\u043e Flutter \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0435.<\/p>\n<figure class=\"full-width\"><img loading=\"lazy\" decoding=\"async\" src=\"https:\/\/habrastorage.org\/r\/w1560\/getpro\/habr\/upload_files\/81f\/e6d\/eb5\/81fe6deb59f9b8eaee61938340f1184e.png\" width=\"560\" height=\"348\" data-src=\"https:\/\/habrastorage.org\/getpro\/habr\/upload_files\/81f\/e6d\/eb5\/81fe6deb59f9b8eaee61938340f1184e.png\"\/><figcaption><\/figcaption><\/figure>\n<p>\u041a\u043e\u0434 \u0432\u044b\u0448\u0435 \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f \u043e\u0431\u0440\u0430\u0431\u043e\u0442\u0447\u0438\u043a\u043e\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0439 \u043e\u0442\u043f\u0440\u0430\u0432\u043b\u044f\u0435\u043c\u044b\u0445 \u0438\u0437 flutter \u0441\u0440\u0435\u0434\u044b. \u0423 <strong>MethodChannel<\/strong> \u043f\u0440\u0438\u043d\u0438\u043c\u0430\u0435\u0442 <strong>MethodCallHandler<\/strong> \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u044f \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043c\u044b \u0443\u0437\u043d\u0430\u0451\u043c \u043a\u0430\u043a\u043e\u0439 \u043c\u0435\u0442\u043e\u0434 \u0441\u0435\u0439\u0447\u0430\u0441 \u0432\u044b\u0437\u044b\u0432\u0430\u0435\u0442\u0441\u044f \u0438 \u0440\u0435\u0430\u0433\u0438\u0440\u0443\u0435\u043c \u043d\u0430 \u043d\u0435\u0433\u043e. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043a\u043e\u0434\u0435 \u043c\u044b \u0432\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u0438\u043b\u0438 \u0432\u044b\u043a\u043b\u044e\u0447\u0430\u0435\u043c \u043f\u043e\u0434\u0441\u0432\u0435\u0442\u043a\u0443 \u043a\u0430\u043c\u0435\u0440\u044b.<\/p>\n<p>\u041a\u043e\u0440\u043e\u0442\u043a\u043e\u0435 \u0432\u0438\u0434\u0435\u043e \u0441 \u043f\u0440\u0438\u043c\u0435\u0440\u043e\u043c \u044d\u0442\u043e\u0433\u043e \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f:<\/p>\n<div class=\"tm-iframe_temp\" data-src=\"https:\/\/embedd.srv.habr.com\/iframe\/619ca931122cc8f638696885\" data-style=\"\" id=\"619ca931122cc8f638696885\" width=\"\"><\/div>\n<p><a href=\"https:\/\/gitlab.com\/postflow\/flutter_qr_code_plugin\" rel=\"noopener noreferrer nofollow\">\u0418\u0441\u0445\u043e\u0434\u043d\u044b\u0439 \u043a\u043e\u0434 \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f<\/a><\/p>\n<p><a href=\"https:\/\/github.com\/journeyapps\/zxing-android-embedded\" rel=\"noopener noreferrer nofollow\"><strong>zxing-android-embedded<\/strong><\/a><\/p>\n<\/div>\n<\/div>\n<\/div>\n<p><!----><!----><\/div>\n<p><!----><!----><br \/> \u0441\u0441\u044b\u043b\u043a\u0430 \u043d\u0430 \u043e\u0440\u0438\u0433\u0438\u043d\u0430\u043b \u0441\u0442\u0430\u0442\u044c\u0438 <a href=\"https:\/\/habr.com\/ru\/articles\/592129\/\"> https:\/\/habr.com\/ru\/articles\/592129\/<\/a><\/p>\n","protected":false},"excerpt":{"rendered":"<div><!--[--><!--]--><\/div>\n<div id=\"post-content-body\">\n<div>\n<div class=\"article-formatted-body article-formatted-body article-formatted-body_version-2\">\n<div xmlns=\"http:\/\/www.w3.org\/1999\/xhtml\">\n<p>\u0418\u0437 \u0431\u0435\u0441\u043f\u043b\u0430\u0442\u043d\u044b\u0445 \u0434\u043e\u0441\u0442\u0443\u043f\u043d\u044b\u0445 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a \u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 qr \u043a\u043e\u0434\u0430\u043c\u0438 \u0432 Android \u0441\u0430\u043c\u043e\u0439 \u043b\u0443\u0447\u0448\u0435\u0439 (\u043d\u0430 \u043c\u043e\u0439 \u043b\u0438\u0447\u043d\u044b\u0439 \u0432\u0437\u0433\u043b\u044f\u0434) \u044f\u0432\u043b\u044f\u0435\u0442\u0441\u044f zxing-android-embedded. \u0427\u0430\u0441\u0442\u043e, UI \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043f\u0440\u0435\u0434\u043e\u0441\u0442\u0430\u0432\u043b\u044f\u0435\u0442 \u044d\u0442\u0430 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0430 \u043d\u0435 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u043e \u0438\u043b\u0438 \u043d\u0443\u0436\u0435\u043d \u043a\u0430\u043a\u043e\u0439-\u0442\u043e \u0438\u043d\u043e\u0439.\u00a0<strong>\u0412 \u044d\u0442\u043e\u0439 \u0441\u0442\u0430\u0442\u044c\u0435 \u043f\u043e\u0439\u0434\u0435\u0442 \u0440\u0435\u0447\u044c \u043e \u0442\u043e\u043c, \u043a\u0430\u043a\u00a0<\/strong>\u00ab<strong>\u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0438\u0440\u043e\u0432\u0430\u0442\u044c<\/strong>\u00bb<strong>\u00a0UI \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0438 zxing-android-embedded \u0434\u043b\u044f \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u0432\u0430\u043d\u0438\u044f QR \u043a\u043e\u0434\u043e\u0432 \u043f\u0440\u0438 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0435\u0451 Flutter \u043f\u0440\u043e\u0435\u043a\u0442\u0435.<\/strong><\/p>\n<p>\u041f\u0440\u0435\u0434\u0441\u0442\u0430\u0432\u043b\u0435\u043d\u043d\u0430\u044f \u0441\u0442\u0430\u0442\u044c\u044f \u0438 \u043a\u043e\u0434 \u0432\u043c\u0435\u0441\u0442\u0435 \u0441 \u043d\u0435\u0439, \u0432\u0441\u0435\u0433\u043e \u043b\u0438\u0448\u044c \u043c\u0438\u043d\u0438\u043c\u0430\u043b\u044c\u043d\u044b\u0439 \u0434\u043e\u0441\u0442\u0430\u0442\u043e\u0447\u043d\u044b\u0439 \u043f\u0440\u0438\u043c\u0435\u0440 \u0434\u043b\u044f \u0434\u0435\u043c\u043e\u043d\u0441\u0442\u0440\u0430\u0446\u0438\u0438 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u0435\u0439 \u00ab\u043a\u0430\u0441\u0442\u043e\u043c\u0438\u0437\u0430\u0446\u0438\u0438\u00bb\u00a0<a href=\"https:\/\/github.com\/journeyapps\/zxing-android-embedded\" rel=\"noopener noreferrer nofollow\"><u>zxing-android<\/u><\/a>\u00a0\u0434\u043b\u044f \u0440\u0430\u0431\u043e\u0442\u044b \u0441 \u043d\u0435\u0439 \u0432\u043e flutter. \u0421\u0442\u0430\u0442\u044c\u044f \u0437\u0430\u0442\u0440\u0430\u0433\u0438\u0432\u0430\u0435\u0442 \u0442\u043e\u043b\u044c\u043a\u043e Android \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e \u043d\u0435 \u043a\u0430\u0441\u0430\u044f\u0441\u044c IOS.<\/p>\n<p>\u041c\u044b \u0431\u0443\u0434\u0435\u043c \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c \u0442\u0440\u0438 \u043e\u0441\u043d\u043e\u0432\u043d\u044b\u0445 \u043a\u043e\u043c\u043f\u043e\u043d\u0435\u043d\u0442\u0430 \u0434\u043b\u044f \u0432\u0437\u0430\u0438\u043c\u043e\u0434\u0435\u0439\u0441\u0442\u0432\u0438\u044f \u0441 \u044d\u0442\u043e\u0439 \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u043e\u0439 \u0438\u0437 flutter \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u043d\u0430\u043c \u043f\u043e\u0442\u0440\u0435\u0431\u0443\u0435\u0442\u0441\u044f:<\/p>\n<ul>\n<li>\n<p>PlatformViewLink<\/p>\n<\/li>\n<li>\n<p>MethodChannel<\/p>\n<\/li>\n<li>\n<p>EventChannel<\/p>\n<\/li>\n<\/ul>\n<h3>PlatformViewLink:<\/h3>\n<p>\u0414\u0430\u0451\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u00ab\u043f\u0440\u043e\u043a\u0438\u043d\u0443\u0442\u044c\u00bb \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 android \u044d\u043a\u0440\u0430\u043d(View) \u0432 \u0432\u0430\u0448\u0435 fluttter \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u042d\u0442\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0432 \u0442\u0435\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043a\u043e\u0433\u0434\u0430 \u0435\u0441\u0442\u044c \u0433\u043e\u0442\u043e\u0432\u043e\u0435, \u043f\u0440\u043e\u0432\u0435\u0440\u0435\u043d\u043d\u043e\u0435 \u0440\u0435\u0448\u0435\u043d\u0438\u0435 \u043f\u043e\u0434 \u043d\u0430\u0442\u0438\u0432\u043d\u0443\u044e \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u0443, \u0430 \u0432\u0440\u0435\u043c\u0435\u043d\u0438 \u043f\u0435\u0440\u0435\u0434\u0435\u043b\u044b\u0432\u0430\u0442\u044c \u043f\u043e\u0434 flutter \u043d\u0435 \u0445\u0432\u0430\u0442\u0430\u0435\u0442 \u0438 \u043b\u0435\u0433\u0447\u0435 \u043f\u043e\u043a\u0430\u0437\u0430\u0442\u044c android activity \u043d\u0430\u043f\u0440\u044f\u043c\u0443\u044e \u0432 \u0432\u0430\u0448\u0435\u043c flutter \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0438. \u041f\u043e \u0442\u0430\u043a\u043e\u043c\u0443 \u043f\u0440\u0438\u043d\u0446\u0438\u043f\u0443 \u0440\u0430\u0431\u043e\u0442\u0430\u044e\u0442 google maps \u0432\u043e flutter \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u044f\u0445. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u0447\u0435\u0440\u0435\u0437 PlatformViewLink \u043c\u044b \u0431\u0443\u0434\u0435\u043c \u043f\u043e\u043a\u0430\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0439 \u044d\u043a\u0440\u0430\u043d \u0441\u043e \u0441\u0442\u0440\u0438\u043c\u043e\u043c \u0444\u043e\u0442\u043e\u043a\u0430\u043c\u0435\u0440\u044b.<\/p>\n<h3>MethodChannel:<\/h3>\n<p>\u0414\u0430\u0451\u0442 \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b(android \u0438\u043b\u0438 ios \u0438 \u0442.\u0434.) \u0438\u0437 flutter \u0441\u0440\u0435\u0434\u044b \u0432 \u0438 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 . \u041d\u0430\u0434\u043e \u0437\u0430\u043c\u0435\u0442\u0438\u0442\u044c \u0447\u0442\u043e \u0432\u0441\u0435 \u0432\u044b\u0437\u043e\u0432\u044b \u043c\u0435\u0442\u043e\u0434\u043e\u0432 \u0430\u0441\u0438\u043d\u0445\u0440\u043e\u043d\u043d\u044b. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u043e\u0435\u043a\u0442\u0435 MethodChannel \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0447\u0442\u043e\u0431\u044b \u0432\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u0438 \u0432\u044b\u043a\u043b\u044e\u0447\u0430\u0442\u044c \u043f\u043e\u0434\u0441\u0432\u0435\u0442\u043a\u0443 \u0444\u043e\u0442\u043e\u043a\u0430\u043c\u0435\u0440\u044b.<\/p>\n<h3>EventChannel:<\/h3>\n<p>\u041f\u043e\u0447\u0442\u0438 \u0442\u043e \u0436\u0435 \u0441\u0430\u043c\u043e\u0435 \u0447\u0442\u043e \u0438 MethodChannel, \u0441 \u0442\u0435\u043c \u043b\u0438\u0448\u044c \u043e\u0442\u043b\u0438\u0447\u0438\u0435\u043c, \u0447\u0442\u043e \u043c\u044b \u043c\u043e\u0436\u0435\u043c \u043f\u043e\u0434\u043f\u0438\u0441\u0430\u0442\u044c\u0441\u044f \u043d\u0430 \u043f\u043e\u0442\u043e\u043a \u0441\u043e\u0431\u044b\u0442\u0438\u0439, \u0433\u0435\u043d\u0435\u0440\u0438\u0440\u0443\u0435\u043c\u044b\u0445 \u0432 \u043d\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435. \u0421\u0430\u043c\u044b\u0439 \u0447\u0430\u0441\u0442\u044b \u043a\u0435\u0439\u0441 \u044d\u0442\u043e \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u00ab\u0441\u043b\u0443\u0448\u0430\u0442\u044c\u00bb gps \u043a\u043e\u043e\u0440\u0434\u0438\u043d\u0430\u0442\u044b \u043e\u0442 \u043d\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u043f\u043b\u0430\u0442\u0444\u043e\u0440\u043c\u044b. \u0412 \u0434\u0430\u043d\u043d\u043e\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 EventChannel \u0431\u0443\u0434\u0435\u0442 \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u0441\u044f \u0434\u043b\u044f \u043e\u0442\u043f\u0440\u0430\u0432\u043a\u0438 \u0440\u0430\u0441\u043f\u043e\u0437\u043d\u0430\u043d\u043d\u043e\u0433\u043e QR \u043a\u043e\u0434\u0430 \u0438\u0437 android \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u044f \u0432 \u043d\u0430\u0448\u0435 flutter \u043f\u0440\u0438\u043b\u043e\u0436\u0435\u043d\u0438\u0435. \u041a\u043e\u043d\u0435\u0447\u043d\u043e, \u0434\u043b\u044f \u043f\u043e\u043b\u0443\u0447\u0435\u043d\u0438\u044f \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442\u0430 \u043c\u044b \u043c\u043e\u0433\u043b\u0438 \u0431\u044b \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c MethodChannel, \u043d\u0430\u043f\u0440\u0438\u043c\u0435\u0440 \u0441\u0430\u043c\u043e\u0441\u0442\u043e\u044f\u0442\u0435\u043b\u044c\u043d\u043e \u0437\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u044f \u0434\u0430\u043d\u043d\u044b\u0435 \u0441\u043a\u0430\u0436\u0435\u043c \u043a\u0430\u0436\u0434\u044b\u0435 10 \u0441\u0435\u043a\u0443\u043d\u0434. \u041d\u043e \u0442\u0430\u043a\u043e\u0439 \u043f\u043e\u0434\u0445\u043e\u0434 \u0432\u044b\u0433\u043b\u044f\u0434\u0438\u0442 \u043d\u0435 \u043e\u0447\u0435\u043d\u044c \u043f\u0440\u0430\u0432\u0438\u043b\u044c\u043d\u044b\u043c \u0432 \u0443\u0441\u043b\u043e\u0432\u0438\u044f\u0445, \u043a\u043e\u0433\u0434\u0430 \u0443 \u043d\u0430\u0441 \u0435\u0441\u0442\u044c \u0432\u043e\u0437\u043c\u043e\u0436\u043d\u043e\u0441\u0442\u044c \u043f\u043e\u043b\u0443\u0447\u0438\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u0438\u043c\u0435\u043d\u043d\u043e \u0442\u043e\u0433\u0434\u0430 \u043a\u043e\u0433\u0434\u0430 \u043e\u043d \u0433\u043e\u0442\u043e\u0432.<\/p>\n<p>\u0421\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u043f\u0443\u0441\u0442\u043e\u0439 flutter \u043f\u0440\u043e\u0435\u043a\u0442. \u0412 \u043a\u043e\u043d\u0441\u043e\u043b\u0438 \u0442\u0435\u0440\u043c\u0438\u043d\u0430\u043b\u0430 \u0432\u044b\u0448\u0435\u0439 \u043b\u044e\u0431\u0438\u043c\u043e\u0439 \u041e\u0421 \u0432\u044b\u043f\u043e\u043b\u043d\u0438\u043c \u043a\u043e\u043c\u0430\u043d\u0434\u0443:<\/p>\n<figure class=\"\"><figcaption><\/figcaption><\/figure>\n<p>\u041e\u0442\u043a\u0440\u043e\u0435\u043c\u00a0<strong>main.dart<\/strong>. \u0414\u043e\u0431\u0430\u0432\u0438\u043c \u0432 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435 home \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u0430\u00a0<strong>MaterialApp\u00a0<\/strong>\u0432\u0438\u0434\u0436\u0435\u0442\u0430, QrCodePage &#8212; \u0432\u0438\u0434\u0436\u0435\u0442, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u043e\u0431\u0435\u0440\u043d\u0451\u0442 \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439 \u044d\u043a\u0440\u0430\u043d \u0432\u00a0<strong>Scaffold\u00a0<\/strong>\u0438 \u0434\u043e\u0431\u0430\u0432\u0438\u0442 AppBar \u0434\u043b\u044f \u043d\u0435\u0433\u043e:<\/p>\n<pre><code class=\"dart\">class MyApp extends StatelessWidget {   @override   Widget build(BuildContext context) {     return MaterialApp(       title: 'Flutter Demo',       theme: ThemeData(         primarySwatch: Colors.blue,       ),       home: QrCodePage(),     );   } }  class QrCodePage extends StatelessWidget {   QrCodePage({Key? key}) : super(key: key);    @override   Widget build(BuildContext context) {     return Scaffold(       appBar: AppBar(         title: Text(\"QR code App\"),       ),       body: PlatformView(),     );   } }<\/code><\/pre>\n<p><strong>PlatformView\u00a0<\/strong>&#8212; \u043e\u0441\u043d\u043e\u0432\u043d\u043e\u0439\u00a0<strong>StatefulWidge<\/strong>\u00a0\u0432\u0438\u0434\u0436\u0435\u0442. \u041e\u043d \u0431\u0443\u0434\u0435\u0442 \u043e\u0431\u0451\u0440\u0442\u043a\u043e\u0439 \u043d\u0430\u0434\u00a0<strong>PlatformViewLink\u00a0<\/strong>\u0438 \u0431\u0443\u0434\u0435\u0442 \u043d\u0435\u043f\u043e\u0441\u0440\u0435\u0434\u0441\u0442\u0432\u0435\u043d\u043d\u043e \u0442\u0440\u0430\u043d\u0441\u043b\u0438\u0440\u043e\u0432\u0430\u0442\u044c \u0432\u0438\u0434\u0435\u043e \u0441 \u043a\u0430\u043c\u0435\u0440\u044b:<\/p>\n<pre><code class=\"dart\">class _PlatformViewState extends State&lt;PlatformView> {   final MethodChannel platformMethodChannel = MethodChannel('flashlight');   bool isFlashOn = false;   bool permissionIsGranted = false;   String result = '';    void _handleQRcodeResult() {     const EventChannel _stream = EventChannel('qrcodeResultStream');     _stream.receiveBroadcastStream().listen((onData) {       print('EventChannel onData = $onData');       result = onData;       setState(() {});     });   }    Future&lt;void> _onFlash() async {     try {       dynamic result = await platformMethodChannel.invokeMethod('onFlash');       setState(() {         isFlashOn = true;       });     } on PlatformException catch (e) {       debugPrint('PlatformException ${e.message}');     }   }    Future&lt;void> _offFlash() async {     try {       dynamic result = await platformMethodChannel.invokeMethod('offFlash');       setState(() {         isFlashOn = false;       });     } on PlatformException catch (e) {       debugPrint('PlatformException ${e.message}');     }   }    @override   void initState() {     super.initState();     _handleQRcodeResult();     _checkPermissions();   }    _requestAppPermissions() {     showDialog(         context: context,         builder: (BuildContext context) => AlertDialog(               title: const Text('Permission required'),               content: const Text('Allow camera permissions'),               actions: &lt;Widget>[                 TextButton(                   onPressed: () {                     _checkPermissions();                     Navigator.pop(context, 'OK');                   },                   child: const Text('OK'),                 ),               ],             ));   }    _checkPermissions() async {     var status = await Permission.camera.status;     if (!status.isGranted) {       final PermissionStatus permissionStatus = await Permission.camera.request();       if (!permissionStatus.isGranted) {         _requestAppPermissions();       }     }   }    @override   Widget build(BuildContext context) {     final String viewType = '&lt;platform-view-type>';     final Map&lt;String, dynamic> creationParams = &lt;String, dynamic>{};     return result.isEmpty         ? Stack(             alignment: Alignment.center,             children: [               PlatformViewLink(                 viewType: viewType,                 surfaceFactory: (BuildContext context, PlatformViewController controller) {                   return Container(                     child: AndroidViewSurface(                       controller: controller as AndroidViewController,                       gestureRecognizers: const &lt;Factory&lt;OneSequenceGestureRecognizer>>{},                       hitTestBehavior: PlatformViewHitTestBehavior.opaque,                     ),                   );                 },                 onCreatePlatformView: (PlatformViewCreationParams params) {                   return PlatformViewsService.initSurfaceAndroidView(                     id: params.id,                     viewType: viewType,                     layoutDirection: TextDirection.ltr,                     creationParams: creationParams,                     creationParamsCodec: StandardMessageCodec(),                   )                     ..addOnPlatformViewCreatedListener(params.onPlatformViewCreated)                     ..create();                 },               ),               Align(                   alignment: Alignment.topCenter,                   child: ElevatedButton(                       onPressed: () {                         if (!isFlashOn) {                           _onFlash();                         } else {                           _offFlash();                         }                       },                       child: isFlashOn ? Text('off flashlight') : Text('on flashlight'))),               Align(                 alignment: Alignment.center,                 child: Container(                   height: 200,                   width: 200,                   decoration: BoxDecoration(                       color: Colors.transparent,                       border: Border.all(                         color: Colors.blueAccent,                         width: 5,                       )),                 ),               )             ],           )         : Container(             child: Center(child: Text('QR code result:\\n$result')),           );   } }<\/code><\/pre>\n<p>\u041f\u0430\u0440\u0443 \u043a\u043e\u043c\u043c\u0435\u043d\u0442\u0430\u0440\u0438\u0435\u0432 \u043a \u043a\u043e\u0434\u0443 \u0432\u0430\u0448\u0435:<\/p>\n<ul>\n<li>\n<p>\u0417\u0430\u043f\u0440\u0430\u0448\u0438\u0432\u0430\u0435\u043c \u0440\u0430\u0437\u0440\u0435\u0448\u0435\u043d\u0438\u044f \u043d\u0430 \u0440\u0430\u0431\u043e\u0442\u0443 \u0441 \u043a\u0430\u043c\u0435\u0440\u043e\u0439:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p>\u0412 \u043f\u043e\u043b\u0435 \u043a\u043b\u0430\u0441\u0441\u0430, \u0441\u043e\u0437\u0434\u0430\u0451\u043c\u00a0<strong>platformMethodChannel &#8212;\u00a0<\/strong>\u0447\u0435\u0440\u0435\u0437 \u044d\u0442\u043e\u0442 \u044d\u043a\u0437\u0435\u043c\u043f\u043b\u044f\u0440 \u0431\u0443\u0434\u0435\u043c \u0432\u044b\u0437\u044b\u0432\u0430\u0442\u044c \u043d\u0430\u0442\u0438\u0432\u043d\u044b\u0435 \u043c\u0435\u0442\u043e\u0434\u044b (\u043a\u043e\u0442\u043e\u0440\u044b\u0435 \u043c\u044b \u0441\u043e\u0437\u0434\u0430\u0434\u0438\u043c \u0447\u0443\u0442\u044c \u043f\u043e\u0437\u0436\u0435) \u0432 android \u043e\u043a\u0440\u0443\u0436\u0435\u043d\u0438\u0438. \u0410\u0440\u0433\u0443\u043c\u0435\u043d\u0442 \u0432 \u043a\u043e\u043d\u0441\u0442\u0440\u0443\u043a\u0442\u043e\u0440\u0435 \u2018flashlight\u2019 \u044d\u0442\u043e \u0441\u0432\u043e\u0435\u0433\u043e \u0440\u043e\u0434\u0430 \u0443\u043d\u0438\u043a\u0430\u043b\u044c\u043d\u044b\u0439 ID, \u043a\u043e\u0442\u043e\u0440\u044b\u0439 \u0434\u043e\u043b\u0436\u0435\u043d \u0431\u044b\u0442\u044c \u0438\u0434\u0435\u043d\u0442\u0438\u0447\u043d\u044b\u0439 \u0432\u043e flutter \u0438 \u043d\u0430\u0442\u0438\u0432\u043d\u043e\u0439 \u0441\u0440\u0435\u0434\u0435:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p>\u041c\u0435\u0442\u043e\u0434\u00a0<strong>_handleQRcodeResult()<\/strong>\u00a0&#8212; \u0431\u0443\u0434\u0435\u0442 \u043f\u043e\u043b\u0443\u0447\u0430\u0442\u044c \u0440\u0435\u0437\u0443\u043b\u044c\u0442\u0430\u0442 \u043e\u0442\u0441\u043a\u0430\u043d\u0438\u0440\u043e\u0432\u0430\u043d\u043d\u043e\u0433\u043e qr \u043a\u043e\u0434\u0430:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<\/li>\n<\/ul>\n<ul>\n<li>\n<p>\u041c\u0435\u0442\u043e\u0434\u044b<strong>\u00a0_onFlash()<\/strong>\u00a0\u0438\u00a0<strong>_offFlash<em>()<\/em><\/strong><em>\u00a0\u0432\u044b\u0437\u044b\u0432\u0430\u044e\u0442 \u0441\u043e\u043e\u0442\u0432\u0435\u0442\u0441\u0442\u0432\u0443\u044e\u0449\u0438\u0439 \u043c\u0435\u0442\u043e\u0434 \u043d\u0430 \u0441\u0442\u043e\u0440\u043e\u043d\u0435 Android \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a\u0430.<\/em><\/p>\n<\/li>\n<li>\n<p>\u0412 \u043d\u0435\u043a\u043e\u0442\u043e\u0440\u044b\u0445 \u0441\u043b\u0443\u0447\u0430\u044f\u0445 \u043d\u0435\u043e\u0431\u0445\u043e\u0434\u0438\u043c\u043e \u043f\u0435\u0440\u0435\u0434\u0430\u0442\u044c \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u044b \u0432 \u043d\u0430\u0442\u0438\u0432\u043d\u0443\u044e \u0441\u0440\u0435\u0434\u0443. \u0414\u043b\u044f \u044d\u0442\u043e\u0433\u043e \u0443\u0434\u043e\u0431\u043d\u043e \u0438\u0441\u043f\u043e\u043b\u044c\u0437\u043e\u0432\u0430\u0442\u044c\u00a0<strong>creationParams<\/strong>. \u041d\u043e \u0432 \u043d\u0430\u0448\u0435\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u043f\u0430\u0440\u0430\u043c\u0435\u0442\u0440\u043e\u0432 \u0434\u043b\u044f \u043f\u0435\u0440\u0435\u0434\u0430\u0447\u0438 \u0443 \u043d\u0430\u0441 \u043d\u0435 \u0431\u0443\u0434\u0435\u0442:<\/p>\n<\/li>\n<\/ul>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<ul>\n<li>\n<p>\u0412 \u043a\u0430\u0447\u0435\u0441\u0442\u0432\u0435\u00a0<strong>ViewGroup\u00a0<\/strong>\u0438\u0441\u043f\u043e\u043b\u044c\u0437\u0443\u0435\u043c\u00a0<strong>Stack\u00a0<\/strong>\u0434\u043b\u044f \u0442\u043e\u0433\u043e \u0447\u0442\u043e\u0431 \u0440\u0430\u0441\u043f\u043e\u043b\u043e\u0436\u0438\u0442\u044c \u0434\u043e\u043f\u043e\u043b\u043d\u0438\u0442\u0435\u043b\u044c\u043d\u044b\u0435 UI \u044d\u043b\u0435\u043c\u0435\u043d\u0442\u044b. \u0412 \u043c\u043e\u0451\u043c \u043f\u0440\u0438\u043c\u0435\u0440\u0435 \u044d\u0442\u043e \u0440\u0430\u043c\u043a\u0430 \u0432 \u0446\u0435\u043d\u0442\u0440 \u044d\u043a\u0440\u0430\u043d\u0430(<strong>Container<\/strong>\u00a0\u0441 \u043f\u0440\u043e\u0437\u0440\u0430\u0447\u043d\u044b\u043c \u0444\u043e\u043d\u043e\u043c \u0438\u00a0<strong>BoxDecoration<\/strong>) \u0438\u00a0<strong>ElevatedButton<\/strong>\u00a0\u043d\u0430\u0434 \u043d\u0435\u0439 \u0434\u043b\u044f \u0432\u043a\u043b\u044e\u0447\u0435\u043d\u0438\u044f \u043f\u043e\u0434\u0441\u0432\u0435\u0442\u043a\u0438.<\/p>\n<\/li>\n<\/ul>\n<h2>\u0412\u0437\u0433\u043b\u044f\u043d\u0435\u043c \u043d\u0430 Android \u0440\u0435\u0430\u043b\u0438\u0437\u0430\u0446\u0438\u044e:<\/h2>\n<p>\u0412\u00a0<strong>build.gradle<\/strong>\u00a0\u043c\u043e\u0434\u0443\u043b\u044f app (android\/app\/build.gradle) \u043f\u043e\u0434\u043a\u043b\u044e\u0447\u0438\u043c \u0431\u0438\u0431\u043b\u0438\u043e\u0442\u0435\u043a\u0443. \u0412 \u0440\u0430\u0437\u0434\u0435\u043b dependencies \u0434\u043e\u0431\u0430\u0432\u0438\u043c:<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 MainActivity, \u0432 \u043c\u0435\u0442\u043e\u0434\u0435\u00a0<strong>configureFlutterEngine, EventChannel<\/strong><\/p>\n<pre><code class=\"dart\">class MainActivity : FlutterFragmentActivity(), LifecycleOwner, ResultCallback {     var myEvents: EventChannel.EventSink? = null      override fun configureFlutterEngine(flutterEngine: FlutterEngine) {         super.configureFlutterEngine(flutterEngine)         EventChannel(flutterEngine.dartExecutor.binaryMessenger, \"qrcodeResultStream\")                 .setStreamHandler(object : EventChannel.StreamHandler {                     override fun onListen(arguments: Any?, events: EventChannel.EventSink?) {                         myEvents = events                     }                      override fun onCancel(arguments: Any?) {                         myEvents = null                     }                 })          flutterEngine                 .platformViewsController                 .registry                 .registerViewFactory(\"&lt;platform-view-type>\", NativeViewFactory())     }      override fun result(result: String) {         myEvents?.success(result)     }      override fun getMyFlutterEngine(): FlutterEngine? = flutterEngine }<\/code><\/pre>\n<p><strong>EventChannel.StreamHandler<\/strong> \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0435\u0442 \u043d\u0430\u043c \u043e\u0431\u044a\u0435\u043a\u0442\u00a0<strong>EventChannel.EventSink\u00a0<\/strong>\u0432\u044b\u0437\u044b\u0432\u0430\u044f \u043d\u0430 \u043a\u043e\u0442\u043e\u0440\u043e\u043c\u00a0<strong>.success(result)<\/strong>\u00a0\u2014 \u043c\u044b \u043f\u0435\u0440\u0435\u0434\u0430\u0451\u043c \u0441\u043e\u0431\u044b\u0442\u0438\u0435 \u0432\u043e flutter \u0444\u0440\u0435\u0439\u043c\u0432\u043e\u0440\u043a. \u0412 \u043d\u0430\u0448\u0435\u043c \u0441\u043b\u0443\u0447\u0430\u0435 \u044d\u0442\u043e \u0431\u0443\u0434\u0435\u0442 \u0441\u0442\u0440\u043e\u043a\u0430 \u0441 QR \u043a\u043e\u0434\u043e\u043c.<\/p>\n<figure class=\"full-width\"><figcaption><\/figcaption><\/figure>\n<p>\u0412 \u043c\u0435\u0442\u043e\u0434\u0435 \u0432\u044b\u0448\u0435 \u043c\u044b \u0440\u0435\u0433\u0438\u0441\u0442\u0440\u0438\u0440\u0443\u0435\u043c \u0444\u0430\u0431\u0440\u0438\u043a\u0443 \u043a\u043e\u0442\u043e\u0440\u0430\u044f \u043c\u043e\u0436\u0435\u0442 \u0432\u043e\u0437\u0432\u0440\u0430\u0449\u0430\u0442\u044c \u0440\u0430\u0437\u043d\u044b\u0435 View \u0432<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[],"tags":[],"class_list":["post-390181","post","type-post","status-publish","format-standard","hentry"],"_links":{"self":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/390181","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=390181"}],"version-history":[{"count":0,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=\/wp\/v2\/posts\/390181\/revisions"}],"wp:attachment":[{"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=390181"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=390181"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/savepearlharbor.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=390181"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}