Skip to content

Commit

Permalink
Fix Errors in PowerShell Code in Flutter Setup Guide for China (#11329)
Browse files Browse the repository at this point in the history
### Page Source Code Location
`src/_includes/docs/community/china/os-settings.md`
https://docs.flutter.dev/community/china

### Problem Description
The code in the documentation is attempting to set environment variables
for Flutter but contains errors that lead to unexpected behavior.

#### Incorrect Code
```powershell
newPath = $pwd.PATH + "/flutter/bin",$env:PATH -join ";"
[System.Environment]::SetEnvironmentVariable('Path',$newPath,User)
[System.Environment]::SetEnvironmentVariable('PUB_HOSTED_URL','https://pub.flutter-io.cn',User)
[System.Environment]::SetEnvironmentVariable('FLUTTER_STORAGE_BASE_URL','https://storage.flutter-io.cn',User)
```

#### Issues Identified:
1. **Incorrect Path Concatenation**: The variable `newPath` concatenates
using a comma, which results in incorrect setting of the PATH
environment variable.
   - **Expected `newPath` (example)**:  
     `C:\Users\User\flutter\bin;C:\Windows`
   - **Actual Value of `newPath`**:  
     `C:\Users\User/flutter/bin C:\Windows`

2. **Missing Quotes for 'User'**: The `User` parameter in
`SetEnvironmentVariable` method calls is not enclosed in quotes, leading
to runtime exceptions.

```plaintext
+ [System.Environment]::SetEnvironmentVariable('Path',$newPath,User)
+                                                              ~
Missing expression after ','.
At line:1 char:62
+ [System.Environment]::SetEnvironmentVariable('Path',$newPath,User)
+                                                              ~~~~
Unexpected token 'User' in expression or statement.
At line:1 char:66
+ [System.Environment]::SetEnvironmentVariable('Path',$newPath,User)
+                                                                  ~
Unexpected token ')' in expression or statement.
    + CategoryInfo          : ParserError: (:) [], ParentContainsErrorRecordException
    + FullyQualifiedErrorId : MissingExpressionAfterToken
```

Co-authored-by: Brett Morgan <[email protected]>
  • Loading branch information
undef-i and domesticmouse authored Oct 31, 2024
1 parent 6fbd62f commit b980954
Showing 1 changed file with 4 additions and 4 deletions.
8 changes: 4 additions & 4 deletions src/_includes/docs/community/china/os-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@
{% capture newdir -%}{{prompt}} New-Item -Path '{{installdirsuggestion}}' -ItemType Directory{% endcapture -%}
{% capture unzip -%} {{prompt}} Expand-Archive .\{% endcapture -%}
{% capture permaddexample -%}
$newPath = $pwd.PATH + "/flutter/bin",$env:PATH -join ";"
[System.Environment]::SetEnvironmentVariable('Path',$newPath,User)
[System.Environment]::SetEnvironmentVariable('PUB_HOSTED_URL','https://pub.flutter-io.cn',User)
[System.Environment]::SetEnvironmentVariable('FLUTTER_STORAGE_BASE_URL','https://storage.flutter-io.cn',User)
$newPath = "$pwd\flutter\bin;$env:PATH"
[System.Environment]::SetEnvironmentVariable('Path', $newPath, 'User')
[System.Environment]::SetEnvironmentVariable('PUB_HOSTED_URL', 'https://pub.flutter-io.cn', 'User')
[System.Environment]::SetEnvironmentVariable('FLUTTER_STORAGE_BASE_URL', 'https://storage.flutter-io.cn', 'User')
{% endcapture -%}
{% else -%}
{% assign shell = 'your terminal' -%}
Expand Down

0 comments on commit b980954

Please sign in to comment.