seanh1986 / flutter-bbtm

MIT License
0 stars 0 forks source link

BB Tournament Manager

BB Tournament Manager is a web app for managing BB tournaments. In includes the following key features.

Admin

Participant

Setup Guide

This guide will walk you through setting up the necessary tools and environment to run this project. We'll be using Homebrew, Node Version Manager (NVM), and Flutter Version Manager (FVM).

Prerequisites

Step 1: Install Homebrew

Homebrew is a package manager for macOS. If you don't have it installed, run this command in your terminal:

/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

After installation, follow the instructions in the terminal to add Homebrew to your PATH.

Step 2: Install NVM (Node Version Manager)

NVM allows you to install and manage multiple versions of Node.js. Install it using Homebrew:

brew install nvm

And follow the provided steps to update and re-source your profile.

Step 3: Install Node.js

Install the Node.js version required for this project:

nvm use

Step 4: Install FVM (Flutter Version Manager)

FVM helps manage Flutter SDK versions.

brew install fvm

And follow the provided steps to update and re-source your profile.

Step 4b: Automatically select the correct Node.js and Flutter versions when changing working directory

See below (optional but useful)

Step 5: Install Flutter & Dart

Install the Flutter and Dart version required for this project:

fvm use

Step 6: Install Project Dependencies

Install Node.js dependencies:

npm install

Install Flutter dependencies:

fvm flutter pub get

Step 7: Run the Project

To run the Flutter part of your project:

fvm flutter run

To run any Node.js scripts:

npm run [script-name]

Additional Notes

Automatically select the correct Node.js and Flutter versions when changing working directory

Currently examples are specific to zsh terminal

NVM

Use the zsh-nvm plugin e.g. with zinit:

# Load zsh-nvm plugin
export NVM_AUTO_USE=true
zinit ice wait lucid
zinit light lukechilds/zsh-nvm

FVM

Copy this script to a file .zsh_fvm_auto_use.zsh and source it from within your .zshrc

# Function to auto-switch Flutter version using FVM
fvm_auto_use() {
  if [[ -x "$(command -v fvm)" ]]; then
    echo "Warning: FVM is not installed or not in PATH. Please install FVM to enable auto-use."
    return 1
  fi

  local fvmrc_file=".fvmrc"
  local fvm_release_file=".fvm/release"

  if [[ -f "$fvmrc_file" ]]; then
    local npmrc_version=$(grep '"flutter":' "$fvmrc_file" | sed 's/.*"flutter": *"\(.*\)".*/\1/')

    if [[ -n "$npmrc_version" ]]; then
      echo "Found $fvmrc_file with version <$npmrc_version>"

      if [[ ! -f "$fvm_release_file" || $(cat "$fvm_release_file") != "$npmrc_version" ]]; then
        echo "Switching Flutter version to $npmrc_version"
        fvm use "$npmrc_version"
      fi
      echo "Now using Flutter version $npmrc_version."
    fi
  fi
}

# Add the function to the chpwd hook (called when changing directories)
autoload -U add-zsh-hook
add-zsh-hook chpwd fvm_auto_use

# Run the function on shell startup
fvm_auto_use

Development vs. Production

Two Google Firebase projects are setup for production and development respesctively.

Production Firebase projectId: bbtournaments-eaa1e Development Firebase projectId: bbtm-dev

When running locally in debug mode (e.g., using VSCode), the project contains two configurations in the launch.json file, one for bbtm - prod and one for bbtm - dev. These can be selected and run locally.

When building, the flutter web project can be built for production or development environments, as outlined below, by specifying the dart-define. Note that the default ENV is prod.

flutter build web --dart-define=ENV=dev
flutter build web --dart-define=ENV=prod

To view the currently selected Firebase project, you can use firebase projects:list. Scripts were added to the package.json file so that we can easily, and clearly, run flutter builds (using above dart-define) and firebase deploy to the correct environment.

npm run deploy:prod
npm run deploy:dev

Note: if you are running into issues (e.g., “path” argument must be of type string. Received undefined), try clearing the firebase hosting cache and re-building, as follows (e.g., in bash):

rm -rf .firebase
flutter clean
flutter build web --dart-define=ENV=dev
firebase deploy