Create your first flutter desktop application – Flutter tutorial – Genuine Coder

Create your first flutter desktop application – Flutter tutorial

Flutter for desktop tutorial

Flutter is the new developer-friendly cross-platform open-source framework developed by Google. The flutter community is growing and as of 2022, with flutter 3, it is stable for Android, iOS, Web and Desktop platforms! Flutter 3 added stable support for Linux desktop and macOS platform.

In this tutorial for beginners, we will learn how to create a simple flutter application and build it as a native desktop application for Linux.

Setting up the flutter development environment

Based on your platform, the steps for installing the flutter and configuring is a bit different. In this tutorial, we will cover the setting up of flutter SDK for Linux Ubuntu platform.

Install and configure flutter for Ubuntu/Mint

  • Step 1: Install the flutter SDK using snap
          sudo snap install flutter --classic
        
  • Step 2: Install additional dependencies for flutter-sdk’s development
          sudo apt-get install clang cmake ninja-build pkg-config libgtk-3-dev liblzma-dev
        
  • Step 3 [OPTIONAL]: Link Android Studio to the flutter by providing Android Studio installed path
          flutter config --android-studio-dir /your/path/to/android-studio/
        
  • Step 4 [OPTIONAL]: Link Android SDK to the flutter by providing Android SDK installed path
          flutter config --android-sdk /usr/local/bin/Programs/android-sdk/
        
  • Step 5 [OPTIONAL]: Accept Android SDK licenses by running the following command
          flutter doctor --android-licenses
        
  • Step 6: Run the flutter doctor command again. Now all dependencies should be ticked!
          flutter doctor --android-licenses
        

Enable flutter desktop development support

First things first, let’s confirm that flutter SDK desktop support is enabled. To do this, run the command “flutter devices” and make sure that your desktop platform is indeed listed as shown in the below screenshot. Note that, based on your platform, it could be Linux (desktop), Windows (desktop) or macOS (desktop).

#Command format
flutter config --enable-<platform>-desktop
#Enable Linux desktop support for flutter
flutter config --enable-windows-desktop
#Enable Windows desktop support for flutter
flutter config --enable-linux-desktop
#Enable macOS desktop support for flutter
flutter config --enable-macOS-desktop

Create a new flutter desktop project

Now, let’s create our flutter project. Flutter project can be created with “flutter create” command. Let’s create a new flutter project named “genuine_flutter_app” with the following command. You can use your project’s name.

flutter create genuine_flutter_app

Now, you will see the following output mentioning that the flutter app is indeed created.

Creating project genuine_flutter_app...
Running "flutter pub get" in genuine_flutter_app...              1,968ms
Wrote 127 files.

All done!
To run your application, type:

  $ cd genuine_flutter_app
  $ flutter run

Your application code is in genuine_flutter_app/lib/main.dart.

The flutter SDK has just created a new folder with default project template and added all the required files for us. We can run the project right away and see if all is good so far.

Run the flutter app on desktop

Since the “flutter create” command created the project with template code, we can run it and test it right away. So, let’s run the project with flutter run command. Since I am using Linux, I will be using “-d linux”. If you are using Windows or Mac, make sure to use your platform’s name there.

#cd into the project directory
cd genuine_flutter_app
#Run the project
flutter run -d linux

and…here we go! You will now see the application window opened. This is the default template project.

Flutter Linux Desktop Application Running

Customize the default project

Let’s customize the default project and see how we can program in dart. To achieve this, let’s open the project on our IDE. I am using VSCode. You can choose your own editor.

Open the file lib/main.dart. This is the source file that is generating the sample demo project. Let’s then customize the project.

Flutter main.dart file inside lib directory

Q1. How to set title of the flutter AppBar?

Currently, the AppBar title is ‘Flutter Demo Home Page’ that is passed on to the MyHomePage widget. So, let’s change it into ‘My First Flutter Desktop App!’ by changing it in the MyApp widget.

Q2. How to change the AppBar color?

The AppBar color can be changed from the theme attribute. Set the primarySwatch as your preferred color and that will update the AppBar color.

class MyApp extends StatelessWidget {
  const MyApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      title: 'Flutter Demo',

      //Set the app color there
      theme: ThemeData(
        primarySwatch: Colors.blue,
      ),
      
      // Set the title here
      home: const MyHomePage(title: 'My First Flutter Desktop App!'),
    );
  }

Q3. How to change the app body color?

To set the background color for the body section, you need to set the background for the scaffold.

