Skip to content

Commit d04cbce

Browse files
levimichaelshortcutsmillotp
authored
guides: add dart onboarding guide (#4147)
Co-authored-by: shortcuts <[email protected]> Co-authored-by: Pierre Millot <[email protected]>
1 parent 2a142c8 commit d04cbce

File tree

4 files changed

+43
-5
lines changed

4 files changed

+43
-5
lines changed

.github/workflows/check.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ jobs:
4141
runs-on: ubuntu-22.04
4242
timeout-minutes: 10
4343
env:
44-
CACHE_VERSION: 1.11 # bump this to run all clients on the CI.
44+
CACHE_VERSION: 1.12 # bump this to run all clients on the CI.
4545
steps:
4646
- name: debugging - dump GitHub context
4747
env:

scripts/formatter.ts

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,13 @@ export async function formatter(language: string, cwd: string): Promise<void> {
1515
}
1616
break;
1717
case 'dart':
18-
if (cwd.includes('tests') || cwd.includes('snippets')) {
19-
await run('dart pub get && dart fix --apply && dart format .', {
18+
if (cwd.includes('clients')) {
19+
await run('dart pub get && melos bs && melos build --no-select && melos lint', {
2020
cwd,
2121
language,
2222
});
2323
} else {
24-
await run('dart pub get && melos bs && melos build --no-select && melos lint', {
24+
await run('dart pub get && dart fix --apply && dart format .', {
2525
cwd,
2626
language,
2727
});
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
import 'package:http/http.dart' as http;
2+
import 'dart:convert';
3+
{{> snippets/import}}
4+
5+
void main() async {
6+
// initiate client
7+
{{> snippets/init}}
8+
9+
// read json file from url
10+
final datasetRequest = await http.get(
11+
Uri.parse('https://dashboard.algolia.com/sample_datasets/movie.json'));
12+
13+
if (datasetRequest.statusCode == 200) {
14+
final moviesData = jsonDecode(datasetRequest.body);
15+
16+
final batchRequests = <BatchRequest>[];
17+
18+
for (final movie in moviesData) {
19+
batchRequests.add(
20+
BatchRequest(action: Action.fromJson('addObject'), body: movie),
21+
);
22+
}
23+
24+
try {
25+
// push data to algolia
26+
await client.batch(
27+
indexName: 'movies_index',
28+
batchWriteParams: BatchWriteParams(requests: batchRequests),
29+
);
30+
print("Successfully indexed records!");
31+
} catch (e) {
32+
print("Error: ${e.toString()}");
33+
}
34+
} else {
35+
throw Exception('Failed to load data');
36+
}
37+
}

templates/dart/snippets/pubspec.mustache

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ dependencies:
1010
algolia_client_insights: ^1.0.0
1111
algolia_client_recommend: ^1.0.0
1212
dotenv: ^4.1.0
13+
http: ^1.2.2
1314

1415
dev_dependencies:
15-
lints: ^5.0.0
16+
lints: ^5.0.0

0 commit comments

Comments
 (0)