A server backend to support DartPad.
This project is a small, stateless Dart server, which powers the front-end of DartPad. It provides many of DartPad's features, including static analysis (errors and warnings), compilation to JavaScript, code completion, dartdoc information, code formatting, and quick fixes for issues.
The Flutter SDK needs to be downloaded and setup; check out https://flutter.dev/get-started.
To run the server, run:
dart bin/server.dartThe server will run from port 8080 and export several JSON APIs, like
/api/v3/analyze and /api/v3/compile.
To test code generation features locally:
-
Get needed API keys:
- Get a GEMINI_API_KEY key from Google AI Studio
-
Set the needed environment variables before running:
export GEMINI_API_KEY=<YOUR_GEMINI_API_KEY> dart bin/server.dart
To run tests:
dart test
Dart services pre-compiles .dill files for the Dart SDK and Flutter Web SDK, which
are uploaded to Cloud Storage automatically. These files are located in the
artifacts/ directory.
If you need to re-generate these files, run the following command.
dart tool/grind.dart build-storage-artifacts
Package dependencies are pinned using the tool/dependencies/pub_dependencies_<CHANNEL>.yaml
files. To make changes to the list of supported packages, you need to verify
that the dependencies resolve and update these pinned versions.
Complete the following steps using each Flutter channel (main, beta and stable):
-
Switch to the desired Flutter channel:
flutter channel <CHANNEL> -
(Optional) If you are adding or removing a package, first edit the
lib/src/project_templates.dartfile, which contains the whitelisted list of packages. -
Create the Dart and Flutter projects in the
project_templates/directory/.dart tool/grind.dart build-project-templates
If this command fails because it can't resolve packages, read the package failure, and edit the
tool/dependencies/pub_dependencies_<CHANNEL>.yamlfile to use the correct package version. -
Once the
project_templates/dart_projectandproject_templates/flutter_projectdirectories are created, runpub upgradein each directory. -
Run
dart tool/grind.dart update-pub-dependenciesto overwrite thetool/dependencies/pub_dependencies_<CHANNEL>.yamlfile for your current channel. This will ensure all packages are pinned to the correct version.
You can install and run a local redis cache. Run sudo apt-get install redis-server to install on Ubuntu or brew install redis for macOS.
See the Redis' Quick Start guide for other platforms.
To configure the server to use the local redis cache, run dart bin/server.dart with the redis-url flag.
Please report issues at https://github.com/dart-lang/dart-pad/issues.
Contributions welcome! Please read this short guide first. You can view our license here.