diff --git a/example/windows/runner/main.cpp b/example/windows/runner/main.cpp index fc45db4..da24248 100644 --- a/example/windows/runner/main.cpp +++ b/example/windows/runner/main.cpp @@ -27,7 +27,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE instance, _In_opt_ HINSTANCE prev, FlutterWindow window(project); Win32Window::Point origin(10, 10); Win32Window::Size size(1280, 720); - if (!window.Create(L"rename appname", origin, size)) { + if (!window.Create(L"rename appname"), origin, size)) { return EXIT_FAILURE; } window.SetQuitOnClose(true); diff --git a/lib/platform_file_editors/windows_platform_file_editor.dart b/lib/platform_file_editors/windows_platform_file_editor.dart index 3a41b91..e2d1441 100644 --- a/lib/platform_file_editors/windows_platform_file_editor.dart +++ b/lib/platform_file_editors/windows_platform_file_editor.dart @@ -80,19 +80,22 @@ class WindowsPlatformFileEditor extends AbstractPlatformFileEditor { List? contentLineByLine = await readFileAsLineByline( filePath: filePath, ); - for (var i = 0; i < contentLineByLine.length; i++) { - if (contentLineByLine[i].contains('window.CreateAndShow')) { - contentLineByLine[i] = contentLineByLine[i] - .replaceAllMapped(RegExp(r'CreateAndShow\(L"(.*?)"'), (match) { - return 'Create(L"$appName"'; - }); - break; - } else if (contentLineByLine[i].contains('window.Create')) { - contentLineByLine[i] = contentLineByLine[i] - .replaceAllMapped(RegExp(r'Create\(L"(.*?)"'), (match) { - return 'Create(L"$appName"'; - }); - break; + var currentAppName = await getAppName(); + if (currentAppName != null) { + for (var i = 0; i < contentLineByLine.length; i++) { + if (contentLineByLine[i]?.contains('window.CreateAndShow') ?? false) { + contentLineByLine[i] = contentLineByLine[i]?.replaceFirst( + currentAppName, + appName, + ); + break; + } else if (contentLineByLine[i]?.contains('window.Create') ?? false) { + contentLineByLine[i] = contentLineByLine[i]?.replaceFirst( + currentAppName, + appName, + ); + break; + } } } final message = await super.setAppName(appName: appName); @@ -100,7 +103,7 @@ class WindowsPlatformFileEditor extends AbstractPlatformFileEditor { filePath: filePath, content: contentLineByLine.join('\n'), ); - return message; + return 'App name set to $appName'; } /// Sets the bundle ID in the Windows Runner.rc file.