Открыть боковую панель
Aurora OS
Flutter
Flutter Community Plugins
qr_code_scanner_aurora
Коммиты
8de0d0cf
Коммит
8de0d0cf
создал
Ноя 24, 2025
по автору
OMP Education
Просмотр файлов
[Source] Refactoring.
владелец
bdaa12c6
Изменения
8
Скрыть пробелы
Построчно
Рядом
example/aurora/desktop/ru.aurora.qr_code_scanner_aurora_example.desktop
Просмотр файла @
8de0d0cf
[Desktop Entry]
Type=Application
Name=Q
r c
ode
s
canner
Name=Q
R C
ode
S
canner
Comment=Example qr_code_scanner for OS Aurora.
Icon=ru.aurora.qr_code_scanner_aurora_example
Exec=/usr/bin/ru.aurora.qr_code_scanner_aurora_example
...
...
example/lib/main.dart
Просмотр файла @
8de0d0cf
// SPDX-FileCopyrightText: Copyright 2024 Open Mobile Platform LLC <community@omp.ru>
// SPDX-License-Identifier: BSD-3-Clause
import
'package:flutter/material.dart'
;
import
'package:qr_code_scanner_aurora/qr_code_scanner.dart'
;
...
...
@@ -15,16 +16,18 @@ class MainWidget extends StatelessWidget {
@override
Widget
build
(
BuildContext
context
)
{
return
Scaffold
(
body:
Center
(
child:
ElevatedButton
(
onPressed:
()
{
Navigator
.
of
(
context
)
.
push
(
MaterialPageRoute
(
builder:
(
ctx
)
=
>
const
ScannerPage
()));
},
child:
const
Text
(
"Open camera"
)),
),
body:
Center
(
child:
ElevatedButton
(
onPressed:
()
{
Navigator
.
of
(
context
)
.
push
(
MaterialPageRoute
(
builder:
(
ctx
)
=
>
const
ScannerPage
()));
},
child:
const
Text
(
"Open camera"
)),
),
);
}
}
class
ScannerPage
extends
StatefulWidget
{
const
ScannerPage
({
super
.
key
});
...
...
@@ -50,80 +53,84 @@ class _MyAppState extends State<ScannerPage> {
@override
Widget
build
(
BuildContext
context
)
{
// For this example we check how width or tall the device is and change the scanArea and overlay accordingly.
var
scanArea
=
(
MediaQuery
.
of
(
context
)
.
size
.
width
<
400
||
MediaQuery
.
of
(
context
)
.
size
.
height
<
400
)
?
250.0
:
350.0
;
var
scanArea
=
(
MediaQuery
.
of
(
context
)
.
size
.
width
<
400
||
MediaQuery
.
of
(
context
)
.
size
.
height
<
400
)
?
250.0
:
350.0
;
return
Scaffold
(
appBar:
AppBar
(
title:
const
Text
(
'QR code scanner'
),
),
floatingActionButton:
Visibility
(
visible:
_states
==
States
.
viewfinder
,
child:
ElevatedButton
.
icon
(
onPressed:
()
async
{
await
_controller
?.
flipCamera
();
},
icon:
const
Icon
(
Icons
.
flip_camera_ios
),
label:
const
Text
(
'Flip camera'
),
),
appBar:
AppBar
(
title:
const
Text
(
'QR code scanner'
),
),
floatingActionButton:
Visibility
(
visible:
_states
==
States
.
viewfinder
,
child:
ElevatedButton
.
icon
(
onPressed:
()
async
{
await
_controller
?.
flipCamera
();
},
icon:
const
Icon
(
Icons
.
flip_camera_ios
),
label:
const
Text
(
'Flip camera'
),
),
body:
SizedBox
.
expand
(
child:
Container
(
color:
Colors
.
black
,
child:
Stack
(
children:
[
if
(
_states
==
States
.
error
)
const
Center
(
child:
Text
(
'An error occurred.'
,
style:
TextStyle
(
color:
Colors
.
red
)),
),
if
(
_states
==
States
.
barcode
)
Center
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
Text
(
'QR:
${_result?.code}
'
.
trim
(),
textAlign:
TextAlign
.
center
,
style:
const
TextStyle
(
color:
Colors
.
white
)),
const
SizedBox
(
height:
12.0
),
ElevatedButton
.
icon
(
onPressed:
()
=
>
setState
(()
{
_controller
?.
resumeCamera
();
_states
=
States
.
viewfinder
;
}),
icon:
const
Icon
(
Icons
.
play_arrow
),
label:
const
Text
(
'Play'
),
),
],
),
),
body:
SizedBox
.
expand
(
child:
Container
(
color:
Colors
.
black
,
child:
Stack
(
children:
[
if
(
_states
==
States
.
error
)
const
Center
(
child:
Text
(
'An error occurred.'
,
style:
TextStyle
(
color:
Colors
.
red
)),
),
if
(
_states
==
States
.
barcode
)
Center
(
child:
Column
(
mainAxisAlignment:
MainAxisAlignment
.
center
,
children:
[
Text
(
'QR:
${_result?.code}
'
.
trim
(),
textAlign:
TextAlign
.
center
,
style:
const
TextStyle
(
color:
Colors
.
white
)),
const
SizedBox
(
height:
12.0
),
ElevatedButton
.
icon
(
onPressed:
()
=
>
setState
(()
{
_controller
?.
resumeCamera
();
_states
=
States
.
viewfinder
;
}),
icon:
const
Icon
(
Icons
.
play_arrow
),
label:
const
Text
(
'Play'
),
),
],
),
Visibility
(
maintainSize:
true
,
maintainAnimation:
true
,
maintainState:
true
,
visible:
_states
==
States
.
viewfinder
,
child:
QRView
(
key:
_globalKey
,
onQRViewCreated:
_onQRViewCreated
,
overlay:
QrScannerOverlayShape
(
borderColor:
Colors
.
purple
,
borderRadius:
10
,
borderLength:
30
,
borderWidth:
10
,
cutOutSize:
scanArea
,
),
onPermissionSet:
(
ctrl
,
p
)
=
>
{
// Error permission
if
(
mounted
&&
!
p
)
{
setState
(()
{
_states
=
States
.
error
;
})
}
},
),
Visibility
(
maintainSize:
true
,
maintainAnimation:
true
,
maintainState:
true
,
visible:
_states
==
States
.
viewfinder
,
child:
QRView
(
key:
_globalKey
,
onQRViewCreated:
_onQRViewCreated
,
overlay:
QrScannerOverlayShape
(
borderColor:
Colors
.
purple
,
borderRadius:
10
,
borderLength:
30
,
borderWidth:
10
,
cutOutSize:
scanArea
,
),
onPermissionSet:
(
ctrl
,
p
)
=
>
{
// Error permission
if
(
mounted
&&
!
p
)
{
setState
(()
{
_states
=
States
.
error
;
})
}
},
),
]
,
)
,
)
,
]
,
),
),
),
);
}
...
...
example/pubspec.lock
удалено
100644 → 0
Просмотр файла @
bdaa12c6
# Generated by pub
# See https://dart.dev/tools/pub/glossary#lockfile
packages:
archive:
dependency: transitive
description: flutter
source: sdk
version: "3.6.1"
async:
dependency: transitive
description: flutter
source: sdk
version: "2.12.0"
aurora_ffmpeg_libs:
dependency: transitive
description: flutter
source: sdk
version: "5.1.6"
aurora_libvpx:
dependency: transitive
description: flutter
source: sdk
version: "1.9.0"
aurora_libyuv:
dependency: transitive
description: flutter
source: sdk
version: "1.0.1848"
aurora_libzxing:
dependency: transitive
description: flutter
source: sdk
version: "2.1.0"
camera:
dependency: transitive
description: flutter
source: sdk
version: "0.11.0+2"
camera_aurora:
dependency: transitive
description: flutter
source: sdk
version: "0.6.0"
camera_platform_interface:
dependency: transitive
description: flutter
source: sdk
version: "2.10.0"
characters:
dependency: transitive
description: flutter
source: sdk
version: "1.4.0"
collection:
dependency: transitive
description: flutter
source: sdk
version: "1.19.1"
cross_file:
dependency: transitive
description: flutter
source: sdk
version: "0.3.4+2"
crypto:
dependency: transitive
description: flutter
source: sdk
version: "3.0.6"
cupertino_icons:
dependency: "direct main"
description: flutter
source: sdk
version: "1.0.8"
flutter:
dependency: "direct main"
description: flutter
source: sdk
version: "0.0.0"
flutter_lints:
dependency: "direct dev"
description: flutter
source: sdk
version: "4.0.0"
flutter_plugin_android_lifecycle:
dependency: transitive
description: flutter
source: sdk
version: "2.0.28"
flutter_web_plugins:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
image:
dependency: transitive
description: flutter
source: sdk
version: "4.3.0"
js:
dependency: transitive
description:
name: js
sha256: f2c445dce49627136094980615a031419f7f3eb393237e4ecd97ac15dea343f3
url: "https://pub.dev"
source: hosted
version: "0.6.7"
lints:
dependency: transitive
description: flutter
source: sdk
version: "4.0.0"
material_color_utilities:
dependency: transitive
description: flutter
source: sdk
version: "0.11.1"
meta:
dependency: transitive
description: flutter
source: sdk
version: "1.16.0"
path:
dependency: transitive
description: flutter
source: sdk
version: "1.9.1"
path_provider:
dependency: transitive
description: flutter
source: sdk
version: "2.1.5"
path_provider_aurora:
dependency: transitive
description: flutter
source: sdk
version: "0.6.1"
path_provider_platform_interface:
dependency: transitive
description: flutter
source: sdk
version: "2.1.2"
petitparser:
dependency: transitive
description: flutter
source: sdk
version: "6.1.0"
platform:
dependency: transitive
description: flutter
source: sdk
version: "3.1.6"
plugin_platform_interface:
dependency: transitive
description: flutter
source: sdk
version: "2.1.8"
qr_code_scanner:
dependency: transitive
description:
name: qr_code_scanner
sha256: f23b68d893505a424f0bd2e324ebea71ed88465d572d26bb8d2e78a4749591fd
url: "https://pub.dev"
source: hosted
version: "1.0.1"
qr_code_scanner_aurora:
dependency: "direct main"
description:
path: ".."
relative: true
source: path
version: "0.0.1"
sky_engine:
dependency: transitive
description: flutter
source: sdk
version: "0.0.0"
stream_transform:
dependency: transitive
description: flutter
source: sdk
version: "2.1.1"
typed_data:
dependency: transitive
description: flutter
source: sdk
version: "1.4.0"
vector_math:
dependency: transitive
description: flutter
source: sdk
version: "2.1.4"
web:
dependency: transitive
description: flutter
source: sdk
version: "1.1.0"
xml:
dependency: transitive
description: flutter
source: sdk
version: "6.5.0"
sdks:
dart: ">=3.7.0-0 <4.0.0"
flutter: ">=3.27.0"
example/pubspec.yaml
Просмотр файла @
8de0d0cf
...
...
@@ -2,7 +2,7 @@
# SPDX-License-Identifier: BSD-3-Clause
name
:
qr_code_scanner_aurora_example
description
:
"
Demonstrates
how
to
use
the
qr_code_scanner_aurora
plugin."
version
:
0.0.
1
version
:
0.0.
2
publish_to
:
'
none'
...
...
lib/aurora/aurora_qr_camera.dart
Просмотр файла @
8de0d0cf
// SPDX-FileCopyrightText: Copyright 2024 Open Mobile Platform LLC <community@omp.ru>
// SPDX-License-Identifier: BSD-3-Clause
import
'dart:async'
;
import
'package:camera_aurora/camera_aurora.dart'
;
import
'package:flutter/material.dart'
;
import
'package:camera/camera.dart'
;
// ignore_for_file: implementation_imports
import
'package:qr_code_scanner/src/types/camera.dart'
;
import
'package:qr_code_scanner/src/types/features.dart'
;
import
'package:qr_code_scanner/src/types/barcode.dart'
;
...
...
lib/aurora/aurora_view.dart
Просмотр файла @
8de0d0cf
// SPDX-FileCopyrightText: Copyright 2024 Open Mobile Platform LLC <community@omp.ru>
// SPDX-License-Identifier: BSD-3-Clause
import
'dart:async'
;
import
'package:flutter/material.dart'
;
...
...
lib/plugin/qr_code_scanner.dart
Просмотр файла @
8de0d0cf
...
...
@@ -82,7 +82,9 @@ class _QRViewState extends State<QRView> {
return
NotificationListener
(
onNotification:
onNotification
,
child:
SizeChangedLayoutNotifier
(
child:
(
widget
.
overlay
!=
null
)
?
_getPlatformQrViewWithOverlay
()
:
_getPlatformQrView
(),
child:
(
widget
.
overlay
!=
null
)
?
_getPlatformQrViewWithOverlay
()
:
_getPlatformQrView
(),
),
);
}
...
...
@@ -94,7 +96,8 @@ class _QRViewState extends State<QRView> {
}
Future
<
void
>
updateDimensions
()
async
{
await
QRViewController
.
updateDimensions
(
widget
.
key
as
GlobalKey
<
State
<
StatefulWidget
>>,
_channel
,
await
QRViewController
.
updateDimensions
(
widget
.
key
as
GlobalKey
<
State
<
StatefulWidget
>>,
_channel
,
overlay:
widget
.
overlay
);
}
...
...
@@ -132,14 +135,16 @@ class _QRViewState extends State<QRView> {
return
AndroidView
(
viewType:
'net.touchcapture.qr.flutterqr/qrview'
,
onPlatformViewCreated:
_onPlatformViewCreated
,
creationParams:
_QrCameraSettings
(
cameraFacing:
widget
.
cameraFacing
)
.
toMap
(),
creationParams:
_QrCameraSettings
(
cameraFacing:
widget
.
cameraFacing
)
.
toMap
(),
creationParamsCodec:
const
StandardMessageCodec
(),
);
case
TargetPlatform
.
iOS
:
return
UiKitView
(
viewType:
'net.touchcapture.qr.flutterqr/qrview'
,
onPlatformViewCreated:
_onPlatformViewCreated
,
creationParams:
_QrCameraSettings
(
cameraFacing:
widget
.
cameraFacing
)
.
toMap
(),
creationParams:
_QrCameraSettings
(
cameraFacing:
widget
.
cameraFacing
)
.
toMap
(),
creationParamsCodec:
const
StandardMessageCodec
(),
);
case
TargetPlatform
.
aurora
:
...
...
@@ -159,9 +164,14 @@ class _QRViewState extends State<QRView> {
void
_onPlatformViewCreated
(
int
id
)
{
_channel
=
MethodChannel
(
'net.touchcapture.qr.flutterqr/qrview_
$id
'
);
// Start scan after creation of the view
final
controller
=
QRViewController
.
_
(
_channel
,
widget
.
key
as
GlobalKey
<
State
<
StatefulWidget
>>
?
,
widget
.
onPermissionSet
,
widget
.
cameraFacing
,
_cameraQrAurora
)
.
.
_startScan
(
widget
.
key
as
GlobalKey
<
State
<
StatefulWidget
>>,
widget
.
overlay
,
widget
.
formatsAllowed
);
final
controller
=
QRViewController
.
_
(
_channel
,
widget
.
key
as
GlobalKey
<
State
<
StatefulWidget
>>
?
,
widget
.
onPermissionSet
,
widget
.
cameraFacing
,
_cameraQrAurora
)
.
.
_startScan
(
widget
.
key
as
GlobalKey
<
State
<
StatefulWidget
>>,
widget
.
overlay
,
widget
.
formatsAllowed
);
// Initialize the controller for controlling the QRView
widget
.
onQRViewCreated
(
controller
);
...
...
@@ -225,7 +235,8 @@ class QRViewController {
final
MethodChannel
_channel
;
final
CameraFacing
_cameraFacing
;
final
CameraQrAurora
?
_cameraQrAurora
;
final
StreamController
<
Barcode
>
_scanUpdateController
=
StreamController
<
Barcode
>();
final
StreamController
<
Barcode
>
_scanUpdateController
=
StreamController
<
Barcode
>();
Stream
<
Barcode
>
get
scannedDataStream
=
>
_scanUpdateController
.
stream
;
...
...
@@ -233,14 +244,16 @@ class QRViewController {
bool
get
hasPermissions
=
>
_hasPermissions
;
/// Starts the barcode scanner
Future
<
void
>
_startScan
(
GlobalKey
key
,
QrScannerOverlayShape
?
overlay
,
List
<
BarcodeFormat
>
?
barcodeFormats
)
async
{
Future
<
void
>
_startScan
(
GlobalKey
key
,
QrScannerOverlayShape
?
overlay
,
List
<
BarcodeFormat
>
?
barcodeFormats
)
async
{
if
(
defaultTargetPlatform
==
TargetPlatform
.
aurora
)
{
return
_cameraQrAurora
!.
startScan
(
_scanUpdateController
);
}
// We need to update the dimension before the scan is started.
try
{
await
QRViewController
.
updateDimensions
(
key
,
_channel
,
overlay:
overlay
);
return
await
_channel
.
invokeMethod
(
'startScan'
,
barcodeFormats
?.
map
((
e
)
=
>
e
.
asInt
())
.
toList
()
??
[]);
return
await
_channel
.
invokeMethod
(
'startScan'
,
barcodeFormats
?.
map
((
e
)
=
>
e
.
asInt
())
.
toList
()
??
[]);
}
on
PlatformException
catch
(
e
)
{
throw
CameraException
(
e
.
code
,
e
.
message
);
}
...
...
@@ -254,7 +267,8 @@ class QRViewController {
try
{
var
cameraFacing
=
await
_channel
.
invokeMethod
(
'getCameraInfo'
)
as
int
;
if
(
cameraFacing
==
-
1
)
return
_cameraFacing
;
return
CameraFacing
.
values
[
await
_channel
.
invokeMethod
(
'getCameraInfo'
)
as
int
];
return
CameraFacing
.
values
[
await
_channel
.
invokeMethod
(
'getCameraInfo'
)
as
int
];
}
on
PlatformException
catch
(
e
)
{
throw
CameraException
(
e
.
code
,
e
.
message
);
}
...
...
@@ -266,7 +280,8 @@ class QRViewController {
return
_cameraQrAurora
!.
flipCamera
();
}
try
{
return
CameraFacing
.
values
[
await
_channel
.
invokeMethod
(
'flipCamera'
)
as
int
];
return
CameraFacing
.
values
[
await
_channel
.
invokeMethod
(
'flipCamera'
)
as
int
];
}
on
PlatformException
catch
(
e
)
{
throw
CameraException
(
e
.
code
,
e
.
message
);
}
...
...
@@ -338,7 +353,8 @@ class QRViewController {
return
_cameraQrAurora
!.
getSystemFeatures
();
}
try
{
var
features
=
await
_channel
.
invokeMapMethod
<
String
,
dynamic
>(
'getSystemFeatures'
);
var
features
=
await
_channel
.
invokeMapMethod
<
String
,
dynamic
>(
'getSystemFeatures'
);
if
(
features
!=
null
)
{
return
SystemFeatures
.
fromJson
(
features
);
}
...
...
@@ -358,7 +374,8 @@ class QRViewController {
}
/// Updates the view dimensions for iOS.
static
Future
<
bool
>
updateDimensions
(
GlobalKey
key
,
MethodChannel
channel
,
{
QrScannerOverlayShape
?
overlay
})
async
{
static
Future
<
bool
>
updateDimensions
(
GlobalKey
key
,
MethodChannel
channel
,
{
QrScannerOverlayShape
?
overlay
})
async
{
if
(
defaultTargetPlatform
==
TargetPlatform
.
iOS
)
{
// Add small delay to ensure the render box is loaded
await
Future
.
delayed
(
const
Duration
(
milliseconds:
300
));
...
...
@@ -397,7 +414,8 @@ class QRViewController {
}
if
(
defaultTargetPlatform
==
TargetPlatform
.
android
)
{
try
{
await
_channel
.
invokeMethod
(
'invertScan'
,
{
"isInvertScan"
:
isScanInvert
});
await
_channel
.
invokeMethod
(
'invertScan'
,
{
"isInvertScan"
:
isScanInvert
});
}
on
PlatformException
catch
(
e
)
{
throw
CameraException
(
e
.
code
,
e
.
message
);
}
...
...
lib/qr_code_scanner.dart
Просмотр файла @
8de0d0cf
// SPDX-FileCopyrightText: Copyright 2024 Open Mobile Platform LLC <community@omp.ru>
// SPDX-License-Identifier: BSD-3-Clause
export
'package:qr_code_scanner/src/qr_scanner_overlay_shape.dart'
;
export
'package:qr_code_scanner/src/types/barcode.dart'
;
export
'package:qr_code_scanner/src/types/barcode_format.dart'
;
...
...
Редактирование
Предварительный просмотр
Поддерживает Markdown
0%
Попробовать снова
или
прикрепить новый файл
.
Отмена
You are about to add
0
people
to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Отмена
Пожалуйста,
зарегистрируйтесь
или
войдите
чтобы прокомментировать