### Setup flutter-pi on Raspberry Pi Source: https://github.com/ardera/flutter-pi/blob/master/GETTING_STARTED.md This bash script installs necessary dependencies, clones the flutter-pi repository, and compiles it on the Raspberry Pi. It also sets up engine binaries and creates an application directory. ```bash export APPNAME=hello_pi # change this to the name of your application # one-time setup sudo usermod -a -G render $USER sudo apt --yes install libgl1-mesa-dev libgles2-mesa-dev libegl-mesa0 libdrm-dev libgbm-dev sudo apt --yes install libsystemd-dev libinput-dev libudev-dev libxkbcommon-dev sudo apt --yes install ttf-mscorefonts-installer fontconfig sudo fc-cache if [ `uname -m` == 'armv7l' ]; then export ARM=arm; else export ARM=arm64; fi mkdir -p ~/dev pushd ~/dev git clone --depth 1 https://github.com/ardera/flutter-engine-binaries-for-arm engine-binaries sudo ./engine-binaries/install.sh git clone https://github.com/ardera/flutter-pi.git cd flutter-pi mkdir build && cd build cmake .. make -j`nproc` # per-application setup mkdir -p ~/dev/$APPNAME popd echo You will need to set ARM to: $ARM ``` -------------------------------- ### Build and Deploy Flutter App with flutter-pi Source: https://github.com/ardera/flutter-pi/blob/master/GETTING_STARTED.md This bash script sets up Flutter on a host machine, creates a new Flutter application, compiles it for the Raspberry Pi, and deploys it to the target device. It includes steps for precaching Flutter, building the application bundle, generating a kernel snapshot, and running the application on the Raspberry Pi. ```bash export VERSION=... # set this to the version determined above, e.g. 1.22.4 export ARM=... # set this to "arm" or "arm64" as determined above export TARGET=... # set this to your Raspberry Pi's hostname export APPNAME=hello_pi # same as what you used earlier export TARGETUSER=pi # set this to your username on the raspberry pi, e.g. "pi" or $USER if it's the same as on the host mkdir -p ~/dev pushd ~/dev # one-time setup git clone --branch $VERSION https://github.com/flutter/flutter.git flutter-for-pi ~/dev/flutter-for-pi/bin/flutter precache git clone --depth 1 https://github.com/ardera/flutter-engine-binaries-for-arm engine-binaries chmod +x engine-binaries/$ARM/gen_snapshot_linux_x64_release # create the application flutter-for-pi/bin/flutter create $APPNAME # compile the application cd $APPNAME ../flutter-for-pi/bin/flutter packages get # this might not be necessary ../flutter-for-pi/bin/flutter build bundle --no-tree-shake-icons --precompiled ../flutter-for-pi/bin/cache/dart-sdk/bin/dart \ ../flutter-for-pi/bin/cache/dart-sdk/bin/snapshots/frontend_server.dart.snapshot \ --sdk-root ~/dev/flutter-for-pi/bin/cache/artifacts/engine/common/flutter_patched_sdk_product \ --target=flutter \ --aot --tfa -Ddart.vm.product=true \ --packages .dart_tool\package_config.json --output-dill build/kernel_snapshot.dill --depfile build/kernel_snapshot.d ../engine-binaries/$ARM/gen_snapshot_linux_x64_release \ --deterministic --snapshot_kind=app-aot-elf \ --strip --sim-use-hardfp \ --elf=build/flutter_assets/app.so build/kernel_snapshot.dill # upload the application rsync --recursive ~/dev/$APPNAME/build/flutter_assets/ $TARGETUSER@$TARGET:dev/$APPNAME # run the application ssh $TARGETUSER@$TARGET "killall" "flutter-pi" ssh $TARGETUSER@$TARGET "dev/flutter-pi/build/flutter-pi" "--release" "~/dev/$APPNAME" popd ``` -------------------------------- ### Bash Vulkan Rendering Setup for flutter-pi Source: https://context7.com/ardera/flutter-pi/llms.txt Provides bash commands to set up Vulkan rendering support for flutter-pi. This involves installing necessary development packages for Vulkan and Mesa, cloning the Mesa and DRM repositories, and building libdrm with specific configurations for optimal performance. ```bash # Install Vulkan build dependencies sudo apt install libvulkan-dev # Install mesa build requirements sudo apt install git python3 python3-pip ninja-build bison flex pkg-config pip3 install mako meson # Build latest mesa Vulkan driver git clone --depth 1 https://gitlab.freedesktop.org/mesa/mesa.git git clone --depth 1 https://gitlab.freedesktop.org/mesa/drm.git # Build libdrm meson setup --prefix ~/mesa-install -Dbuildtype=release \ -Dradeon=disabled -Damdgpu=disabled -Dnouveau=disabled \ -Dvmwgfx=disabled -Dfreedreno=disabled -Detnaviv=disabled \ -Dc_args="-march=native -mcpu=native -mtune=native" \ ./drm ./drm/build ninja -C ./drm/build install ``` -------------------------------- ### Build Flutter App Bundle and Deploy Example (flutter gallery) Source: https://github.com/ardera/flutter-pi/wiki/Manually-building-an-app-bundle This example demonstrates cloning the Flutter gallery, building its asset bundle, and deploying it to a Raspberry Pi. It then shows how to run the deployed app in debug mode using flutter-pi. This requires git, flutter SDK, and rsync. ```bash git clone https://github.com/flutter/gallery.git flutter_gallery && cd flutter_gallery flutter build bundle rsync -a ./build/flutter_assets/ pi@raspberrypi:/home/pi/flutter_gallery/ flutter-pi /home/pi/flutter_gallery ``` -------------------------------- ### Install flutter-pi (Shell) Source: https://github.com/ardera/flutter-pi/blob/master/README.md Installs the compiled flutter-pi project to the system. This command typically copies the necessary executables and libraries to standard system locations, making flutter-pi available for execution. ```shell sudo make install ``` -------------------------------- ### Setup ALSA for Audio Playback on Raspberry Pi Source: https://context7.com/ardera/flutter-pi/llms.txt Configures the Raspberry Pi for audio playback using ALSA, which is required for the audioplayers plugin. This includes installing the GStreamer ALSA plugin and verifying ALSA functionality. ```bash # Required setup on Raspberry Pi # Remove pulseaudio (can interfere with ALSA) sudo apt remove pulseaudio # Install ALSA gstreamer plugin sudo apt install gstreamer1.0-alsa # Verify ALSA is working aplay -L # Test audio with gstreamer directly gst-launch-1.0 playbin uri=file:///path/to/audio.mp3 ``` -------------------------------- ### Install System Libraries for flutter-pi (Shell) Source: https://github.com/ardera/flutter-pi/blob/master/README.md Installs essential system libraries for flutter-pi, including CMake, OpenGL ES, EGL, DRM, GBM, font packages, systemd utilities, and input handling libraries. This command ensures all necessary components are present for flutter-pi to function correctly. ```shell sudo apt install cmake libgl1-mesa-dev libgles2-mesa-dev libegl1-mesa-dev libdrm-dev libgbm-dev ttf-mscorefonts-installer fontconfig libsystemd-dev libinput-dev libudev-dev libxkbcommon-dev ``` -------------------------------- ### Install GStreamer Libraries for flutter-pi (Shell) Source: https://github.com/ardera/flutter-pi/blob/master/README.md Installs GStreamer development libraries and plugins required for video playback functionality within flutter-pi. This is an optional step, only needed if the gstreamer video player feature is to be utilized. ```shell sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-plugins-bad gstreamer1.0-libav gstreamer1.0-alsa ``` -------------------------------- ### Build and Deploy Flutter Gallery Example on Windows Source: https://github.com/ardera/flutter-pi/wiki/Manually-building-an-app-bundle This Bash script clones the Flutter Gallery repository, downloads engine binaries, builds the asset bundle, compiles the kernel snapshot, generates an AOT ELF snapshot for ARM, and deploys the assets to a Raspberry Pi using rsync. It requires Git, Flutter SDK, and WSL. ```bash git clone https://github.com/flutter/gallery.git flutter_gallery git clone --depth 1 https://github.com/ardera/flutter-engine-binaries-for-arm.git engine-binaries cd flutter_gallery git checkout d77920b4ced4a105ad35659fbe3958800d418fb9 flutter build bundle C:\flutter\bin\cache\dart-sdk\bin\dart.exe \ C:\flutter\bin\cache\dart-sdk\bin\snapshots\frontend_server.dart.snapshot \ --sdk-root C:\flutter\bin\cache\artifacts\engine\common\flutter_patched_sdk_product \ --target=flutter \ --aot \ --tfa \ -Ddart.vm.product=true \ --packages .dart_tool\package_config.json \ --output-dill build\kernel_snapshot.dill \ --verbose \ --depfile build\kernel_snapshot.d \ package:gallery/main.dart wsl ../engine-binaries/arm/gen_snapshot_linux_x64_release \ --deterministic \ --snapshot_kind=app-aot-elf \ --elf=build/flutter_assets/app.so \ --strip \ --sim-use-hardfp \ build/kernel_snapshot.dill rsync -a --info=progress2 ./build/flutter_assets/ pi@raspberrypi:/home/pi/flutter_gallery/ exit ``` -------------------------------- ### Install Flutter-pi Vulkan Build Dependencies (Shell) Source: https://github.com/ardera/flutter-pi/wiki/Running-flutter-pi-with-vulkan Installs the development headers for the Vulkan library, which are necessary for building flutter-pi with Vulkan support. ```shell sudo apt install libvulkan-dev ``` -------------------------------- ### Install Flutter-Pi Executable - CMake Source: https://github.com/ardera/flutter-pi/blob/master/CMakeLists.txt Installs the 'flutter-pi' target to the 'bin' directory at runtime. This makes the executable available in the system's PATH after installation. ```cmake install(TARGETS flutter-pi RUNTIME DESTINATION bin) ``` -------------------------------- ### Install Mesa Build Dependencies (Shell) Source: https://github.com/ardera/flutter-pi/wiki/Running-flutter-pi-with-vulkan Installs the essential packages required to build the Mesa graphics driver from source. This includes tools like git, python, ninja, bison, flex, and pkg-config, along with the mako Python package. ```shell $ sudo apt install git python3 python3-pip ninja-build bison flex pkg-config $ pip3 install mako ``` -------------------------------- ### Install GStreamer for flutter-pi Source: https://context7.com/ardera/flutter-pi/llms.txt Installs the necessary GStreamer development libraries and plugins on a Raspberry Pi to enable video playback with flutter-pi. After installation, flutter-pi needs to be rebuilt to include the GStreamer plugin. ```bash # Ensure gstreamer is installed on Raspberry Pi sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \ libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base \ gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly \ gstreamer1.0-plugins-bad gstreamer1.0-libav gstreamer1.0-alsa # Rebuild flutter-pi to enable gstreamer plugin cd flutter-pi/build rm -rf * cake .. make -j$(nproc) sudo make install ``` -------------------------------- ### Install Dependencies and Build flutter-pi Source: https://context7.com/ardera/flutter-pi/llms.txt Installs necessary dependencies for flutter-pi and then clones, builds, and installs the embedder from source. This process is essential for running Flutter applications on Raspberry Pi without a desktop environment. It includes optional dependencies for the gstreamer video player plugin. ```bash # Install required dependencies sudo apt install cmake libgl1-mesa-dev libgles2-mesa-dev libegl1-mesa-dev \ libdrm-dev libgbm-dev ttf-mscorefonts-installer fontconfig libsystemd-dev \ libinput-dev libudev-dev libxkbcommon-dev # Install gstreamer dependencies for video player plugin (optional) sudo apt install libgstreamer1.0-dev libgstreamer-plugins-base1.0-dev \ libgstreamer-plugins-bad1.0-dev gstreamer1.0-plugins-base \ gstreamer1.0-plugins-good gstreamer1.0-plugins-ugly gstreamer1.0-plugins-bad \ gstreamer1.0-libav gstreamer1.0-alsa # Update font cache sudo fc-cache # Clone and build flutter-pi git clone --recursive https://github.com/ardera/flutter-pi cd flutter-pi mkdir build && cd build cmake .. make -j$(nproc) sudo make install ``` -------------------------------- ### Reinstall Meson for Mesa (Shell) Source: https://github.com/ardera/flutter-pi/wiki/Running-flutter-pi-with-vulkan Ensures that a compatible version of the Meson build system is installed, as Mesa requires a newer version than what might be available through Raspbian's package manager. ```shell $ sudo apt remove meson $ pip3 install meson ``` -------------------------------- ### Deploy Flutter Assets to Raspberry Pi using scp Source: https://github.com/ardera/flutter-pi/wiki/Manually-building-an-app-bundle This command deploys the Flutter asset bundle from the local build directory to a specified path on the Raspberry Pi using scp. It recursively copies the assets. Ensure you have scp installed and SSH access to your Raspberry Pi. ```bash scp -r ./build/flutter_assets/ pi@raspberrypi:/home/pi/my_apps_flutter_assets ``` -------------------------------- ### Install Sentry Dependencies on Debian/Ubuntu Source: https://github.com/ardera/flutter-pi/wiki/Sentry-Plugin Installs the required development library for libcurl, a common dependency for network-related operations used by Sentry. ```shell sudo apt install libcurl4-openssl-dev ``` -------------------------------- ### Clone and Build Mesa Graphics Driver (Shell) Source: https://github.com/ardera/flutter-pi/wiki/Running-flutter-pi-with-vulkan Clones the Mesa and DRM repositories and compiles them with specific configurations for Raspberry Pi. This process involves setting up the build environment using Meson and then installing the compiled drivers. ```shell $ git clone --depth 1 https://gitlab.freedesktop.org/mesa/mesa.git $ git clone --depth 1 https://gitlab.freedesktop.org/mesa/drm.git $ meson setup --prefix ~/mesa-install -Dbuildtype=release -Dradeon=disabled -Damdgpu=disabled -Dnouveau=disabled -Dvmwgfx=disabled -Dfreedreno=disabled -Detnaviv=disabled -Dc_args="-march=native -mcpu=native -mtune=native" ./drm ./drm/build $ ninja -C ./drm/build install $ PKG_CONFIG_PATH=~/mesa-install/lib/arm-linux-gnueabihf/pkgconfig meson setup --prefix=~/mesa-install -Dbuildtype=release -Dgallium-drivers= -Dllvm=disabled -Dvulkan-drivers=broadcom -Dglx=disabled -Dplatforms= -Dc_args="-march=native -mcpu=native -mtune=native" ./mesa ./mesa/build $ ninja -C ./mesa/build install ``` -------------------------------- ### Enable and Capture Verbose DRM Logs with flutter-pi Source: https://github.com/ardera/flutter-pi/wiki/debugging-output-issues This snippet demonstrates how to enable verbose DRM logging by writing to a kernel parameter, clear existing kernel logs, start capturing new logs to a file in the background, run the flutter-pi application, and then disable DRM logging. This process is crucial for capturing detailed information about graphics driver behavior during flutter-pi execution. ```bash echo 0x1FF | sudo tee /sys/module/drm/parameters/debug # Enable verbose DRM logging sudo dmesg -C # Clear kernel logs dmesg -w >dmesg.log & # Continuously write DRM logs to a file, in the background flutter-pi ... # Run flutter-pi again, manually terminate it after a few errors have happened fg # Kill dmesg with Ctrl+C echo 0 | sudo tee /sys/module/drm/parameters/debug # Disable DRM logging ``` -------------------------------- ### Deploy Flutter Assets to Raspberry Pi using rsync Source: https://github.com/ardera/flutter-pi/wiki/Manually-building-an-app-bundle This command deploys the Flutter asset bundle from the local build directory to a specified path on the Raspberry Pi. It utilizes rsync for efficient file transfer, showing progress. Ensure you have rsync installed and SSH access to your Raspberry Pi. ```bash rsync -a --info=progress2 ./build/flutter_assets/ pi@raspberrypi:/home/pi/my_apps_flutter_assets ``` -------------------------------- ### Flutter Audio Player with ALSA Backend Source: https://context7.com/ardera/flutter-pi/llms.txt Demonstrates how to use the audioplayers plugin in Flutter to play audio files, specifically configured to use the ALSA backend on a Raspberry Pi. This involves installing the GStreamer ALSA plugin and potentially removing PulseAudio. ```dart // Flutter code using audioplayers ^5.0.0 import 'package:audioplayers/audioplayers.dart'; class AudioPlayerExample { // Use a single global instance for constrained systems static final AudioPlayer player = AudioPlayer(); static Future playSound(String url) async { await player.play(UrlSource(url)); } static Future playAsset(String assetPath) async { await player.play(AssetSource(assetPath)); } static Future pause() async { await player.pause(); } static Future resume() async { await player.resume(); } static Future stop() async { await player.stop(); } static Future setVolume(double volume) async { await player.setVolume(volume); // 0.0 to 1.0 } } ``` -------------------------------- ### Deploy Release Build to Raspberry Pi (Bash) Source: https://github.com/ardera/flutter-pi/blob/master/README.md Deploys the built asset bundle and the app.so file to the Raspberry Pi for release mode execution. This uses rsync or scp for transferring the files to the specified directory on the Pi. ```bash rsync -a --info=progress2 ./build/flutter_assets/ pi@raspberrypi:/home/pi/my_app ``` ```bash scp -r ./build/flutter_assets/ pi@raspberrypi:/home/pi/my_app ``` -------------------------------- ### Build and Deploy Flutter App Assets (Bash) Source: https://github.com/ardera/flutter-pi/blob/master/README.md Builds the Flutter asset bundle for an application and deploys it to a Raspberry Pi using rsync. This is typically used for debug builds. Ensure the Flutter SDK and engine binaries are compatible. ```bash rsync -a --info=progress2 ./build/flutter_assets/ pi@raspberrypi:/home/pi/my_apps_flutter_assets ``` ```bash scp -r ./build/flutter_assets/ pi@raspberrypi:/home/pi/my_apps_flutter_assets ``` ```bash git clone https://github.com/flutter/gallery.git flutter_gallery cd flutter_gallery git checkout d77920b4ced4a105ad35659fbe3958800d418fb9 flutter build bundle rsync -a ./build/flutter_assets/ pi@raspberrypi:/home/pi/flutter_gallery/ ``` -------------------------------- ### Deploy Flutter App Bundle and app.so to Raspberry Pi Source: https://github.com/ardera/flutter-pi/wiki/Manually-building-an-app-bundle This command deploys both the Flutter asset bundle and the compiled app.so file to the Raspberry Pi. It uses rsync for efficient transfer, showing progress. This is the final deployment step before running the app in release mode. ```bash rsync -a --info=progress2 ./build/flutter_assets/ pi@raspberrypi:/home/pi/my_app ``` -------------------------------- ### Build Kernel Snapshot for Flutter App (Windows CMD) Source: https://github.com/ardera/flutter-pi/wiki/Manually-building-an-app-bundle This command builds a kernel snapshot for a Flutter application on Windows. It requires the Flutter SDK and its associated tools. The command specifies SDK roots, target platform, and output files. Ensure the paths to dart.exe, frontend_server.dart.snapshot, and the SDK are correct for your environment. ```cmd C:\flutter\bin\cache\dart-sdk\bin\dart.exe ^ C:\flutter\bin\cache\dart-sdk\bin\snapshots\frontend_server.dart.snapshot ^ --sdk-root C:\flutter\bin\cache\artifacts\engine\common\flutter_patched_sdk_product ^ --target=flutter ^ --aot ^ --tfa ^ -Ddart.vm.product=true ^ --packages .dart_tool\package_config.json ^ --output-dill build\kernel_snapshot.dill ^ --verbose ^ --depfile build\kernel_snapshot.d ^ package:my_app_name/main.dart ``` -------------------------------- ### Update System Fonts (Bash) Source: https://github.com/ardera/flutter-pi/blob/master/README.md Updates the system's font cache after installing new fonts, such as the Arial font required by the flutter engine. This command ensures that newly installed fonts are recognized and available for applications. ```bash sudo fc-cache ``` -------------------------------- ### Run Flutter Applications with flutter-pi Source: https://context7.com/ardera/flutter-pi/llms.txt Demonstrates various command-line options for running Flutter applications using flutter-pi. This includes selecting runtime modes (debug, release, profile), setting screen orientation, applying rotation, specifying display dimensions for DPI scaling, forcing video modes, enabling Vulkan rendering, running in headless mode with a dummy display, and selecting pixel formats. ```bash # Run app in debug mode (default) flutter-pi ~/my_flutter_app # Run app in release mode (requires AOT compiled app.so) flutter-pi --release ~/my_flutter_app # Run app in profile mode flutter-pi --profile ~/my_flutter_app # Run with specific screen orientation flutter-pi -o portrait_up ~/my_flutter_app flutter-pi -o landscape_left ~/my_flutter_app flutter-pi -o portrait_down ~/my_flutter_app flutter-pi -o landscape_right ~/my_flutter_app # Run with rotation (degrees, clockwise) flutter-pi -r 90 ~/my_flutter_app flutter-pi -r 180 ~/my_flutter_app # Specify physical display dimensions (mm) for correct DPI scaling flutter-pi -d "155,86" ~/my_flutter_app # Force specific video mode flutter-pi --videomode 1920x1080 ~/my_flutter_app flutter-pi --videomode 1280x720@60 ~/my_flutter_app # Run with Vulkan rendering (requires Vulkan support) flutter-pi --vulkan ~/my_flutter_app # Run without a physical display (headless mode) flutter-pi --dummy-display --dummy-display-size "800,480" ~/my_flutter_app # Select specific pixel format for framebuffers flutter-pi --pixelformat ARGB8888 ~/my_flutter_app ``` -------------------------------- ### Build app.so for Release/Profile Mode (Linux x64) Source: https://github.com/ardera/flutter-pi/wiki/Manually-building-an-app-bundle This command builds the shared object file (app.so) required for running Flutter apps in release or profile mode on Raspberry Pi. It's executed on a Linux x64 machine (or WSL/VM) using a pre-downloaded snapshot generator. Ensure you have the correct `gen_snapshot_linux_x64_release` binary and the kernel snapshot file. ```bash gen_snapshot_linux_x64_release \ --deterministic \ --snapshot_kind=app-aot-elf \ --elf=build/flutter_assets/app.so \ --strip \ --sim-use-hardfp \ build/kernel_snapshot.dill ``` -------------------------------- ### Clone flutter-pi Repository (Bash) Source: https://github.com/ardera/flutter-pi/blob/master/README.md Clones the flutter-pi repository from GitHub, including all submodules, and navigates into the cloned directory. The `--recursive` flag is crucial for ensuring that all necessary submodules, like the flutter engine, are downloaded. ```bash git clone --recursive https://github.com/ardera/flutter-pi cd flutter-pi ``` -------------------------------- ### Flutter Video Player with GStreamer Source: https://context7.com/ardera/flutter-pi/llms.txt Integrates Flutter's standard video_player package with the built-in GStreamer video player plugin on Raspberry Pi. No special configuration is needed within the Flutter code itself, assuming GStreamer is properly installed and flutter-pi is rebuilt with GStreamer support. ```dart // Flutter code - no special configuration needed import 'package:video_player/video_player.dart'; class VideoPlayerWidget extends StatefulWidget { @override _VideoPlayerWidgetState createState() => _VideoPlayerWidgetState(); } class _VideoPlayerWidgetState extends State { late VideoPlayerController _controller; @override void initState() { super.initState(); _controller = VideoPlayerController.network( 'https://example.com/video.mp4', )..initialize().then((_) { setState(() {}); _controller.play(); }); } @override Widget build(BuildContext context) { return _controller.value.isInitialized ? AspectRatio( aspectRatio: _controller.value.aspectRatio, child: VideoPlayer(_controller), ) : CircularProgressIndicator(); } @override void dispose() { _controller.dispose(); super.dispose(); } } ``` -------------------------------- ### Compile flutter-pi Project (Shell) Source: https://github.com/ardera/flutter-pi/blob/master/README.md Compiles the flutter-pi project using CMake and Make. It first creates a build directory, then configures the build using CMake, and finally compiles the project utilizing all available processor cores for faster build times. ```shell mkdir build && cd build cmake .. make -j`nproc` ``` -------------------------------- ### Run Flutter App in Release Mode on Raspberry Pi Source: https://github.com/ardera/flutter-pi/wiki/Manually-building-an-app-bundle This command launches a deployed Flutter application in release mode on the Raspberry Pi using the flutter-pi executable. It requires the path to the deployed application assets. Ensure the app.so and asset bundle are correctly placed on the Raspberry Pi. ```bash flutter-pi --release /home/pi/my_app ``` -------------------------------- ### Build and Deploy Flutter App to Raspberry Pi Source: https://context7.com/ardera/flutter-pi/llms.txt This snippet demonstrates how to build the app.so snapshot for ARM 64-bit and then deploy it to a Raspberry Pi. It uses rsync for file transfer and ssh to run the flutter-pi command remotely. Ensure you have the necessary build tools and SSH access configured. ```bash # Build app.so (ARM 64-bit - omit --sim-use-hardfp) ./gen_snapshot_linux_x64_release \ --deterministic \ --snapshot_kind=app-aot-elf \ --elf=build/flutter_assets/app.so \ --strip \ build/kernel_snapshot.dill # Deploy and run rsync -a ./build/flutter_assets/ pi@raspberrypi:/home/pi/my_app/ ssh pi@raspberrypi "flutter-pi --release /home/pi/my_app" ``` -------------------------------- ### Clone flutter-pi with Git Submodules Source: https://github.com/ardera/flutter-pi/wiki/Sentry-Plugin Instructions to clone the flutter-pi repository, ensuring that all necessary submodules, including the Sentry native integration, are fetched. ```shell git submodule update --init --recursive git clone --recursive https://github.com/ardera/flutter-pi.git ``` -------------------------------- ### Build Mesa Vulkan Driver and flutter-pi Source: https://context7.com/ardera/flutter-pi/llms.txt Builds the Mesa Vulkan driver and then compiles flutter-pi with Vulkan support. This involves setting up the build environment for Mesa and then using CMake and Ninja for flutter-pi. ```bash # Build mesa Vulkan driver PKG_CONFIG_PATH=~/mesa-install/lib/arm-linux-gnueabihf/pkgconfig \ meson setup --prefix=~/mesa-install -Dbuildtype=release \ -Dgallium-drivers= -Dllvm=disabled -Dvulkan-drivers=broadcom \ -Dglx=disabled -Dplatforms= \ -Dc_args="-march=native -mcpu=native -mtune=native" \ ./mesa ./mesa/build ninja -C ./mesa/build install # Build flutter-pi with Vulkan support git clone https://github.com/ardera/flutter-pi.git cd flutter-pi mkdir build && cd build cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -DENABLE_VULKAN=On -DVULKAN_DEBUG=OFF ninja ``` -------------------------------- ### Manually Build Flutter App Bundle with AOT Compilation Source: https://context7.com/ardera/flutter-pi/llms.txt Provides a manual process for building a Flutter application bundle with Ahead-of-Time (AOT) compilation for release or profile modes. This involves building the asset bundle, generating a kernel snapshot using `frontend_server.dart.snapshot`, and then creating the `app.so` file using `gen_snapshot` for ARM 32-bit. ```bash # Build the asset bundle cd ~/my_flutter_project flutter build bundle # Build kernel snapshot (Linux/macOS) dart \ $(dirname $(which flutter))/cache/dart-sdk/bin/snapshots/frontend_server.dart.snapshot \ --sdk-root $(dirname $(which flutter))/cache/artifacts/engine/common/flutter_patched_sdk_product \ --target=flutter \ --aot \ --tfa \ -Ddart.vm.product=true \ --packages .dart_tool/package_config.json \ --output-dill build/kernel_snapshot.dill \ --depfile build/kernel_snapshot.d \ package:my_app/main.dart # Build app.so using gen_snapshot (ARM 32-bit) ./gen_snapshot_linux_x64_release \ --deterministic \ --snapshot_kind=app-aot-elf \ --elf=build/flutter_assets/app.so \ --strip \ --sim-use-hardfp \ build/kernel_snapshot.dill ``` -------------------------------- ### Build Flutter App Bundle with flutterpi_tool Source: https://context7.com/ardera/flutter-pi/llms.txt Builds a Flutter application bundle for Raspberry Pi using the `flutterpi_tool`, which automates cross-compilation. This method simplifies the process of preparing an application for deployment. It also includes commands for deploying the built assets to the Raspberry Pi using `rsync` or `scp` and then running the application remotely. ```bash # One-time setup: Install flutterpi_tool flutter pub global activate flutterpi_tool # Navigate to your Flutter project cd ~/my_flutter_project # Build for ARM 32-bit debug mode (default) flutterpi_tool build # Build for ARM 64-bit release mode, optimized for Pi 4 flutterpi_tool build --arch=arm64 --cpu=pi4 --release # Build for ARM 32-bit profile mode flutterpi_tool build --arch=arm --profile # Deploy to Raspberry Pi using rsync rsync -a --info=progress2 ./build/flutter_assets/ pi@raspberrypi:/home/pi/my_app # Or deploy using scp scp -r ./build/flutter_assets/ pi@raspberrypi:/home/pi/my_app # Run on Raspberry Pi ssh pi@raspberrypi "flutter-pi --release /home/pi/my_app" ``` -------------------------------- ### Raspberry Pi Configuration for flutter-pi Source: https://context7.com/ardera/flutter-pi/llms.txt This section details the configuration steps for a Raspberry Pi to optimize flutter-pi performance. It includes modifying system settings via raspi-config, granting render permissions, and rebooting. These steps are crucial for smooth Flutter application execution on the device. ```bash # Open raspi-config sudo raspi-config # Configuration steps: # 1. System Options -> Boot / Auto Login -> Console (or Console Autologin) # 2. Advanced Options -> GL Driver -> GL (Fake KMS) [Skip on Pi 4 with Bullseye] # 3. Performance Options -> GPU Memory -> 64 # Grant render permissions to user (alternative to running as sudo) sudo usermod -a -G render $USER # Reboot to apply changes sudo reboot ``` -------------------------------- ### C Plugin Development for flutter-pi Source: https://context7.com/ardera/flutter-pi/llms.txt Demonstrates how to create a custom flutter-pi plugin with initialization, message handling, and cleanup functions. It utilizes the plugin registry and platform channels for communication with the Flutter application. Dependencies include 'pluginregistry.h' and 'platformchannel.h'. ```c #include "pluginregistry.h" #include "platformchannel.h" // Plugin state structure struct my_plugin_state { int sensor_fd; char *device_path; }; // Message handler for the plugin static void on_platform_message(void *userdata, const FlutterPlatformMessage *message) { struct my_plugin_state *state = userdata; // Decode the message struct platch_obj object; if (platch_decode(message->message, message->message_size, kStandardMethodCall, &object) != 0) { platch_respond_not_implemented(message->response_handle); return; } if (strcmp(object.method, "initialize") == 0) { // Initialize sensor platch_respond_success_std(message->response_handle, &STDBOOL(true)); } else if (strcmp(object.method, "readSensor") == 0) { // Read sensor value double value = 42.0; // Read from actual sensor platch_respond_success_std(message->response_handle, &STDFLOAT64(value)); } else { platch_respond_not_implemented(message->response_handle); } platch_free_obj(&object); } // Plugin initialization function static enum plugin_init_result my_plugin_init(struct flutterpi *flutterpi, void **userdata_out) { struct my_plugin_state *state = calloc(1, sizeof(*state)); if (!state) { return PLUGIN_INIT_RESULT_ERROR; } // Initialize plugin resources state->device_path = strdup("/dev/sensor0"); state->sensor_fd = -1; // Open actual device // Register platform channel receiver struct plugin_registry *registry = flutterpi_get_plugin_registry(flutterpi); plugin_registry_set_receiver_v2(registry, "com.example/my_sensor", on_platform_message, state); *userdata_out = state; return PLUGIN_INIT_RESULT_INITIALIZED; } // Plugin cleanup function static void my_plugin_deinit(struct flutterpi *flutterpi, void *userdata) { struct my_plugin_state *state = userdata; // Remove channel receiver struct plugin_registry *registry = flutterpi_get_plugin_registry(flutterpi); plugin_registry_remove_receiver_v2(registry, "com.example/my_sensor"); // Cleanup resources if (state->sensor_fd >= 0) { close(state->sensor_fd); } free(state->device_path); free(state); } // Register the plugin using the macro FLUTTERPI_PLUGIN("my_sensor_plugin", my_sensor_plugin, my_plugin_init, my_plugin_deinit); ``` -------------------------------- ### Define Executable and Link Libraries (CMake) Source: https://github.com/ardera/flutter-pi/blob/master/test/CMakeLists.txt This snippet demonstrates how to define an executable target and link it with necessary libraries using CMake. It includes adding source files to the executable and specifying dependencies like 'flutterpi_module' and 'Unity'. This is a common pattern for building C/C++ projects with CMake. ```cmake add_executable(platformchannel_test platformchannel_test.c ) target_link_libraries( platformchannel_test flutterpi_module Unity ) ``` ```cmake add_executable(flutterpi_test flutterpi_test.c ) target_link_libraries( flutterpi_test flutterpi_module Unity ) ``` -------------------------------- ### Build Flutter-pi with Vulkan Enabled (Shell) Source: https://github.com/ardera/flutter-pi/wiki/Running-flutter-pi-with-vulkan Clones the flutter-pi repository, checks out the Vulkan-enabled branch, and compiles the application with Vulkan support activated. The `ENABLE_VULKAN` CMake option is set to 'On'. ```shell $ git clone https://github.com/ardera/flutter-pi.git $ cd flutter-pi $ git checkout feature/compositor-ng $ mkdir build $ cd build $ cmake .. -GNinja -DCMAKE_BUILD_TYPE=Release -DENABLE_VULKAN=On -DVULKAN_DEBUG=OFF $ ninja ``` -------------------------------- ### Initialize Sentry with Flutter-pi Platform Checker Source: https://github.com/ardera/flutter-pi/wiki/Sentry-Plugin Initializes the Sentry SDK within a Flutter application, configuring DSN, sampling rates, and crucially, using the custom `FlutterpiCompatiblePlatformChecker` to ensure native integration is correctly detected and enabled on flutter-pi devices. ```dart void main() async { await SentryFlutter.init( (options) { options.dsn = sentryDsn; // Set tracesSampleRate to 1.0 to capture 100% of transactions for performance monitoring. // We recommend adjusting this value in production. options.tracesSampleRate = 1.0; // The sampling rate for profiling is relative to tracesSampleRate // Setting to 1.0 will profile 100% of sampled transactions: options.profilesSampleRate = 1.0; options.debug = kDebugMode; }, appRunner: () => runApp(MyApp()), // Needed because sentry doesn't use the platform checker configured in the options // to check for native integration. // ignore: invalid_use_of_internal_member platformChecker: FlutterpiCompatiblePlatformChecker(), ); } ``` -------------------------------- ### Set Unity Library Compile Definitions Source: https://github.com/ardera/flutter-pi/blob/master/third_party/CMakeLists.txt Defines preprocessor macros for the 'Unity' library during compilation. 'UNITY_SUPPORT_64' and 'UNITY_INCLUDE_DOUBLE' are specific flags for this library's build. ```cmake target_compile_definitions(Unity PUBLIC UNITY_SUPPORT_64 UNITY_INCLUDE_DOUBLE ) ``` -------------------------------- ### Set Unity Library Include Directories Source: https://github.com/ardera/flutter-pi/blob/master/third_party/CMakeLists.txt Configures the public include directories for the 'Unity' library. This allows header files within the 'Unity/src' directory to be found during compilation. ```cmake target_include_directories(Unity PUBLIC Unity/src ) ``` -------------------------------- ### Upload Debug Symbols for C/C++ Stack Traces Source: https://github.com/ardera/flutter-pi/wiki/Sentry-Plugin Instructions for uploading debug symbols using `sentry-cli` to enable meaningful C/C++ stack traces in Sentry. This requires building flutter-pi and the Flutter app with debug information. ```shell sentry-cli debug-files upload # For flutter-pi: use -DCMAKE_BUILD_TYPE=RelWithDebInfo or -DCMAKE_BUILD_TYPE=Debug # For flutter app: flutterpi_tool build --debug-symbols ``` -------------------------------- ### Configure LTO/IPO Support in CMake Source: https://github.com/ardera/flutter-pi/blob/master/CMakeLists.txt This snippet checks and configures Link-Time Optimization (LTO) and Interprocedural Optimization (IPO) based on build type and toolchain support. It attempts to detect if LTO/IPO is supported by the compiler and linker, issuing warnings if not. It also includes logic to check for specific linker support like 'gold' or 'lld'. ```cmake set(NEEDS_LLD OFF) if(LTO AND (CMAKE_BUILD_TYPE STREQUAL Release OR CMAKE_BUILD_TYPE STREQUAL RelWithDebInfo)) # So people can specify `-fuse-ld=lld` in the CMAKE_C_FLAGS. # Otherwise check_ipo_supported will not use CMAKE_C_FLAGS. if (POLICY CMP0138) cmake_policy(SET CMP0138 NEW) endif() check_ipo_supported(RESULT IPO_SUPPORTED OUTPUT IPO_SUPPORT_OUTPUT) if (NOT IPO_SUPPORTED) message(WARNING "IPO/LTO was requested in the configure options, but is not supported by the toolchain. Check CMakeFiles/CMakeError.log for details.") endif() # clang doesn't support LTO when using GNU ld. if(IPO_SUPPORTED AND ("${CMAKE_C_COMPILER_ID}" STREQUAL "Clang")) execute_process(COMMAND ${CMAKE_C_COMPILER} -Wl,--version OUTPUT_VARIABLE LINKER_VERSION_OUTPUT ERROR_QUIET) if("${LINKER_VERSION_OUTPUT}" MATCHES "GNU ld") message(WARNING "IPO/LTO was requested, but is not supported when using clang with GNU ld as the linker. Try setting gold or lld as the system linker.") set(IPO_SUPPORTED OFF) endif() endif() if (IPO_SUPPORTED) set(USE_LTO ON) endif() endif() message(STATUS "IPO/LTO ................ ${USE_LTO}") if (USE_LTO) set_property(TARGET flutterpi_module PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) set_property(TARGET flutter-pi PROPERTY INTERPROCEDURAL_OPTIMIZATION TRUE) endif() ``` -------------------------------- ### Run Flutter-pi with Vulkan Enabled (Shell) Source: https://github.com/ardera/flutter-pi/wiki/Running-flutter-pi-with-vulkan Executes the compiled flutter-pi application with Vulkan rendering enabled. This command sets the `VK_ICD_FILENAMES` environment variable to point to the custom Vulkan ICD file and specifies the path to the flutter application. ```shell $ VK_ICD_FILENAMES=~/mesa-install/share/vulkan/icd.d/broadcom_icd.armv7l.json ./flutter-pi/build/flutter-pi --vulkan /path/to/your/app ``` -------------------------------- ### Add Unity Static Library Source: https://github.com/ardera/flutter-pi/blob/master/third_party/CMakeLists.txt This snippet defines a static library named 'Unity' using source files located in the 'Unity/src' directory. It's a common CMake command for organizing project components. ```cmake add_library(Unity STATIC Unity/src/unity.c ) ``` -------------------------------- ### Configure Session Switching with libseat in CMake Source: https://github.com/ardera/flutter-pi/blob/master/CMakeLists.txt This CMake snippet configures session switching support using the libseat library. It checks if session switching is enabled and attempts to find the libseat library using pkg-config. If libseat is found, it's linked to the flutterpi_module and a flag is set to indicate its availability. ```cmake set(HAVE_LIBSEAT OFF) if (ENABLE_SESSION_SWITCHING) if (TRY_ENABLE_SESSION_SWITCHING) pkg_check_modules(LIBSEAT IMPORTED_TARGET libseat) else() pkg_check_modules(LIBSEAT REQUIRED IMPORTED_TARGET libseat) endif() if (LIBSEAT_FOUND) target_link_libraries(flutterpi_module PUBLIC PkgConfig::LIBSEAT) set(HAVE_LIBSEAT ON) else() message("libseat was not found. flutter-pi will be built without session switching support.") endif() endif() message(STATUS "Session switching ...... ${HAVE_LIBSEAT}") ``` -------------------------------- ### Configure Header File - CMake Source: https://github.com/ardera/flutter-pi/blob/master/CMakeLists.txt Generates the config.h file from a template (config.h.in) using CMake's configure_file command. The @ONLY option ensures that only variables are substituted. ```cmake configure_file(config.h.in config.h @ONLY) ``` -------------------------------- ### GStreamer Audio Player Plugin Configuration (CMake) Source: https://github.com/ardera/flutter-pi/blob/master/CMakeLists.txt Configures the GStreamer audio player plugin for flutter-pi. It checks for GStreamer core, app, and audio libraries using pkg_check_modules. If dependencies are met, it adds the plugin's source files and links the necessary libraries. ```cmake if (BUILD_GSTREAMER_AUDIO_PLAYER_PLUGIN) if (TRY_BUILD_GSTREAMER_AUDIO_PLAYER_PLUGIN) pkg_check_modules(LIBGSTREAMER IMPORTED_TARGET gstreamer-1.0) pkg_check_modules(LIBGSTREAMER_APP IMPORTED_TARGET gstreamer-app-1.0) pkg_check_modules(LIBGSTREAMER_AUDIO IMPORTED_TARGET gstreamer-audio-1.0) else() pkg_check_modules(LIBGSTREAMER REQUIRED IMPORTED_TARGET gstreamer-1.0) pkg_check_modules(LIBGSTREAMER_APP REQUIRED IMPORTED_TARGET gstreamer-app-1.0) pkg_check_modules(LIBGSTREAMER_AUDIO REQUIRED IMPORTED_TARGET gstreamer-audio-1.0) endif() if (LIBGSTREAMER_FOUND AND LIBGSTREAMER_APP_FOUND AND LIBGSTREAMER_AUDIO_FOUND) target_sources(flutterpi_module PRIVATE src/plugins/audioplayers/plugin.c src/plugins/audioplayers/player.c ) target_link_libraries(flutterpi_module PUBLIC PkgConfig::LIBGSTREAMER PkgConfig::LIBGSTREAMER_APP PkgConfig::LIBGSTREAMER_AUDIO ) else() message(NOTICE "Couldn't find gstreamer libraries. Gstreamer audio player plugin won't be build.") endif() endif() ``` -------------------------------- ### C Texture Registry API for flutter-pi Source: https://context7.com/ardera/flutter-pi/llms.txt Shows how to register and update external textures for rendering video frames or custom graphics within flutter-pi. It covers creating textures, pushing frames (both GL and unresolved), and cleanup. Dependencies include 'texture_registry.h' and 'flutter-pi.h'. ```c #include "texture_registry.h" #include "flutter-pi.h" // Create a new texture struct texture_registry *registry = flutterpi_get_texture_registry(flutterpi); struct texture *my_texture = texture_new(registry); int64_t texture_id = texture_get_id(my_texture); // Send texture_id to Flutter via platform channel for Texture widget // Push a GL texture frame #ifdef HAVE_EGL_GLES2 struct texture_frame frame = { .gl = { .target = GL_TEXTURE_2D, .name = gl_texture_name, .format = GL_RGBA8, .width = 1920, .height = 1080, }, .destroy = my_frame_destroy_callback, .userdata = my_frame_data, }; ttexture_push_frame(my_texture, &frame); #endif // For lazy frame resolution (e.g., video decoding) static int resolve_frame(size_t width, size_t height, void *userdata, struct texture_frame *frame_out) { // Decode video frame on-demand at requested size frame_out->gl.target = GL_TEXTURE_2D; frame_out->gl.name = decoded_texture; frame_out->gl.format = GL_RGBA8; frame_out->gl.width = width; frame_out->gl.height = height; frame_out->destroy = NULL; frame_out->userdata = NULL; return 0; } struct unresolved_texture_frame unresolved = { .resolve = resolve_frame, .destroy = cleanup_decoder, .userdata = decoder_context, }; texture_push_unresolved_frame(my_texture, &unresolved); // Cleanup when done texture_destroy(my_texture); ``` -------------------------------- ### Build flutter-pi with Sentry Plugin Support Source: https://github.com/ardera/flutter-pi/wiki/Sentry-Plugin Configures the CMake build system to include the Sentry plugin during the flutter-pi compilation process. ```shell cmake ... -DBUILD_SENTRY_PLUGIN=On ```