-
-
Notifications
You must be signed in to change notification settings - Fork 287
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* All barcode detections are now computed in an Isolate * Add a setStateSafe method * Only accept 1D barcodes * Between each decoding a window is passed * Let's try to reduce a little bit the quality of the camera * Improve a little bit the documentation * Fix a typo * Fix some typos * Fixes issues highlighted by MonsieurTanuki in the PR * Remove irrelevant `mount` check * Fix wrong import
- Loading branch information
Showing
7 changed files
with
590 additions
and
117 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
import 'dart:collection'; | ||
|
||
import 'package:collection/collection.dart'; | ||
|
||
/// List of [num] with a max length of [_maxCapacity], where we can easily | ||
/// compute the average value of all elements. | ||
class AverageList<T extends num> with ListMixin<T> { | ||
static const int _maxCapacity = 10; | ||
final List<T> _elements = <T>[]; | ||
|
||
int average(int defaultValueIfEmpty) { | ||
if (_elements.isEmpty) { | ||
return defaultValueIfEmpty; | ||
} else { | ||
return _elements.average.floor(); | ||
} | ||
} | ||
|
||
@override | ||
int get length => _elements.length; | ||
|
||
@override | ||
T operator [](int index) => throw UnsupportedError( | ||
'Please only use the "add" method', | ||
); | ||
|
||
@override | ||
void operator []=(int index, T value) { | ||
if (index > _maxCapacity) { | ||
throw UnsupportedError('The index is above the capacity!'); | ||
} else { | ||
_elements[index] = value; | ||
} | ||
} | ||
|
||
@override | ||
void add(T element) { | ||
// The first element is always the latest added | ||
_elements.insert(0, element); | ||
|
||
if (_elements.length >= _maxCapacity) { | ||
_elements.removeLast(); | ||
} | ||
} | ||
|
||
@override | ||
set length(int newLength) { | ||
throw UnimplementedError('This list has a fixed size of $_maxCapacity'); | ||
} | ||
} |
Oops, something went wrong.