From ec08a47de112839a675bcfbcc9d5f0cfafd52aa5 Mon Sep 17 00:00:00 2001 From: Rich Young Date: Wed, 4 Feb 2026 04:41:20 -0500 Subject: [PATCH] feat(flutter_tools): add linux-gtk template selector --- packages/flutter_tools/lib/src/commands/create.dart | 7 +++++++ .../flutter_tools/lib/src/commands/create_base.dart | 2 ++ packages/flutter_tools/lib/src/template.dart | 12 ++++++++++++ 3 files changed, 21 insertions(+) diff --git a/packages/flutter_tools/lib/src/commands/create.dart b/packages/flutter_tools/lib/src/commands/create.dart index b18a4c6e6b5..385ac07213d 100644 --- a/packages/flutter_tools/lib/src/commands/create.dart +++ b/packages/flutter_tools/lib/src/commands/create.dart @@ -83,6 +83,12 @@ class CreateCommand extends FlutterCommand with CreateBase { help: 'The language to use for Android-specific code, either Kotlin (recommended) or Java (legacy).', ); + argParser.addOption( + 'linux-gtk', + defaultsTo: 'gtk4', + allowed: ['gtk4', 'gtk3'], + help: 'Select the GTK version for Linux templates (gtk4 default, gtk3 opt-in).', + ); argParser.addFlag( 'skip-name-checks', help: @@ -459,6 +465,7 @@ class CreateCommand extends FlutterCommand with CreateBase { darwin: includeDarwin, web: includeWeb, linux: includeLinux, + linuxGtkVersion: stringArg('linux-gtk') ?? 'gtk4', macos: includeMacos, windows: includeWindows, dartSdkVersionBounds: '^$dartSdk', diff --git a/packages/flutter_tools/lib/src/commands/create_base.dart b/packages/flutter_tools/lib/src/commands/create_base.dart index 2f10376c82e..271674d5035 100644 --- a/packages/flutter_tools/lib/src/commands/create_base.dart +++ b/packages/flutter_tools/lib/src/commands/create_base.dart @@ -319,6 +319,7 @@ mixin CreateBase on FlutterCommand { bool android = false, bool web = false, bool linux = false, + String linuxGtkVersion = 'gtk4', bool macos = false, bool windows = false, bool darwin = false, @@ -375,6 +376,7 @@ mixin CreateBase on FlutterCommand { 'android': android, 'web': web, 'linux': linux, + 'linuxGtkVersion': linuxGtkVersion, 'macos': macos, 'darwin': darwin, 'sharedDarwinSource': darwin, diff --git a/packages/flutter_tools/lib/src/template.dart b/packages/flutter_tools/lib/src/template.dart index 9f83b0b7299..df47c7e9864 100644 --- a/packages/flutter_tools/lib/src/template.dart +++ b/packages/flutter_tools/lib/src/template.dart @@ -258,6 +258,18 @@ class Template { } // Only build a Linux project if explicitly asked. final bool linux = (context['linux'] as bool?) ?? false; + final String linuxGtkVersion = (context['linuxGtkVersion'] as String?) ?? 'gtk4'; + final bool linuxGtk3Template = relativeDestinationPath.startsWith('linux-gtk3.tmpl'); + final bool linuxGtk4Template = relativeDestinationPath.startsWith('linux-gtk4.tmpl'); + if ((linuxGtk3Template || linuxGtk4Template) && !linux) { + return null; + } + if (linuxGtk3Template && linuxGtkVersion != 'gtk3') { + return null; + } + if (linuxGtk4Template && linuxGtkVersion != 'gtk4') { + return null; + } if (relativeDestinationPath.startsWith('linux.tmpl') && !linux) { return null; }