main.dart 2.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. import 'package:flutter/material.dart';
  2. import 'dart:async';
  3. import 'package:flutter/services.dart';
  4. import 'package:fqreader/fqreader.dart';
  5. import 'package:flustars/flustars.dart';
  6. import 'package:cool_ui/cool_ui.dart';
  7. void main() => runApp(new MyApp());
  8. class MyApp extends StatefulWidget {
  9. @override
  10. _MyAppState createState() => new _MyAppState();
  11. }
  12. class _MyAppState extends State<MyApp> {
  13. @override
  14. void initState() {
  15. super.initState();
  16. }
  17. @override
  18. Widget build(BuildContext context) {
  19. return new MaterialApp(
  20. home: Builder(builder: (context){
  21. ScreenUtil.getInstance().init(context);
  22. double bodyHeight = (ScreenUtil.screenHeight - ScreenUtil.appBarHeight);
  23. Rect viewRect = Rect.fromLTRB(0, 60, ScreenUtil.screenWidth, ScreenUtil.screenHeight);
  24. Rect scanRect= Rect.fromLTWH(
  25. ScreenUtil.screenWidth * 0.1,
  26. (bodyHeight - ScreenUtil.screenWidth * 0.8) / 2,
  27. ScreenUtil.screenWidth * 0.8,
  28. ScreenUtil.screenWidth * 0.8);
  29. return new Scaffold(
  30. appBar: new AppBar(
  31. title: const Text('Plugin example app'),
  32. ),
  33. body: Stack(
  34. children: <Widget>[
  35. ScanView(onScan: (value){
  36. showWeuiSuccessToast(
  37. context: context,
  38. message:Text("扫描成功:" + value)
  39. );
  40. },viewRect: viewRect,scanRect:scanRect),
  41. Positioned(
  42. top: 0.0,
  43. left: 0.0,
  44. child:FlatButton(child: Text("启动扫描"),color: Colors.red,onPressed: ()=>Fqreader.startScan(),),
  45. ),
  46. Positioned(
  47. top: 0.0,
  48. left: 80.0,
  49. child:FlatButton(child: Text("暂停扫描"),color: Colors.red,onPressed: ()=>Fqreader.stopScan(),),
  50. ),
  51. Positioned(
  52. top: scanRect.top,
  53. left: scanRect.left,
  54. child: Container(
  55. width: scanRect.width,
  56. height: scanRect.height,
  57. decoration: BoxDecoration(
  58. border: Border.all()
  59. ),
  60. ),
  61. )
  62. ],
  63. ),
  64. );
  65. }),
  66. );
  67. }
  68. }