Skip to content

Commit 30b0d69

Browse files
authored
Fix flutter version detection (#104)
1 parent 0552e15 commit 30b0d69

File tree

1 file changed

+19
-1
lines changed

1 file changed

+19
-1
lines changed

internal/flutterversion/version.go

Lines changed: 19 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package flutterversion
22

33
import (
4+
"bytes"
45
"encoding/json"
56
"os"
67
"os/exec"
@@ -25,8 +26,25 @@ func readFlutterVersion() flutterVersionResponse {
2526
log.Errorf("Failed to run %s: %v", log.Au().Magenta("flutter --version --machine"), err)
2627
os.Exit(1)
2728
}
29+
30+
// Read bytes from the stdout until we receive what looks like the start of
31+
// a valid json object. This code may be removed when the following flutter
32+
// issue is resolved. https://github.com/flutter/flutter/issues/54014
33+
outputBuffer := bytes.NewBuffer(out)
34+
for {
35+
b, err := outputBuffer.ReadByte()
36+
if err != nil {
37+
log.Errorf("Failed to run %s: did not return information in json", log.Au().Magenta("flutter --version --machine"))
38+
os.Exit(1)
39+
}
40+
if b == '{' {
41+
outputBuffer.UnreadByte()
42+
break
43+
}
44+
}
45+
2846
var response flutterVersionResponse
29-
err = json.Unmarshal(out, &response)
47+
err = json.NewDecoder(outputBuffer).Decode(&response)
3048
if err != nil {
3149
log.Errorf("Failed parsing json: %v", err)
3250
os.Exit(1)

0 commit comments

Comments
 (0)