Linux setup
Arch Linux has a flutter package, but to avoid conflict it’s better to follow the instructions at the flutter docs
To check if the environment is correctly configured run flutter doctor
For development, VSCode is the easiest out of the box solution.
Build for web
You need to have Chrome instaled to execute the flutter run command for the web.
A quick fix to use Chromium instead if to make a symlink.
which chromium
ln -s /path/to/chromium /usr/bin/google-chromeInstall packages
Using the Command Line
Navigate to your project’s root directory in the terminal or command prompt.
Run the following command to add the package:
flutter pub add package_nameThis command will automatically add the package to your pubspec.yaml file and download it.
Manual Installation
Open your pubspec.yaml file.
Add the package under the dependencies section:
dependencies:
flutter:
sdk: flutter
package_name: ^version_numberRun the following command in your terminal to fetch the package:
flutter pub getCLI usage
Initialization
To create a new project
flutter createBuild and Run
For building:
flutter buildFor running:
flutter build
flutter build -d <deviceID>Testing
To run tests:
flutter testTo run analyze code:
flutter analyzeConfig and setup
Configure Flutter settings with:
flutter configManage dependencies using:
flutter pubDevice management
To see a list of all devices
flutter devicesTo install apps on devices:
flutter installTroubleshooting
To check environment setup:
flutter doctorTo vie app logs:
flutter doctorRaspberry Pi
For running on Raspberry Pi as an embedded application there is flutter-pi
flutterpi_tool build --arch=arm --cpu=generic
rsync -a --info=progress2 ./build/flutter_assets/ pi@192.168.68.230:/home/pi/app
flutter-pi app (in pi)
Android app development
To check if the setup is correctly configured you can run flutter doctor
adb may need to be run as root to connect the first time
sudo ~/Android/Sdk/platform-tools/adb reconnect
If a device with usb debugging is connected flutter run will automatically run install and run the app in it.
A tool for Mirror Android on Linux like scrcpy can be useful to run apps on a real machine with the VM feeling.
Fix CMakefile error
If you change the path of the project, by moving or changing the directory name you get the next error:
❯ flutter run
Launching lib/main.dart on Linux in debug mode...
CMake Error: The current CMakeCache.txt directory /home/miguel/dev/hr_merlin/hr_merlin_app/build/linux/x64/debug/CMakeCache.txt is different than the directory /home/miguel/dev/hr-app/hr_merlin_app/build/linux/x64/debug where CMakeCache.txt was created. This may result in binaries being created in the wrong place. If you are not sure, reedit the CMakeCache.txt
CMake Error: The source "/home/miguel/dev/hr_merlin/hr_merlin_app/linux/CMakeLists.txt" does not match the source "/home/miguel/dev/hr-app/hr_merlin_app/linux/CMakeLists.txt" used to generate cache. Re-run cmake with a different source directory.
Building Linux application...
Error: Unable to generate build filesTo fix it just:
flutter clean
flutter create .Project structure
https://codewithandrea.com/articles/flutter-project-structure/
VScode tips
https://codewithandrea.com/articles/vscode-shortcuts-extensions-settings-flutter-development/