📜 ⬆️ ⬇️

We collect Flutter application for a desktop

image

Hello!


Today I will show you how to run your existing Flutter application on the desktop (MacOS, Linux or Windows).


First, you will have to switch the Flutter channel from release to master. To do this, you need to run the following commands on the command line:


flutter channel master flutter upgrade 

Then you need to set the ENABLE_FLUTTER_DESKTOP environment variable to true .


To do this, run the following in the command line:


Mac OS and Linux


 export ENABLE_FLUTTER_DESKTOP=true 

Windows powershell


 $env:ENABLE_FLUTTER_DESKTOP="true" 

Windows CMD


 set ENABLE_FLUTTER_DESKTOP=true 

After that, you should see your desktop in the list of available devices to start Flutter. To check this, run the flutter devices command.


image


As you can see in the screenshot, I have a Mac OS in the list of available devices.


Next we need to look into the following repository:
https://github.com/google/flutter-desktop-embedding


We are interested in the contents of the example directory, namely the macos , linux and windows folders. These are the runners for the respective platforms — the native applications within which Flutter runs. Exactly the same as you can see in the directory of your project when you create a project with the help of the flutter create command.


Just copy the runner for the platform you are interested in to the project directory. This step is necessary because flutter create does not yet support the automatic creation of runners for the desktop.


Already almost done. Now you need to edit your main.dart a little


Add the following imports:


 import 'dart:io' show Platform; import 'package:flutter/foundation.dart' show debugDefaultTargetPlatformOverride; 

Change main () as follows:


 void main() { debugDefaultTargetPlatformOverride = TargetPlatform.fuchsia; [...] } 

Last step. Run the following commands:


 flutter packages get flutter precache --linux 

Done! Now just run the flutter run and your application will gather on the desktop!


Important note:


It should be borne in mind that many third-party plug-ins that you used in your Flutter applications will not work on the desktop, as they depend on the native APIs. In the future, the situation will, of course, change, but for now it is better not to use this method for something serious.


')

Source: https://habr.com/ru/post/453092/


All Articles