Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions lib/flutter_qr_reader.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@ class FlutterQrReader {
static const MethodChannel _channel = const MethodChannel('me.hetian.flutter_qr_reader');

static Future<String> imgScan(File file) async {
if (file?.existsSync() == false) {
return null;
}
if (!file?.existsSync()) file.createSync();
try {
final rest = await _channel.invokeMethod("imgQrCode", {"file": file.path});
return rest;
Expand Down
40 changes: 15 additions & 25 deletions lib/qrcode_reader_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import 'package:image_picker/image_picker.dart';
/// Relevant privileges must be obtained before use
class QrcodeReaderView extends StatefulWidget {
final Widget headerWidget;
final Future Function(String) onScan;
final Future Function(String, BuildContext context) onScan;
final double scanBoxRatio;
final Color boxLineColor;
final Widget helpWidget;
Expand All @@ -31,7 +31,7 @@ class QrcodeReaderView extends StatefulWidget {
/// qrViewKey.currentState.startScan();
/// ```
class QrcodeReaderViewState extends State<QrcodeReaderView>
with TickerProviderStateMixin {
with SingleTickerProviderStateMixin {
QrReaderViewController _controller;
AnimationController _animationController;
bool openFlashlight;
Expand Down Expand Up @@ -86,7 +86,7 @@ class QrcodeReaderViewState extends State<QrcodeReaderView>
if (isScan == true) return;
isScan = true;
stopScan();
await widget.onScan(data);
await widget.onScan(data, context);
}

void startScan() {
Expand All @@ -109,12 +109,13 @@ class QrcodeReaderViewState extends State<QrcodeReaderView>
Future _scanImage() async {
stopScan();
var image = await ImagePicker.pickImage(source: ImageSource.gallery);
if(image.existsSync() == false) image.createSync();
if (image == null) {
startScan();
return;
}
final rest = await FlutterQrReader.imgScan(image);
await widget.onScan(rest);
await widget.onScan(rest, context);
startScan();
}

Expand Down Expand Up @@ -179,7 +180,8 @@ class QrcodeReaderViewState extends State<QrcodeReaderView>
alignment: Alignment.center,
child: DefaultTextStyle(
style: TextStyle(color: Colors.white),
child: widget.helpWidget ?? Text("请将二维码置于方框中"),
textAlign: TextAlign.center,
child: widget.helpWidget ?? Text("Galeriden fotoğraf seçmek için aşağıdaki butonu kullanın."),
),
),
),
Expand All @@ -205,14 +207,18 @@ class QrcodeReaderViewState extends State<QrcodeReaderView>
: 12,
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceEvenly,
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
GestureDetector(
behavior: HitTestBehavior.translucent,
onTap: _scanImage,
child: Container(
width: 45,
height: 45,
width: 80,
height: 80,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(40)),
border: Border.all(color: Colors.white30, width: 12),
),
alignment: Alignment.center,
child: Image.asset(
"assets/tool_img.png",
Expand All @@ -223,23 +229,7 @@ class QrcodeReaderViewState extends State<QrcodeReaderView>
),
),
),
Container(
width: 80,
height: 80,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(40)),
border: Border.all(color: Colors.white30, width: 12),
),
alignment: Alignment.center,
child: Image.asset(
"assets/tool_qrcode.png",
package: "flutter_qr_reader",
width: 35,
height: 35,
color: Colors.white54,
),
),
SizedBox(width: 45, height: 45),

],
),
)
Expand Down