Flutter: Difference between revisions

From NixOS Wiki
imported>Onny
mNo edit summary
imported>Garethstokes
m update dev flake to flutter 3.13.x
Line 7: Line 7:
{{file|flake.nix|nix|<nowiki>
{{file|flake.nix|nix|<nowiki>
{
{
description = "Flutter 3.0.4";
description = "Flutter 3.13.x";
inputs = {
inputs = {
   nixpkgs.url = "github:NixOS/nixpkgs/23.05";
   nixpkgs.url = "github:NixOS/nixpkgs/23.05";
Line 22: Line 22:
         };
         };
       };
       };
       buildToolsVersion = "30.0.3";
       buildToolsVersion = "34.0.0";
       androidComposition = pkgs.androidenv.composeAndroidPackages {
       androidComposition = pkgs.androidenv.composeAndroidPackages {
         buildToolsVersions = [ buildToolsVersion "28.0.3" ];
         buildToolsVersions = [ buildToolsVersion "28.0.3" ];
         platformVersions = [ "31" "28" ];
         platformVersions = [ "34" "28" ];
         abiVersions = [ "armeabi-v7a" "arm64-v8a" ];
         abiVersions = [ "armeabi-v7a" "arm64-v8a" ];
       };
       };
Line 37: Line 37:
             flutter
             flutter
             androidSdk
             androidSdk
             jdk11
             jdk17
           ];
           ];
         };
         };

Revision as of 00:05, 5 November 2023

Flutter is an open-source mobile application development framework created by Google. It allows developers to build high-performance, cross-platform apps for iOS and Android using a single codebase.

Development

Create following flake.nix in a new project directory

flake.nix
{
description = "Flutter 3.13.x";
inputs = {
  nixpkgs.url = "github:NixOS/nixpkgs/23.05";
  flake-utils.url = "github:numtide/flake-utils";
};
outputs = { self, nixpkgs, flake-utils }:
  flake-utils.lib.eachDefaultSystem (system:
    let
      pkgs = import nixpkgs {
        inherit system;
        config = {
          android_sdk.accept_license = true;
          allowUnfree = true;
        };
      };
      buildToolsVersion = "34.0.0";
      androidComposition = pkgs.androidenv.composeAndroidPackages {
        buildToolsVersions = [ buildToolsVersion "28.0.3" ];
        platformVersions = [ "34" "28" ];
        abiVersions = [ "armeabi-v7a" "arm64-v8a" ];
      };
      androidSdk = androidComposition.androidsdk;
    in
    {
      devShell =
        with pkgs; mkShell rec {
          ANDROID_SDK_ROOT = "${androidSdk}/libexec/android-sdk";
          buildInputs = [
            flutter
            androidSdk
            jdk17
          ];
        };
    });
}

Run following commands to start a new demo project and run the "hello world" application

# nix develop
# flutter create my_app
# cd my_app
# flutter run

Packaging

Use buildFlutterApplication from nixpkgs.

See also

  • The team working on flutter in nixpkgs maintains several pieces of infrastructure related to the cause. The documentation is lacking as of now, but there are plans to improve it.