import 'dart:ui'; import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:image_pickers/image_pickers.dart'; import 'package:scan/scan.dart'; import '../../retrofit/business_api.dart'; import '../../retrofit/data/base_data.dart'; import '../../retrofit/data/ticket_details.dart'; import '../../utils/business_instance.dart'; import '../view_widget/settlement_tips_dialog.dart'; class ScanCodePage extends StatefulWidget { final Map arguments; ScanCodePage({this.arguments}); @override State createState() { return _ScanCodePage(); } } class _ScanCodePage extends State { ScanController controller = ScanController(); final screenWidth = window.physicalSize.width; final screenHeight = window.physicalSize.height; BusinessApiService businessService; TicketDetails ticketDetails; @override void initState() { super.initState(); } @override void dispose() { if (this.controller != null) { this.controller.pause(); } super.dispose(); } ///票券详情 queryTicketDetails(code) async { if (businessService == null) { businessService = BusinessApiService(Dio(), context: context, token: BusinessInstance.instance.businessToken, tenant: BusinessInstance.instance.businessTenant, storeId: widget.arguments["storeId"]); } BaseData baseData = await businessService.ticketCode(code).catchError((error) {}); if (baseData != null && baseData.isSuccess) { ticketDetails = baseData.data; Navigator.of(context) .popAndPushNamed('/router/order_write_off', arguments: { "ticketDetails": ticketDetails, }); } else { Navigator.of(context).pop(); SmartDialog.showToast(baseData.msg, alignment: Alignment.center); } } @override Widget build(BuildContext context) { return Scaffold( body: Stack( children: [ Positioned( child: Column( children: [ Expanded( child: ScanView( controller: controller, scanAreaScale: 0.7, scanLineColor: Colors.green.shade400, onCapture: (data) { if (data != null && data != "") { queryTicketDetails(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.end, crossAxisAlignment: CrossAxisAlignment.center, children: [ GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { Navigator.of(context).pop(); }, child: Container( padding: EdgeInsets.symmetric(horizontal: 10.w), alignment: Alignment.centerLeft, child: Image.asset( "assets/image/return_left.webp", fit: BoxFit.fill, color: Colors.white, ), ), ), Spacer(), ], ), ), top: MediaQuery.of(context).padding.top, left: 0, right: 0, ), Positioned( child: GestureDetector( behavior: HitTestBehavior.opaque, onTap: () { pickImage(); }, child: Container( decoration: BoxDecoration( color: Colors.white.withAlpha(35), borderRadius: BorderRadius.circular(100), ), padding: EdgeInsets.all(8.w), margin: EdgeInsets.only(left: 12.w, right: 16.w, top: 16.h), child:Icon( Icons.image, size: 25.w, color: Colors.white, ), ), ), right: 0, bottom: 50.h, ), ], ), ); } pickImage() async { List 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 != "") { queryTicketDetails(result); }else{ SmartDialog.show( widget: SettlementTips( () { }, text: "照片中未识别到二维码/条码", color: Color(0xFF30415B), )); } } } }