Skip to content

Instantly share code, notes, and snippets.

@busla
Last active July 24, 2024 09:19
Show Gist options
  • Save busla/36e01f39c7a4d89d8c4e6b2360603f54 to your computer and use it in GitHub Desktop.
Save busla/36e01f39c7a4d89d8c4e6b2360603f54 to your computer and use it in GitHub Desktop.
flutterflow-local for Linux
#!/bin/bash
# Inspired by: https://github.com/bulgariamitko/flutterflowtutorials/blob/main/Linux%20App%20(unofficial)/ff-run.sh
# Adjusted for Fedora toolbox
command_exists() {
command -v "$1" >/dev/null 2>&1
}
# Check for required environment variables
if [ -z "$FLUTTERFLOW_PROJECT" ]; then
echo "Error: FLUTTERFLOW_PROJECT environment variable is not set."
exit 1
fi
# Assign arguments to variables
run_mode=${1:-"linux"} # Default to Linux mode if no argument is provided
is_flutter_running=${2:-false}
# Function to export FlutterFlow code
export_flutterflow_code() {
echo "Exporting FlutterFlow code..."
flutterflow export-code --dest "ff-app/$FLUTTERFLOW_PROJECT" --include-assets --no-parent-folder
}
# Function to check and install Linux dependencies in toolbox
check_and_install_linux_deps() {
local deps=(
"gtk3-devel"
"clang"
"cmake"
"ninja-build"
"pkgconf-pkg-config"
"glib2-devel"
"cairo-devel"
"pango-devel"
"libxkbcommon-devel"
"libX11-devel"
"libXrandr-devel"
"libXi-devel"
"libXcursor-devel"
"libXinerama-devel"
"mesa-libGL-devel"
"mesa-libEGL-devel"
"gstreamer1-devel"
"gstreamer1-plugins-base-devel"
)
for dep in "${deps[@]}"; do
if ! rpm -q "$dep" &>/dev/null; then
echo "Installing $dep..."
sudo dnf install -y "$dep"
else
echo "$dep is already installed."
fi
done
# Ensure pkg-config can find GTK3
export PKG_CONFIG_PATH="/usr/lib64/pkgconfig:/usr/share/pkgconfig:$PKG_CONFIG_PATH"
# Verify GTK3 installation
echo "Verifying GTK3 installation..."
if pkg-config --exists gtk+-3.0; then
echo "GTK3 found by pkg-config"
echo "GTK3 version: $(pkg-config --modversion gtk+-3.0)"
else
echo "Error: GTK3 not found by pkg-config"
echo "PKG_CONFIG_PATH: $PKG_CONFIG_PATH"
echo "Contents of /usr/lib64/pkgconfig:"
ls -l /usr/lib64/pkgconfig | grep gtk
echo "Contents of /usr/share/pkgconfig:"
ls -l /usr/share/pkgconfig | grep gtk
exit 1
fi
}
# Main
if [ "$is_flutter_running" = "true" ]; then
export_flutterflow_code
else
prerequisites_met=true
# Check for FlutterFlow CLI
if command_exists flutterflow; then
echo "FlutterFlow CLI is installed."
else
echo "Error: FlutterFlow CLI is not installed. Please install it from https://pub.dev/packages/flutterflow_cli"
prerequisites_met=false
fi
# Check for Flutter
if command_exists flutter; then
echo "Flutter is installed."
else
echo "Error: Flutter is not installed. Please install Flutter from https://flutter.dev/docs/get-started/install"
prerequisites_met=false
fi
if [ "$prerequisites_met" = true ]; then
export_flutterflow_code
if [ $? -eq 0 ]; then
cd "ff-app/$FLUTTERFLOW_PROJECT" || {
echo "Error: Failed to change directory to ff-app/$FLUTTERFLOW_PROJECT"
exit 1
}
echo "Current directory: $(pwd)"
if [ "$run_mode" = "web" ]; then
echo "Running Flutter project in Chrome web debugger mode..."
flutter run -d chrome --web-browser-flag "--disable-extensions"
elif [ "$run_mode" = "linux" ]; then
# Check and install Linux dependencies
check_and_install_linux_deps
# Add Linux support
echo "Adding Linux desktop support to the project..."
# Create a temporary directory with a valid name
temp_dir=$(mktemp -d)
valid_name=$(echo "$FLUTTERFLOW_PROJECT" | tr '[:upper:]' '[:lower:]' | sed 's/[^a-z0-9_]/_/g')
# Create a new Flutter project with Linux support in the temp directory
flutter create --platforms=linux "$temp_dir/$valid_name"
# Copy the Linux-specific files to our project
cp -r "$temp_dir/$valid_name/linux" .
# Clean up
rm -rf "$temp_dir"
# Update pubspec.yaml to include Linux
sed -i '/platforms:/a\ linux: # Add Linux platform' pubspec.yaml
# Modify CMakeLists.txt to change install directory
sed -i '1a set(CMAKE_INSTALL_PREFIX ${CMAKE_BINARY_DIR}/install CACHE PATH "Installation directory")' linux/CMakeLists.txt
# Build the project
echo "Building the Flutter project..."
flutter build linux
echo "Investigating build output..."
echo "Contents of the current directory:"
ls -R
echo "Searching for executable files:"
find . -type f -executable
echo "Attempting to find and run the built application..."
built_app=$(find . -type f -executable -name "fairgame_flutter_f1zz3x" 2>/dev/null | grep -v "intermediates_do_not_run" | head -n 1)
if [ -n "$built_app" ]; then
echo "Found executable: $built_app"
# Check file permissions
echo "File permissions:"
ls -l "$built_app"
# Check file type
echo "File type:"
file "$built_app"
# Check dynamic dependencies
echo "Dynamic dependencies:"
ldd "$built_app"
echo "Attempting to run the application..."
if [ -x "$built_app" ]; then
"$built_app"
else
echo "Error: The file is not executable. Attempting to make it executable..."
chmod +x "$built_app"
"$built_app"
fi
else
echo "Error: Could not find the built application executable."
exit 1
fi
else
echo "Error: Invalid run mode. Use 'linux' for Linux desktop or 'web' for Chrome web debugger."
exit 1
fi
else
echo "Error: FlutterFlow code export failed."
exit 1
fi
else
echo "Error: Prerequisites not met. Please address the issues above and try again."
exit 1
fi
fi
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment