• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

inventree / inventree-app / 10299786653

08 Aug 2024 09:44AM UTC coverage: 9.204% (+0.01%) from 9.192%
10299786653

push

github

web-flow
Change from fontawesome to tabler icons (#516)

* Change from fontawesome to tabler icons

- Consistent with the frontend

* Cleanup conflicts

* Use double quotes

* remove unused import

* Update release notes

* Migrate some google icons to tabler icons

* Icon update

* Properly support display of custom icons

* Fix lookup

1 of 254 new or added lines in 43 files covered. (0.39%)

4 existing lines in 4 files now uncovered.

754 of 8192 relevant lines covered (9.2%)

0.31 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/lib/barcode/camera_controller.dart
1
import "dart:io";
2
import "package:flutter/material.dart";
3
import "package:flutter_tabler_icons/flutter_tabler_icons.dart";
4
import "package:inventree/app_colors.dart";
5
import "package:inventree/preferences.dart";
6

7
import "package:qr_code_scanner/qr_code_scanner.dart";
8

9
import "package:inventree/l10.dart";
10

11
import "package:inventree/barcode/handler.dart";
12
import "package:inventree/barcode/controller.dart";
13

14
/*
15
 * Barcode controller which uses the device's camera to scan barcodes.
16
 * Under the hood it uses the qr_code_scanner package.
17
 */
18
class CameraBarcodeController extends InvenTreeBarcodeController {
19
  const CameraBarcodeController(BarcodeHandler handler, {Key? key})
×
20
      : super(handler, key: key);
×
21

22
  @override
×
23
  State<StatefulWidget> createState() => _CameraBarcodeControllerState();
×
24
}
25

26
class _CameraBarcodeControllerState extends InvenTreeBarcodeControllerState {
27
  _CameraBarcodeControllerState() : super();
×
28

29
  QRViewController? _controller;
30

31
  bool flash_status = false;
32

33
  bool single_scanning = false;
34
  bool scanning_paused = false;
35

36
  Future<void> _loadSettings() async {
×
37
    bool _single = await InvenTreeSettingsManager()
×
38
        .getBool(INV_BARCODE_SCAN_SINGLE, false);
×
39

40
    if (mounted) {
×
41
      setState(() {
×
42
        single_scanning = _single;
×
43
        scanning_paused = false;
×
44
      });
45
    }
46
  }
47

48
  /* Callback function when the Barcode scanner view is initially created */
49
  void _onViewCreated(BuildContext context, QRViewController controller) {
×
50
    _controller = controller;
×
51

52
    controller.scannedDataStream.listen((barcode) {
×
53
      if (!scanning_paused) {
×
54
        handleBarcodeData(barcode.code).then((value) => {
×
55
              // If in single-scanning mode, pause after successful scan
56
              if (single_scanning && mounted)
×
57
                {
×
58
                  setState(() {
×
59
                    scanning_paused = true;
×
60
                  })
61
                }
62
            });
63
      }
64
    });
65

66
    _loadSettings();
×
67
  }
68

69
  // In order to get hot reload to work we need to pause the camera if the platform
70
  // is android, or resume the camera if the platform is iOS.
71
  @override
×
72
  void reassemble() {
73
    super.reassemble();
×
74

75
    if (mounted) {
×
76
      if (Platform.isAndroid) {
×
77
        _controller!.pauseCamera();
×
78
      }
79

80
      _controller!.resumeCamera();
×
81
    }
82
  }
83

84
  @override
×
85
  void dispose() {
86
    _controller?.dispose();
×
87
    super.dispose();
×
88
  }
89

90
  @override
×
91
  Future<void> pauseScan() async {
92
    try {
93
      await _controller?.pauseCamera();
×
94
    } on CameraException {
×
95
      // do nothing
96
    }
97
  }
98

99
  @override
×
100
  Future<void> resumeScan() async {
101
    // Do not attempt to resume if the widget is not mounted
102
    if (!mounted) {
×
103
      return;
104
    }
105

106
    try {
107
      await _controller?.resumeCamera();
×
108
    } on CameraException {
×
109
      // do nothing
110
    }
111
  }
112

113
  // Toggle the status of the camera flash
114
  Future<void> updateFlashStatus() async {
×
115
    final bool? status = await _controller?.getFlashStatus();
×
116

117
    if (mounted) {
×
118
      setState(() {
×
119
        flash_status = status != null && status;
×
120
      });
121
    }
122
  }
123

124
  @override
×
125
  Widget build(BuildContext context) {
126
    Widget actionIcon =
NEW
127
        Icon(TablerIcons.player_pause, color: COLOR_WARNING, size: 64);
×
128

129
    if (scanning_paused) {
×
130
      actionIcon =
NEW
131
          Icon(TablerIcons.player_play, color: COLOR_ACTION, size: 64);
×
132
    }
133

134
    String info_text = scanning_paused ? L10().barcodeScanPaused : L10().barcodeScanPause;
×
135

136
    return Scaffold(
×
137
        appBar: AppBar(
×
138
          title: Text(L10().scanBarcode),
×
139
          actions: [
×
140
            IconButton(
×
141
                icon: Icon(Icons.flip_camera_android),
×
142
                onPressed: () {
×
143
                  _controller?.flipCamera();
×
144
                }),
145
            IconButton(
×
146
              icon: flash_status ? Icon(Icons.flash_off) : Icon(Icons.flash_on),
×
147
              onPressed: () {
×
148
                _controller?.toggleFlash();
×
149
                updateFlashStatus();
×
150
              },
151
            )
152
          ],
153
        ),
154
        body: GestureDetector(
×
155
            onTapDown: (details) async {
×
156
              setState(() {
×
157
                scanning_paused = !scanning_paused;
×
158
              });
159
            },
160
            onLongPressEnd: (details) async {
×
161
              if (mounted) {
×
162
                setState(() {
×
163
                  scanning_paused = false;
×
164
                });
165
              }
166
            },
167
            child: Stack(
×
168
              children: <Widget>[
×
169
                Column(children: [
×
170
                  Expanded(
×
171
                      child: QRView(
×
172
                    key: barcodeControllerKey,
×
173
                    onQRViewCreated: (QRViewController controller) {
×
174
                      _onViewCreated(context, controller);
×
175
                    },
176
                    overlay: QrScannerOverlayShape(
×
177
                      borderColor:
178
                          scanning_paused ? COLOR_WARNING : COLOR_ACTION,
×
179
                      borderRadius: 10,
180
                      borderLength: 30,
181
                      borderWidth: 10,
182
                      cutOutSize: 300,
183
                    ),
184
                  ))
185
                ]),
186
                Center(
×
187
                    child: Column(children: [
×
188
                  Padding(
×
189
                      child: Text(
×
190
                        widget.handler.getOverlayText(context),
×
191
                        style: TextStyle(
×
192
                          fontSize: 16,
193
                            fontWeight: FontWeight.bold, color: Colors.white),
194
                      ),
195
                      padding: EdgeInsets.all(25)),
×
196
                  Padding(
×
197
                    child: CircularProgressIndicator(
×
198
                        value: scanning_paused ? 0 : null),
×
199
                    padding: EdgeInsets.all(40),
×
200
                  ),
201
                  Spacer(),
×
202
                  SizedBox(
×
203
                    child: Center(
×
204
                      child: actionIcon,
205
                    ),
206
                    width: 100,
207
                    height: 150,
208
                  ),
209
                  Padding(
×
210
                    child: Text(info_text,
×
211
                        textAlign: TextAlign.center,
212
                        style: TextStyle(
×
213
                          color: Colors.white,
214
                        )),
215
                    padding: EdgeInsets.all(25),
×
216
                  ),
217
                ]))
218
              ],
219
            )));
220
  }
221
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc