MCPcopy Create free account
hub / github.com/Dart-Code/Dart-Code / getFlutterSnippets

Function getFlutterSnippets

src/extension/sdk/flutter_docs_snippets.ts:10–30  ·  view source on GitHub ↗
(logger: Logger, sdks: Sdks)

Source from the content-addressed store, hash-verified

8import { runToolProcess } from "../utils/processes";
9
10export async function getFlutterSnippets(logger: Logger, sdks: Sdks): Promise<FlutterSampleSnippet[]> {
11 if (!sdks.flutter)
12 throw new Error("Flutter SDK not available");
13
14 const binPath = path.join(sdks.flutter, flutterPath);
15
16 const fileName = `flutter-samples-${getRandomInt(0x1000, 0x10000).toString(16)}.txt`;
17 const tempPath = path.join(os.tmpdir(), fileName);
18
19 try {
20 const res = await runToolProcess(logger, undefined, binPath, ["create", "--list-samples", tempPath]);
21 if (res.exitCode !== 0)
22 throw new Error(`Failed to get Flutter samples from SDK (${res.exitCode})\n\n${res.stderr}\n\n${res.stdout}`);
23
24 const json = fs.readFileSync(tempPath, { encoding: "utf8" });
25
26 return JSON.parse(json) as FlutterSampleSnippet[];
27 } finally {
28 tryDeleteFile(tempPath);
29 }
30}

Callers 1

Calls 4

getRandomIntFunction · 0.90
runToolProcessFunction · 0.90
tryDeleteFileFunction · 0.90
toStringMethod · 0.45

Tested by

no test coverage detected