Skip to content

V- Modal AI: Visual Video / Image Search - Flutter Video SDK

fix(example): load result frames via image bytes API instead of NetworkImage

pc_homee246d2d72285
diff --git a/example/01_full_app/lib/main.dart b/example/01_full_app/lib/main.dart
index e4dc405..245f1db 100644
--- a/example/01_full_app/lib/main.dart
+++ b/example/01_full_app/lib/main.dart
@@ -1,4 +1,5 @@
import 'dart:async';
+import 'dart:convert';
import 'dart:io';
import 'package:file_selector/file_selector.dart';
@@ -125,6 +126,7 @@ class ExampleSearchImage {
required this.stream,
required this.timestamp,
required this.score,
+ this.bytes,
});
final String id;
@@ -134,6 +136,7 @@ class ExampleSearchImage {
final String stream;
final String timestamp;
final String score;
+ final Uint8List? bytes;
}
List<ExampleSearchCandidate> exampleSearchCandidates(
@@ -212,9 +215,25 @@ int? _exampleInputIndex(Object? value) {
return null;
}
+Map<String, Uint8List> exampleDecodeImageBytes(ImageGetBulkResponse response) {
+ final decoded = <String, Uint8List>{};
+ for (final raw in response.records) {
+ final url = '${raw['url_pre_signed'] ?? ''}'.trim();
+ final encoded = '${raw['content_base64'] ?? ''}'.trim();
+ if (url.isEmpty || encoded.isEmpty) continue;
+ try {
+ decoded[url] = base64Decode(encoded);
+ } on FormatException {
+ continue;
+ }
+ }
+ return decoded;
+}
+
List<ExampleSearchImage> exampleSearchImages(
List<ExampleSearchCandidate> candidates,
ImageUrlBulkResponse response,
+ Map<String, Uint8List> imageMap,
) {
final resolved = <int, ExampleSearchImage>{};
for (var rowIndex = 0; rowIndex < response.records.length; rowIndex++) {
@@ -256,6 +275,7 @@ List<ExampleSearchImage> exampleSearchImages(
stream: stream,
timestamp: timestamp,
score: exampleScore(hit),
+ bytes: imageMap[url],
);
}
final indexes = resolved.keys.toList()..sort();
@@ -375,7 +395,9 @@ class ExampleSearchImageCard extends StatelessWidget {
AspectRatio(
aspectRatio: 1,
child: Image(
- image: imageProviderFactory(image.url),
+ image: image.bytes == null
+ ? imageProviderFactory(image.url)
+ : MemoryImage(image.bytes!),
fit: BoxFit.cover,
semanticLabel: 'Search result image: ${image.title}',
loadingBuilder:
@@ -721,7 +743,15 @@ class _VmodalExampleAppState extends State<VmodalExampleApp> {
.toList(),
);
if (!_currentSearch(generation, query, collection, stream)) return;
- images = exampleSearchImages(candidates, urls);
+ final urlList = urls.records
+ .where((row) => row['found'] != false)
+ .map((row) => '${row['url_pre_signed'] ?? ''}'.trim())
+ .where((String url) => url.isNotEmpty)
+ .toList();
+ final contents = await client.images.getImageBulkFromUrls(urlList);
+ if (!_currentSearch(generation, query, collection, stream)) return;
+ final imageMap = exampleDecodeImageBytes(contents);
+ images = exampleSearchImages(candidates, urls, imageMap);
}
_safeState(() {
_images = images;
diff --git a/example/01_full_app/test/widget_test.dart b/example/01_full_app/test/widget_test.dart
index f19212b..f19bf69 100644
--- a/example/01_full_app/test/widget_test.dart
+++ b/example/01_full_app/test/widget_test.dart
@@ -164,7 +164,7 @@ void main() {
expect(candidate.record, <String, Object?>{
'mode': 'vid_file',
'group_name': 'videos',
- 'modality': 'image',
+ 'modality': 'vid_img',
'stream_name': 'custom',
'filename': 'clip.mp4',
'ts_unix_13digits': '1700000000000',
@@ -181,6 +181,7 @@ void main() {
},
],
}),
+ const <String, Uint8List>{},
).single;
expect(image.title, 'Red bicycle');
expect(image.filename, 'clip.mp4');
@@ -190,7 +191,7 @@ void main() {
expect(image.id, isNot(contains(image.url)));
});
- test('all filename aliases use basename and blank hits are omitted', () {
+ test('filename aliases use basename and blank names fall back to title', () {
_log('checking every documented filename alias and both path separators');
const keys = <String>[
'filename',
@@ -217,7 +218,9 @@ void main() {
<String, Object?>{'title': 'No file'},
],
});
- expect(exampleSearchCandidates(blank, 'group', 'stream'), isEmpty);
+ final candidates = exampleSearchCandidates(blank, 'group', 'stream');
+ expect(candidates, hasLength(1));
+ expect(candidates.single.record, containsPair('filename', 'No file'));
});
test('timestamps normalize to the 13-digit lookup contract', () {
@@ -282,6 +285,7 @@ void main() {
<String, Object?>{'input_index': 3, 'url_pre_signed': ' '},
],
}),
+ const <String, Uint8List>{},
);
expect(images.map((ExampleSearchImage image) => image.title), <String>[
'Title 0',
@@ -312,6 +316,7 @@ void main() {
<String, Object?>{'url_pre_signed': 'https://image.test/outside'},
],
}),
+ const <String, Uint8List>{},
);
expect(images.map((ExampleSearchImage image) => image.filename), <String>[
'zero.mp4',