user1209216
user1209216

Reputation: 7914

Flutter desktop - change window title from Dart code

I am unable to find any way to do that when searching official documentation. Does anybody know any way to do that?

Upvotes: 18

Views: 13203

Answers (5)

Baysagalan Dashdorj
Baysagalan Dashdorj

Reputation: 21

In order to replace flutter app title on the Windows caption bar, as well as optionally adjusting the dimensions for size and the window coordinates you have to navigate to windows/main.cpp file and edit following code: !window.Create(L"My App New Title Here", origin, size) Source: https://docs.flutter.dev/platform-integration/windows/building

Upvotes: 0

tomrozb
tomrozb

Reputation: 26251

It is possible, as mentioned in https://github.com/flutter/flutter/issues/30712

In pubspec.yaml add

dependencies:
  window_size:
    git:
      url: https://github.com/google/flutter-desktop-embedding.git
      path: plugins/window_size
      ref: fd519be1e8398c6b6c2062c2447bac960a71bc02

Now in your code just call

import 'package:window_size/window_size.dart';

WidgetsFlutterBinding.ensureInitialized();
setWindowTitle("Custom window title");

Works fine on Linux. Haven't tested on Windows/Mac

PS Thanks to @Johan Ordenes Galleguillos for the missing WidgetsFlutterBinding.ensureInitialized();

Upvotes: 23

serhii_mikh
serhii_mikh

Reputation: 31

Achieved this by using windowmanager package. It has a lot of features for desktop development with flutter.

After installing package just add this to main():

void main() async {
 //needed to ensure binding was initialized 
  WidgetsFlutterBinding.ensureInitialized();

  await WindowManager.instance.ensureInitialized();
  windowManager.waitUntilReadyToShow().then((_) async {
     await windowManager.setTitle('Yor title goes here');
  });

runApp(const MyApp());
}

for me worked with Windows and Linux.

references:

WidgetsFlutterBinding class

window manager Documentation

Upvotes: 3

Go to windows > runner > main.cpp folder, find a " !window.CreateAndShow(L"schedule_task", origin, size) " And change the "schedule_task" text

Upvotes: 6

user1209216
user1209216

Reputation: 7914

Ok, that seems to be not possible (yet), but work in progress: https://github.com/flutter/flutter/issues/30712

Upvotes: 1

Related Questions