searchSticker method

Future<List<Sticker>> searchSticker({
  1. required String searchQuery,
  2. required BuildContext context,
})

Search stickers

Implementation

Future<List<Sticker>> searchSticker({
  required String searchQuery,
  required BuildContext context,
}) async {
  //Get all Sticker assets

  // Load as String
  final manifestContent =
      await DefaultAssetBundle.of(context).loadString('AssetManifest.json');
  // Decode to Map
  final Map<String, dynamic> manifestMap = json.decode(manifestContent);

// Filter by path
  List<Sticker> allStickers = manifestMap.keys
      .where((path) => path.startsWith('assets/stickers/'))
      .where(
        (path) =>
            (path.toLowerCase()).endsWith(".webp") ||
            (path.toLowerCase()).endsWith(".png") ||
            (path.toLowerCase()).endsWith(".jpg") ||
            (path.toLowerCase()).endsWith(".gif") ||
            (path.toLowerCase()).endsWith(".jpeg"),
      )
      .where((element) => element.split('/').last.contains(searchQuery))
      .toList()
      .map((assetUrl) =>
          Sticker(assetUrl: assetUrl, category: assetUrl.split('/')[2]))
      .toList();

  return allStickers;
}