Repository: flutter
Issue: flutter create command does not populate iOS Team Identifier
Labels: platform-ios,tool,P2,has partial patch,team-ios,triaged-ios

### Steps to reproduce

1. on a Mac
2. on command line, create a new project `flutter create testproject`
3. open project in vscode
4. select physical iOS device for debugging
5. run project


### Expected results

Project should build, sign, deploy, and run on an iOS device

### Actual results

Build output
```
Launching lib/main.dart on Gadget Boys iPhone in debug mode...
Developer identity "REDACTED" selected for iOS code signing!
Xcode build done.                                            0.9s
Failed to build iOS app
Could not build the precompiled application for the device.
Error (Xcode): Signing for "Runner" requires a development team. Select a development team in the Signing & Capabilities editor.
/Users/adam/Projects/testlist/ios/Runner.xcodeproj
```

### Code sample


I have tracked down the exact cause of the issue.

The flutter iOS Runner swift project template looks like this...

```
{{#hasIosDevelopmentTeam}}
				DEVELOPMENT_TEAM = {{iosDevelopmentTeam}};
{{/hasIosDevelopmentTeam}}
```

Which appears to show that the "development team" _should be_ getting populated with a valid value.

Tracking the code in flutter tools, I can see the `iosDevelopmentTeam` template token is populated by this code

https://github.com/flutter/flutter/blob/a0ba2decab156c88708c4261d40660ab8f60da5f/packages/flutter_tools/lib/src/ios/code_signing.dart#L155

There is plenty of logging to debug what is going on at runtime, so I ran the template generator with verbose logging...
`flutter create --verbose`, outputs the following
```
[   +5 ms] executing: security find-identity -p codesigning -v
[  +90 ms]   1) REDACTED "Apple Distribution: REDACTED"
             2) REDACTED "Apple Development: REDACTED"
             3) REDACTED "Apple Development: REDACTED"
                3 valid identities found
[   +1 ms] Developer identity "REDACTED" selected for iOS code signing
[  +13 ms] -----BEGIN CERTIFICATE-----
           REDACTED
           -----END CERTIFICATE-----
[        ] executing: openssl x509 -subject
[  +52 ms] Creating project testlist...
```

So, the template generator has indeed detected my signing certificate and team... why isn't it getting populated?
The only code straight after this logging, is a call to openssl to decode the signing certificate... then a regex to parse its output... but that bit doesnt have any logging unfortunately.

```
final Process opensslProcess = await processUtils.start(
    const <String>['openssl', 'x509', '-subject']);

  await ProcessUtils.writeToStdinGuarded(
    stdin: opensslProcess.stdin,
    content: signingCertificateStdout,
    onError: (Object? error, _) {
      throw Exception('Unexpected error when writing to openssl: $error');
    },
  );
  await opensslProcess.stdin.close();

  final String opensslOutput = await utf8.decodeStream(opensslProcess.stdout);
  // Fire and forget discard of the stderr stream so we don't hold onto resources.
  // Don't care about the result.
  unawaited(opensslProcess.stderr.drain<String?>());

  if (await opensslProcess.exitCode != 0) {
    return null;
  }

  return _certificateOrganizationalUnitExtractionPattern.firstMatch(opensslOutput)?.group(1);
```

So, I run the same openssl command, using the public key output that the flutter templator logged, and I get 
```
adam@Mac ~ % openssl  x509 -subject < test.txt 
subject=UID = REDACTED, CN = REDACTED, OU = 73FD8HDG96, O = REDACTED, C = REDACTED
-----BEGIN CERTIFICATE-----
REDACTED
-----END CERTIFICATE-----
```

ok, let's take a look a the regex to see if it matched my certificate subject...
```
final RegExp _certificateOrganizationalUnitExtractionPattern = RegExp(r'OU=([a-zA-Z0-9]+)');
```

Aha! The regex isn't expecting spaces around the tokens in the subject key/value pairs.
I edited my copy of `code_signing.dart` to make the regex resilient to spaces...
```
final RegExp _certificateOrganizationalUnitExtractionPattern = RegExp(r'OU[\s]*=[\s]*([a-zA-Z0-9]+)');
```

...re run the template builder
```
> flutter create testproject
```

Check the ios project output
```
		97C147061CF9000F007C117D /* Debug */ = {
			isa = XCBuildConfiguration;
			baseConfigurationReference = 9740EEB21CF90195004384FC /* Debug.xcconfig */;
			buildSettings = {
				ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
				CLANG_ENABLE_MODULES = YES;
				CURRENT_PROJECT_VERSION = "$(FLUTTER_BUILD_NUMBER)";
				DEVELOPMENT_TEAM = REDACTED;
				ENABLE_BITCODE = NO;
				INFOPLIST_FILE = Runner/Info.plist;
```

Yay!!! My dev team has been populated

Hit F5... and it signs and runs on my device!

### Screenshots or Video

<details open>
<summary>Screenshots / Video demonstration</summary>

[Upload media here]

</details>


### Logs

<details open><summary>Logs</summary>

```console
[Paste your logs here]
```

</details>


### Flutter Doctor output

<details open><summary>Doctor output</summary>

```console
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 3.24.5, on macOS 15.1.1 24B2091 darwin-arm64, locale en-NZ)
[✓] Android toolchain - develop for Android devices (Android SDK version 32.0.0)
[✓] Xcode - develop for iOS and macOS (Xcode 16.1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 2023.2)
[✓] VS Code (version 1.95.3)
[✓] Connected device (4 available)
    ! Error: Browsing on the local area network for Adam’s Apple Watch. Ensure the device is unlocked and discoverable via Bluetooth. (code -27)
[✓] Network resources

• No issues found!
```

</details>