From 74f04f7b8890bfc5f88ddcbfe8683a51946c6810 Mon Sep 17 00:00:00 2001 From: Jeff Scaturro <53348890+jeffs-sf@users.noreply.github.com> Date: Fri, 12 Feb 2021 12:03:26 -0500 Subject: [PATCH] feat: add flutter wrapper to project --- .gitmodules | 4 ++ .vscode/launch.json | 12 +++++ .vscode/settings.json | 3 ++ README.md | 51 ++++++++++++++++++-- app/.flutter | 1 + app/flutterw | 108 ++++++++++++++++++++++++++++++++++++++++++ 6 files changed, 176 insertions(+), 3 deletions(-) create mode 100644 .gitmodules create mode 100644 .vscode/launch.json create mode 100644 .vscode/settings.json create mode 160000 app/.flutter create mode 100755 app/flutterw diff --git a/.gitmodules b/.gitmodules new file mode 100644 index 00000000..ed435765 --- /dev/null +++ b/.gitmodules @@ -0,0 +1,4 @@ +[submodule "app/.flutter"] + path = app/.flutter + url = https://github.com/flutter/flutter.git + branch = stable diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..663e4dc9 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,12 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [{ + "name": "app", + "cwd": "app", + "request": "launch", + "type": "dart" + }] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..66011e4e --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "dart.flutterSdkPath": "app/.flutter", +} \ No newline at end of file diff --git a/README.md b/README.md index ea26149d..f5ebeaaa 100644 --- a/README.md +++ b/README.md @@ -2,6 +2,51 @@ Be sure to read **all** of this document carefully, and follow the guidelines within. +## Vendorized Flutter + +We are on a fixed Flutter release, similar to how gradle does this with a wrapper. More information on the approach can be found here: + +> https://github.com/passsy/flutter_wrapper + +_Be sure to use the `flutterw` wrapper while working on this repo._ + +From the `app` directory _(currently)_: + +- `./flutterw channel {x}` to switch the Flutter channel. +- `./flutterw upgrade` to upgrade the version of Flutter. +- `./flutterw run -d {device_id}` to run the app. + +### IDE Setup + +
+Use with VSCode +

+ +If you're a VScode user link the new Flutter SDK path in your settings +`$projectRoot/.vscode/settings.json` (create if it doesn't exists yet) + +```json +{ + "dart.flutterSdkPath": ".flutter" +} +``` + +Commit this file to your git repo and your coworkers will automatically use `flutterw` from now on + +

+
+ +
+Use with IntelliJ / Android Studio +

+ +Go to `Preferences > Languages & Frameworks > Flutter` and set the Flutter SDK path to `$projectRoot/.flutter` + +IntelliJ Settings + +

