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.
139 lines
3.8 KiB
139 lines
3.8 KiB
1 year ago
|
import 'dart:ui';
|
||
|
|
||
|
import 'package:flutter/cupertino.dart';
|
||
|
import 'package:flutter/material.dart';
|
||
|
import 'package:image_pickers/image_pickers.dart';
|
||
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
||
|
import 'package:scan/scan.dart';
|
||
|
import '../generated/l10n.dart';
|
||
|
|
||
|
class BusinessScanCode extends StatefulWidget {
|
||
|
|
||
|
@override
|
||
|
State<StatefulWidget> createState() {
|
||
|
return _BusinessScanCode();
|
||
|
}
|
||
|
}
|
||
|
|
||
|
class _BusinessScanCode extends State<BusinessScanCode>
|
||
|
with AutomaticKeepAliveClientMixin {
|
||
|
ScanController controller = ScanController();
|
||
|
final screenWidth = window.physicalSize.width;
|
||
|
final screenHeight = window.physicalSize.height;
|
||
|
|
||
|
@override
|
||
|
void initState() {
|
||
|
super.initState();
|
||
|
}
|
||
|
|
||
|
|
||
|
@override
|
||
|
void dispose() {
|
||
|
if (this.controller != null) {
|
||
|
this.controller.pause();
|
||
|
}
|
||
|
super.dispose();
|
||
|
}
|
||
|
|
||
|
@override
|
||
|
Widget build(BuildContext context) {
|
||
|
super.build(context);
|
||
|
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: Container(
|
||
|
margin: EdgeInsets.only(left:12.w,right: 16.w,top: 16.h),
|
||
|
child:Row(
|
||
|
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||
|
crossAxisAlignment: CrossAxisAlignment.center,
|
||
|
children: [
|
||
|
Expanded(child:Text(
|
||
|
S.of(context).saoma,
|
||
|
style: TextStyle(
|
||
|
color: Colors.white,
|
||
|
fontSize: 18.sp,
|
||
|
fontWeight: FontWeight.bold,
|
||
|
),
|
||
|
)),
|
||
|
GestureDetector(
|
||
|
behavior: HitTestBehavior.opaque,
|
||
|
onTap: () {
|
||
|
pickImage();
|
||
|
},
|
||
|
child:Container(
|
||
|
padding: EdgeInsets.symmetric(horizontal:10.w),
|
||
|
child: Text(
|
||
|
S.of(context).xiangce,
|
||
|
style: TextStyle(
|
||
|
color: Colors.black,
|
||
|
fontSize: 18.sp,
|
||
|
fontWeight: FontWeight.bold,
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
),
|
||
|
],
|
||
|
),
|
||
|
),
|
||
|
top:MediaQuery.of(context).padding.top,
|
||
|
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
|
||
|
bool get wantKeepAlive => true;
|
||
|
}
|