Skip to content

Commit 51cbd06

Browse files
committed
feat(dart): use final instead of var
1 parent 03d1220 commit 51cbd06

File tree

7 files changed

+26
-26
lines changed

7 files changed

+26
-26
lines changed

templates/dart/guides/search/deleteMultipleIndices.mustache

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,15 +5,15 @@ void deleteMultipleIndices() async {
55
{{> snippets/init}}
66

77
// List all indices
8-
var indices = await {{#dynamicSnippet}}listIndicesSimple{{/dynamicSnippet}};
8+
final indices = await {{#dynamicSnippet}}listIndicesSimple{{/dynamicSnippet}};
99

1010
// Primary indices don't have a `primary` key
11-
var primaryIndices = indices.items.where((element) => element.primary == null).toList();
12-
var replicaIndices = indices.items.where((element) => element.primary != null).toList();
11+
final primaryIndices = indices.items.where((element) => element.primary == null).toList();
12+
final replicaIndices = indices.items.where((element) => element.primary != null).toList();
1313

1414
// Delete primary indices first
1515
if (primaryIndices.isNotEmpty) {
16-
List<MultipleBatchRequest> requests = primaryIndices.map((element) =>
16+
final List<MultipleBatchRequest> requests = primaryIndices.map((element) =>
1717
MultipleBatchRequest(
1818
action: Action.delete,
1919
indexName: element.name
@@ -25,7 +25,7 @@ void deleteMultipleIndices() async {
2525

2626
// Now, delete replica indices
2727
if (replicaIndices.isNotEmpty) {
28-
List<MultipleBatchRequest> requests = replicaIndices.map((element) =>
28+
final List<MultipleBatchRequest> requests = replicaIndices.map((element) =>
2929
MultipleBatchRequest(
3030
action: Action.delete,
3131
indexName: element.name

templates/dart/guides/search/saveObjectsChunks.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import 'dart:io';
44
{{> snippets/import}}
55

66
void saveObjectsChunks() async {
7-
const path = '/tmp/records.json';
7+
final path = '/tmp/records.json';
88
final json = File(path).readAsStringSync();
99
List<Map<String, dynamic>> records;
1010
try {
@@ -15,11 +15,11 @@ void saveObjectsChunks() async {
1515

1616
{{> snippets/init}}
1717

18-
const chunkSize = 10000;
18+
final chunkSize = 10000;
1919

2020
for (var i = 0; i < records.length; i += chunkSize) {
21-
var chunk = records.sublist(i, (i + chunkSize > records.length) ? records.length : i + chunkSize);
22-
var batchParams = BatchWriteParams(
21+
final chunk = records.sublist(i, (i + chunkSize > records.length) ? records.length : i + chunkSize);
22+
final batchParams = BatchWriteParams(
2323
requests: chunk.map((record) =>
2424
BatchRequest(
2525
action: Action.addObject,

templates/dart/guides/search/saveObjectsMCM.mustache

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,15 +7,15 @@ List<Map<String, String>> getAllAppIDConfigurations() {
77
List<Map> playlists = [/* Your records */];
88

99
void saveObjectsMCM() async {
10-
var configurations = getAllAppIDConfigurations();
10+
final configurations = getAllAppIDConfigurations();
1111
1212
for (var configuration in configurations) {
13-
var appId = configuration['appID'] ?? "";
14-
var apiKey = configuration['apiKey'] ?? "";
15-
var client = SearchClient(appId: appId, apiKey: apiKey);
13+
final appId = configuration['appID'] ?? "";
14+
final apiKey = configuration['apiKey'] ?? "";
15+
final client = SearchClient(appId: appId, apiKey: apiKey);
1616
1717
try {
18-
var batchParams = BatchWriteParams(
18+
final batchParams = BatchWriteParams(
1919
requests: playlists
2020
.map((record) => BatchRequest(
2121
action: Action.addObject,

templates/dart/guides/search/saveObjectsModified.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import 'dart:io';
66
void saveObjectsModified() async {
77
{{> snippets/init}}
88

9-
const path = '/tmp/records.json';
9+
final path = '/tmp/records.json';
1010
final json = File(path).readAsStringSync();
1111
List<Map<String, dynamic>> products;
1212
try {
@@ -15,7 +15,7 @@ import 'dart:io';
1515
throw Exception('Failed to read file at $path: $e');
1616
}
1717

18-
var records = products.map((product) {
18+
final records = products.map((product) {
1919
final reference = product['product_reference'].toString();
2020
final suffixes = [
2121
for (int i = 1; i <= reference.length; i++)
@@ -28,7 +28,7 @@ import 'dart:io';
2828
return updatedProduct;
2929
}).toList();
3030

31-
var batchParams = BatchWriteParams(
31+
final batchParams = BatchWriteParams(
3232
requests: records
3333
.map((record) => BatchRequest(
3434
action: Action.addObject,

templates/dart/guides/search/saveObjectsPublicUser.mustache

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
{{> snippets/import}}
22

3-
var playlists = [/* Your records */];
3+
final playlists = [/* Your records */];
44

5-
void saveObjectsPublicUser() async {
5+
void saveObjectsPublicUser() async {
66
{{> snippets/init}}
77

8-
var batchParams = BatchWriteParams(
8+
final batchParams = BatchWriteParams(
99
requests: playlists
1010
.map((record) => BatchRequest(
1111
action: Action.addObject,

templates/dart/guides/search/savePopularRecords.mustache

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -3,15 +3,15 @@
33
void savePopularRecords() async {
44
{{> snippets/init}}
55

6-
List<Map<String, dynamic>> records = [];
6+
final List<Map<String, dynamic>> records = [];
77

88
BrowseResponse? browseResponse;
99
do {
10-
var browseParams = BrowseParamsObject(hitsPerPage: 1000, cursor: browseResponse?.cursor);
10+
final browseParams = BrowseParamsObject(hitsPerPage: 1000, cursor: browseResponse?.cursor);
1111
browseResponse = await client.browse(
1212
indexName: "indexName", browseParams: browseParams
1313
);
14-
for (var hit in browseResponse.hits) {
14+
for (final hit in browseResponse.hits) {
1515
final isPopular = hit['nbFollowers'] > 1000;
1616
final updatedProduct = {
1717
...hit,
@@ -21,7 +21,7 @@ void savePopularRecords() async {
2121
}
2222
} while (browseResponse.cursor != null);
2323

24-
var batchParams = BatchWriteParams(
24+
final batchParams = BatchWriteParams(
2525
requests: records
2626
.map((record) => BatchRequest(
2727
action: Action.addObject,

templates/dart/guides/search/saveRecentlyPublishedBooks.mustache

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
void searchRecentlyPublishedBooks() async {
44
{{> snippets/init}}
55

6-
var dateTimestamp = DateTime.now().millisecondsSinceEpoch;
7-
var searchParams = SearchParamsObject(
6+
final dateTimestamp = DateTime.now().millisecondsSinceEpoch;
7+
final searchParams = SearchParamsObject(
88
query: "<YOUR_SEARCH_QUERY>",
99
filters: "date_timestamp > $dateTimestamp"
1010
);

0 commit comments

Comments
 (0)