+
+ ## Requirements ### App Structure @@ -51,7 +96,7 @@ Feel free to add more tests as you see fit but the above is the minimum requirem ## Design - See this [Figma File](https://www.figma.com/file/UOQDbU02GG2yaJMfrO9q9d/Flutter-Test?node-id=0%3A1) for design specifics like -fonts, themes, colors, etc. + fonts, themes, colors, etc. ![List View](screenshots/listview.png) ![Detail View](screenshots/detailview.png) @@ -79,7 +124,7 @@ Please restrict your usage of state or dependency injection to the following opt 4. [get_it](https://pub.dev/packages/get_it)/[get_it_mixins](https://pub.dev/packages/get_it_mixin) 5. [Mobx](https://pub.dev/packages/mobx) -We ask this because this challenge values consistency and efficiency over ingenuity. Using commonly used libraries ensures that we can review your code in a timely manner and allows us to provide better feedback. +We ask this because this challenge values consistency and efficiency over ingenuity. Using commonly used libraries ensures that we can review your code in a timely manner and allows us to provide better feedback. ## Coding Values @@ -111,7 +156,7 @@ While the purpose of this challenge is not to guage whether you can achieve 100% If you are feeling up to it and want to add some more functionality to the application try some of these bonus items - Implement persistance storage for favorited restaurants -- Implement the *Bonus Detail Screen* +- Implement the _Bonus Detail Screen_ - Implement a basic CI job that runs your tests and builds the app ## Q&A diff --git a/app/.flutter b/app/.flutter new file mode 160000 index 00000000..9b2d32b6 --- /dev/null +++ b/app/.flutter @@ -0,0 +1 @@ +Subproject commit 9b2d32b605630f28625709ebd9d78ab3016b2bf6 diff --git a/app/flutterw b/app/flutterw new file mode 100755 index 00000000..65d5c3be --- /dev/null +++ b/app/flutterw @@ -0,0 +1,108 @@ +#!/usr/bin/env sh + +############################################################################## +## +## Flutter start up script for UN*X +## Version: v1.1.2 +## Date: 2021-02-12 10:12:44 +## +## Use this flutter wrapper to bundle Flutter within your project to make +## sure everybody builds with the same version. +## +## Read about the install and uninstall process in the README on GitHub +## https://github.com/passsy/flutter_wrapper +## +## Inspired by gradle-wrapper. +## +############################################################################## + +# Attempt to set APP_HOME +# Resolve links: $0 may be a link +PRG="$0" +# Need this for relative symlinks. +while [ -h "$PRG" ]; do + ls=$(ls -ld "$PRG") + link=$(expr "$ls" : '.*-> \(.*\)$') + if expr "$link" : '/.*' >/dev/null; then + PRG="$link" + else + PRG=$(dirname "$PRG")"/$link" + fi +done +SAVED="$(pwd)" +cd "$(dirname "$PRG")/" >/dev/null +APP_HOME="$(pwd -P)" +cd "$SAVED" >/dev/null + +FLUTTER_SUBMODULE_NAME='.flutter' +FLUTTER_DIR="$APP_HOME/$FLUTTER_SUBMODULE_NAME" + +# by default we should be in the correct project dir, but when run from Finder on Mac, the cwd is wrong +if [ "$(uname)" = "Darwin" ] && [ "$HOME" = "$PWD" ]; then + cd "$(dirname "$0")" +fi + +# submodule starting with "-" are not initialized +init_status=$(git submodule | grep "\ $FLUTTER_SUBMODULE_NAME$" | cut -c 1) + +# Fix not initialized flutter submodule +if [ "$init_status" = "-" ]; then + echo "$FLUTTER_SUBMODULE_NAME submodule not initialized. Initializing..." + git submodule update --init ${FLUTTER_SUBMODULE_NAME} +fi + +# Detect detach HEAD and fix it. commands like upgrade expect a valid branch, not a detached HEAD +FLUTTER_SYMBOLIC_REF=$(git -C ${FLUTTER_SUBMODULE_NAME} symbolic-ref -q HEAD) +if [ -z ${FLUTTER_SYMBOLIC_REF} ]; then + FLUTTER_REV=$(git -C ${FLUTTER_SUBMODULE_NAME} rev-parse HEAD) + FLUTTER_CHANNEL=$(git config -f .gitmodules submodule.${FLUTTER_SUBMODULE_NAME}.branch) + + if [ -z $FLUTTER_CHANNEL ]; then + echo "Warning: Submodule '$FLUTTER_SUBMODULE_NAME' doesn't point to an official Flutter channel \ + (one of stable|beta|dev|master). './flutterw upgrade' will fail without a channel." + echo "Fix this by adding a specific channel with:" + echo "\t- './flutterw channel ' or" + echo "\t- Add 'branch = ' to '$FLUTTER_SUBMODULE_NAME' submodule in .gitmodules" + else + echo "Fixing detached HEAD: '$FLUTTER_SUBMODULE_NAME' submodule points to a specific commit $FLUTTER_REV, not channel '$FLUTTER_CHANNEL' (as defined in .gitmodules)." + # Make sure channel is fetched + # Remove old channel branch because it might be moved to an unrelated commit where fast-forward pull isn't possible + git -C ${FLUTTER_SUBMODULE_NAME} branch -q -D ${FLUTTER_CHANNEL} 2> /dev/null || true + git -C ${FLUTTER_SUBMODULE_NAME} fetch -q origin + + # bind current HEAD to channel defined in .gitmodules + git -C ${FLUTTER_SUBMODULE_NAME} checkout -q -b ${FLUTTER_CHANNEL} ${FLUTTER_REV} + git -C ${FLUTTER_SUBMODULE_NAME} branch -q -u origin/${FLUTTER_CHANNEL} ${FLUTTER_CHANNEL} + echo "Fixed! Migrated to channel '$FLUTTER_CHANNEL' while staying at commit $FLUTTER_REV. './flutterw upgrade' now works without problems!" + git -C ${FLUTTER_SUBMODULE_NAME} status -bs + fi +fi + +# Wrapper tasks done, call flutter binay with all args +set -e +"$FLUTTER_DIR/bin/flutter" "$@" + +# Post flutterw tasks. exit code from /bin/flutterw will be used as final exit +FLUTTER_EXIT_STATUS=$? +if [ ${FLUTTER_EXIT_STATUS} -eq 0 ]; then + + # ./flutterw channel CHANNEL + if echo "$@" | grep -q "channel"; then + # make sure .gitmodules is updated as well + CHANNEL=${2} # second arg + git config -f .gitmodules submodule.${FLUTTER_SUBMODULE_NAME}.branch ${CHANNEL} + # makes sure nobody forgets to do commit all changed files + git add .gitmodules + git add ${FLUTTER_SUBMODULE_NAME} + fi + + # ./flutterw upgrade + if echo "$@" | grep -q "upgrade"; then + # makes sure nobody forgets to do commit the changed submodule + git add ${FLUTTER_SUBMODULE_NAME} + # flutter packages get runs automatically. Stage those changes as well + git add pubspec.lock + fi +fi + +exit ${FLUTTER_EXIT_STATUS}