....
@override
Widget build(BuildContext context) {
  return Scaffold(
    //This is where the AppBar title is set
    appBar: AppBar(
      title: Text(widget.title),
    ),
    //Set your preferred background color
    backgroundColor: Colors.grey,
....

Build and release executable file from flutter project

Now that we have a working flutter application, let’s see how we can build an executable file for our project. Thanks to flutter, this is also an easy step. You can execute the “flutter build” command to start the building. If you are using Windows or Mac, make sure to use your platform instead of Linux.

#Generates Linux runnable image (application/x-executable)
flutter build linux
#Generates Windows runnable .exe file
flutter build windows
#Generates macOS runnable .app file
flutter build macos

This will build an executable file for the project. The executable can then be found at the following path. [your_platform] can be Linux, windows and macOS.

build/[your_platform]/x64/release/bundle
Flutter project released as Linux desktop executable

Conclusion

In this tutorial, we have learned how to create a Flutter desktop application and build a release executable file from the project. We will be posting more flutter related tutorials in the future. If you liked this tutorial, you might also be interested in checking out the following articles.

Comments

51 responses to “Create your first flutter desktop application – Flutter tutorial”

  1. iweb blog comments widget

    drtqfrcvd zbkmz rmksocg qxft dfitxdszapintpt

  2. … [Trackback]

    […] Read More Info here to that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  3. … [Trackback]

    […] There you can find 44779 additional Info on that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  4. … [Trackback]

    […] Find More on that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  5. … [Trackback]

    […] Read More here to that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  6. … [Trackback]

    […] Find More on that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  7. … [Trackback]

    […] Here you will find 8246 additional Info to that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  8. … [Trackback]

    […] Info to that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  9. … [Trackback]

    […] Find More Information here on that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  10. … [Trackback]

    […] Read More on on that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  11. … [Trackback]

    […] Read More Information here to that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  12. … [Trackback]

    […] Read More here to that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  13. … [Trackback]

    […] Information on that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  14. … [Trackback]

    […] Read More Information here to that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  15. … [Trackback]

    […] Read More Info here on that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  16. … [Trackback]

    […] Read More on that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  17. … [Trackback]

    […] Read More here on that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  18. … [Trackback]

    […] Information on that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  19. … [Trackback]

    […] Find More on to that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  20. … [Trackback]

    […] Read More here on that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  21. … [Trackback]

    […] There you will find 37602 additional Info on that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  22. … [Trackback]

    […] Read More to that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  23. … [Trackback]

    […] Info on that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  24. … [Trackback]

    […] Find More on that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  25. … [Trackback]

    […] Read More Information here on that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  26. … [Trackback]

    […] Find More here on that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  27. … [Trackback]

    […] Here you will find 84454 additional Information on that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  28. … [Trackback]

    […] Read More here to that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  29. … [Trackback]

    […] Here you will find 58880 additional Info on that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  30. … [Trackback]

    […] Find More Information here on that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  31. … [Trackback]

    […] Read More to that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  32. … [Trackback]

    […] Find More here on that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  33. … [Trackback]

    […] Find More Info here on that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  34. … [Trackback]

    […] There you will find 26278 more Information to that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  35. … [Trackback]

    […] Info to that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  36. … [Trackback]

    […] Read More here to that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  37. … [Trackback]

    […] Read More on on that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  38. … [Trackback]

    […] Read More to that Topic: genuinecoder.com/create-flutter-desktop-application-tutorial/ […]

  39. sans ordonnance kamagra france acheter

    medicament kamagra pharmacie gratuit comprime acheter en ligne

  40. ordering enclomiphene where to purchase

    generic enclomiphene from canada

  41. how to buy androxal buy safely online

    buy androxal generic no prescription

  42. buying flexeril cyclobenzaprine generic tablets

    order flexeril cyclobenzaprine buy mastercard

  43. how to buy dutasteride canada internet

    discount dutasteride canada internet

  44. purchase gabapentin generic in us

    discount gabapentin cheap australia

  45. cheap fildena generic fildena

    buying fildena cost per tablet

  46. purchase itraconazole without prescriptions canada

    buying itraconazole generic itraconazole

  47. cheap staxyn usa where to buy

    buy cheap staxyn cheap buy online no prescription

  48. buy cheap avodart uk in store

    get avodart generic work

  49. how to buy xifaxan cheap sale

    cheapest xifaxan substitute sildenafil

  50. get rifaximin canada fast shipping

    ordering rifaximin lowest cost pharmacy

  51. kamagra prodeje v usa

    dト嬪テ。 levnテゥ kamagra prテ。ci

Leave a Reply Cancel reply

Exit mobile version