You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

124 lines
3.3 KiB

3 years ago
import 'dart:ui';
3 years ago
import 'package:flutter/material.dart';
3 years ago
// import 'package:flutter_scankit/scan_kit_widget.dart';
3 years ago
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/view_widget/my_appbar.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
3 years ago
import 'package:image_pickers/image_pickers.dart';
3 years ago
import 'package:permission_handler/permission_handler.dart';
3 years ago
import 'package:scan/scan.dart';
3 years ago
class QrCodeScanPage extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return _QrCodeScanPage();
}
}
class _QrCodeScanPage extends State<QrCodeScanPage> {
3 years ago
ScanController controller = ScanController();
final screenWidth = window.physicalSize.width;
final screenHeight = window.physicalSize.height;
@override
void initState() {
super.initState();
}
@override
3 years ago
Widget build(BuildContext context) {
3 years ago
return Scaffold(
body: Container(
child: Stack(
children: [
Positioned(
child: Column(
children: [
Expanded(
child: ScanView(
controller: controller,
scanAreaScale: 0.7,
scanLineColor: Colors.green.shade400,
onCapture: (data) {
if (data != null && data != "") {
Navigator.of(context).pop(data);
}
},
),
flex: 1,
),
],
),
top: 0,
bottom: 0,
left: 0,
right: 0,
),
Positioned(
child: MyAppBar(
title: "扫码",
titleColor: Colors.white,
leadingColor: Colors.white,
brightness: Brightness.dark,
background: Colors.transparent,
action: Container(
alignment: Alignment.center,
margin: EdgeInsets.only(right: 16.w),
child: GestureDetector(
onTap: () {
pickImage();
},
child: Text(
S.of(context).xiangce,
style: TextStyle(
color: Colors.black,
fontSize: 18.sp,
fontWeight: FontWeight.bold,
),
),
),
),
),
top: 0,
left: 0,
right: 0,
),
],
),
),
);
}
pickImage() async {
List<Media> medias = await ImagePickers.pickerPaths(
galleryMode: GalleryMode.image,
selectCount: 1,
showGif: true,
showCamera: false,
compressSize: 500,
uiConfig: UIConfig(
uiThemeColor: Color(0xFFFFFFFF),
),
cropConfig: CropConfig(
enableCrop: false,
),
);
if (medias != null && medias.length > 0) {
String result = await Scan.parse(medias[0].path);
if (result != null && result != "") {
Navigator.of(context).pop(result);
}
}
}
@override
void dispose() {
if (this.controller != null) {
this.controller.pause();
}
super.dispose();
3 years ago
}
}