encode method
Returns a square matrix of modules.
Implementation
List<List<bool>> encode(String data) {
final Uint8List bytes = Uint8List.fromList(data.codeUnits);
final int version = _pickVersion(bytes.length);
final _RsParams params = _rsParams(version);
final List<int> codewords = _buildData(bytes, version, params);
final List<int> full = _addEcc(codewords, params);
final int size = _moduleCount(version);
final List<List<int>> grid = List<List<int>>.generate(
size,
(_) => List<int>.filled(size, -1),
);
final List<List<bool>> locked = List<List<bool>>.generate(
size,
(_) => List<bool>.filled(size, false),
);
_drawFunctionPatterns(grid, locked, version);
_drawCodewords(grid, locked, full);
final int mask = _bestMask(grid, locked, version);
_applyMask(grid, locked, mask);
_drawFormat(grid, locked, mask);
if (version >= 7) {
_drawVersion(grid, locked, version);
}
return <List<bool>>[
for (final List<int> row in grid)
<bool>[for (final int cell in row) cell == 1],
];
}