PieceSet.fromImageAssets constructor
PieceSet.fromImageAssets({})
Specifies a set of WidgetBuilder
s from a set of image files in a folder.
The file names should be in a format like 'wB.png' (white bishop),
'bN.png' (black knight).
A format
other than 'png' can be specified, as long as it works with
Image.asset
. SVG cannot be used with this, but look at piece_set.dart
for a commented out example of how flutter_svg can be used.
Make sure that every symbol in symbols
has a 'wSymbol' and 'bSymbol' file.
If the images are coming from a package (for example, from Squares), then
specify package
.
See PieceSet.merida()
for an example.
Implementation
factory PieceSet.fromImageAssets({
required String folder,
String? package,
required List<String> symbols,
String format = 'png',
}) {
Map<String, WidgetBuilder> pieces = {};
for (String symbol in symbols) {
pieces[symbol.toUpperCase()] =
(BuildContext context) => Image.asset('${folder}w$symbol.$format', package: package);
pieces[symbol.toLowerCase()] =
(BuildContext context) => Image.asset('${folder}b$symbol.$format', package: package);
}
return PieceSet(pieces: pieces);
}