TDD in Flutter/Dart. How to reduce start up time - unit-testing

I try to do Test-Driven Development (TDD) in Dart for the business logic of apps with Flutter. The startup time for running the test feels a little bit slow for fast TDD cycles. It is around 4-5 seconds on my machine.
I am using the package:test/test.dart, so there is no need to deploy the app onto the device and the tests can run locally on the Dart VM. The tests themselves run fast.
While developing Android native apps with Java's JUnit and the local Java VM the startup time was much faster < 1sec.
Is there a way to get the start-up time for unit testing in Dart that fast too? (Without buying a much faster physical machine).
Edit:
My Dart versions:
Flutter doctor -v: 2.0.0-dev.54.0.flutter-46ab040e58
The Dart Plugin uses:
2.0.0-edge.c080951d45e79cd25df98036c4be835b284a269c and is in my flutter installation: C:\flutter\bin\cache\dart-sdk
The Dart tests are inside a Flutter project. I start the Dart tests in Android Studio via right-clicking a file with a test or just use the ">" run test buttons in the IDE. Android Studio then generates a run config, so I can start it with keyboard shortcuts fast.

I've tried running a sample test (using the Flutter demo app) recently, running flutter test through the terminal initializes the test in an instant.
However, I got similar startup time (around 4 seconds) when the tests were run through the UI.
I tried digging into the settings and there doesn't seem to be any config that we can modify to make the tests initialize faster compared to what we have at present.
Here's my flutter doctor for reference.
[✓] Flutter (Channel master, 1.26.0-2.0.pre.281, on macOS 11.1 20C69 darwin-x64)
• Flutter version 1.26.0-2.0.pre.281
• Framework revision 4d5db88998 (2 weeks ago), 2021-01-11 10:29:26 -0800
• Engine revision d5cacaa3a6
• Dart version 2.12.0 (build 2.12.0-211.0.dev)
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Platform android-30, build-tools 29.0.2
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 12.0.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.0.1, Build version 12A7300
• CocoaPods version 1.10.0
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 4.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
🔨 https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b3-6915495)
[✓] VS Code (version 1.52.1)
• VS Code at /Applications/Visual Studio Code.app/Contents
• Flutter extension version 3.18.1
[✓] Connected device (1 available)
• Chrome (web) • chrome • web-javascript • Google Chrome 88.0.4324.96
• No issues found!

This method works perfectly for me:
1. flutter run --profile --cache-sksl
2. Press M at the command line of flutter run to write the captured SkSL shaders into a file named something like flutter_01.sksl.json.
3. Build the app with SkSL warm-up using the following, as appropriate:
Android:
flutter build apk --bundle-sksl-path flutter_01.sksl.json
or
flutter build appbundle --bundle-sksl-path flutter_01.sksl.json
iOS:
flutter build ios --bundle-sksl-path flutter_01.sksl.json
For more information, visit: https://flutter.dev/docs/perf/rendering/shader

Related

'Execution failed for task ':amplify_core:compileDebugKotlin' ' error message in Flutter

My Windows updated and my app wouldn't run because I had to update a few things and managed to sort the issues that arose out. My app stopped compiling again and turns out I had to redownload flutter and it started compiling again. And now it's back to not compiling, this error, however, has become difficult for me to solve.
This is the error I get when I try to compile my app.
Launching lib\main.dart on AOSP on IA Emulator in debug mode...
Running Gradle task 'assembleDebug'...
e: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\amplify_core-0.2.10\android\src\main\kotlin\com\amazonaws\amplify\amplify_core\AtomicResult.kt: (26, 1): Class 'AtomicResult' is not abstract and does not implement abstract member public abstract fun error(p0: String, p1: String?, p2: Any?): Unit defined in io.flutter.plugin.common.MethodChannel.Result
e: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\amplify_core-0.2.10\android\src\main\kotlin\com\amazonaws\amplify\amplify_core\AtomicResult.kt: (54, 5): 'error' overrides nothing
e: C:\src\flutter\.pub-cache\hosted\pub.dartlang.org\amplify_core-0.2.10\android\src\main\kotlin\com\amazonaws\amplify\amplify_core\AtomicResult.kt: (66, 26): Type mismatch: inferred type is String? but String was expected
FAILURE: Build failed with an exception.
* What went wrong:
Execution failed for task ':amplify_core:compileDebugKotlin'.
> A failure occurred while executing org.jetbrains.kotlin.compilerRunner.GradleCompilerRunnerWithWorkers$GradleKotlinCompilerWorkAction
> Compilation error. See log for more details
* Try:
> Run with --stacktrace option to get the stack trace.
> Run with --info or --debug option to get more log output.
> Run with --scan to get full insights.
* Get more help at https://help.gradle.org
BUILD FAILED in 3s
Exception: Gradle task assembleDebug failed with exit code 1
I tried migrating code to AndroidX, upgrading flutter, flutter channel is stable. I need help.
Below is the result of flutter doctor.
[√] Flutter (Channel stable, 3.0.5, on Microsoft Windows [Version 10.0.19044.1889])
• Flutter version 3.0.5 at C:\source\flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision f1875d570e (5 weeks ago), 2022-07-13 11:24:16 -0700
• Engine revision e85ea0e79c
• Dart version 2.17.6
• DevTools version 2.12.2
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
• Android SDK at C:\Users\AppData\Local\Android\sdk
• Platform android-33, build-tools 33.0.0
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
• All Android licenses accepted.
[√] Chrome - develop for the web
• Chrome at C:\Program Files (x86)\Google\Chrome\Application\chrome.exe
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.3.0)
• Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Community
• Visual Studio Community 2022 version 17.3.32804.467
• Windows 10 SDK version 10.0.19041.0
[√] Android Studio (version 2021.2)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin can be installed from:
https://plugins.jetbrains.com/plugin/9212-flutter
• Dart plugin can be installed from:
https://plugins.jetbrains.com/plugin/6351-dart
• Java version OpenJDK Runtime Environment (build 11.0.12+7-b1504.28-7817840)
[√] Connected device (4 available)
• AOSP on IA Emulator (mobile) • emulator-5554 • android-x86 • Android 9 (API 28) (emulator)
• Windows (desktop) • windows • windows-x64 • Microsoft Windows [Version 10.0.19044.1889]
• Chrome (web) • chrome • web-javascript • Google Chrome 104.0.5112.81
• Edge (web) • edge • web-javascript • Microsoft Edge 104.0.1293.54
[√] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!
C:\Users>flutter channel
Flutter channels:
master
beta
* stable
In your project folder, look for the build.gradle file at the root of your Android directory and upgrade to the latest version of Kotlin. For the moment the version is at 1.7.10, so go to the Kotlin website and check the last version released. In the file it will look like this:
ext.kotlin_version = '1.7.10

Dart 2.3 ignores breakpoints

I am developing a web app in Dart using Webstorm as IDE. After upgrading from Dart SDK 2.2 to Dart SDK 2.3 I noticed that all breakpoints I set in Webstorm are ignored (although the app seems to run properly in Chrome) That breakpoints are correctly marked as a "red circle" but unlike the previous SDK they miss the "tick" inside (which I think means they are not recognized by Chrome).
I tried to "repair cache" and "upgrade dependencies" but breakpoints still don't work.
That's the pubspec.yaml dev_dependencies:
dev_dependencies:
build_runner: ^1.4.0
build_test: ^0.10.7+3
build_web_compilers: ^2.1.0
Here is the "webdev serve" command:
/dart/2.3.1/dart-sdk/bin/pub global run webdev serve web:53321
Here is the "webdev serve" command result:
[INFO] Serving `web` on http://localhost:53321
[INFO] Running build completed, took 351ms
[INFO] Caching finalized dependency graph completed, took 177ms
[INFO] Succeeded after 536ms with 0 outputs (0 actions)
Here the versions of envolved softwares:
- O.S.: macOS High Sierra 10.13.6
- Chrome: 74.0.3729.169
- Webstorm: 2019.1 - Build 191.7141.49
- Dart SDK: 2.3.1
- Dart webdev: 2.0.5
I'm trying to figure out if the issue is related to Webstorm, Dart SDK or Chrome. I don't exclude that I miss some new configuration due to the Dart SDK upgrade. Downgrading back to Dart SDK 2.2 everything works fine. Thank you for your hints.
Reproduced, logged as WEB-39095. Please follow it for updates
The bug was in webdev 2.0.0 - 2.0.6. It is fixed in webdev 2.0.7. You may run pub global activate webdev to get the latest version. You might need to close/open the project in the IDE to get it working.

Unable to run Dart2 w/ Angular for web along side Flutter for mobile project - plan to share code

I have made good progress with Flutter on mobile apps. Currently using:
[✓] Flutter (Channel master, v0.3.1-pre.13, on Mac OS X 10.13.4 17E199, locale en-US)
• Flutter version 0.3.1-pre.13 at /Users/golftocs/PhpstormProjects/flutter
• Framework revision 85be28d36b (32 hours ago), 2018-04-16 14:02:07 -0700
• Engine revision 76cb311d9c
• Dart version 2.0.0-dev.47.0.flutter-f76dad0adc
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.1)
• Android SDK at /Users/golftocs/Library/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-27, build-tools 27.0.1
• ANDROID_HOME = /Users/golftocs/Library/Android/sdk
• Java binary at: /Applications/Android Studio.app/Contents/jre/jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
• All Android licenses accepted.
[✓] iOS toolchain - develop for iOS devices (Xcode 9.3)
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 9.3, Build version 9E145
• ios-deploy 1.9.2
• CocoaPods version 1.5.0
[✓] Android Studio (version 3.1)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 23.1.2
• Dart plugin version 173.4700
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1024-b01)
[!] Connected devices
! No devices available
Now I want to begin a project that uses this Flutter set-up for mobile and share code with a Dart2/Angular web app. I am unable to get a web app working successfully. I've cloned https://github.com/angular-examples/toh-5 and based on running 'pub get' this is returned:
Overriding the upper bound Dart SDK constraint to <=2.0.0-
edge.0d5cf900b021bf5c9fa593ffa12b15bcd1cc5fe0 for the following packages:
archive, args, barback, bazel_worker, boolean_selector, build_barback,
build_config, build_modules, charcode, cli_util, code_transformers,
convert, crypto, csslib, dart_style, fixnum, front_end, glob, graphs,
html, http, http_multi_server, http_parser, intl, io, isolate, js,
json_annotation, kernel, logging, matcher, meta, multi_server_socket,
node_preamble, package_config, package_resolver, path, plugin, pool,
protobuf, pub_semver, quiver, quiver_hashcode, shelf,
shelf_packages_handler, shelf_static, shelf_web_socket,
source_map_stack_trace, source_maps, source_span, stack_trace,
stream_channel, string_scanner, term_glyph, test, tuple, typed_data, yaml
Then, when I run 'pub run build_runner serve' from my terminal I get:
[INFO] Generating build script completed, took 446ms
[INFO] Setting up file watchers completed, took 25ms
[INFO] Waiting for all file watchers to be ready completed, took 199ms
[INFO] Building new asset graph completed, took 921ms
[INFO] Checking for unexpected pre-existing outputs. completed, took 2ms
[SEVERE] build_web_compilers|ddc on package:angular_router/src/url.module:
ProcessException: No such file or directory
Command: /Users/golftocs/PhpstormProjects/flutter/bin/cache/dart-sdk/bin/dartdevc --persistent_worker
[WARNING] build_web_compilers|entrypoint on web/main.dart:
Unable to read angular_router|lib/src/url.ddc.js, check your console or the `.dart_tool/build/generated/angular_router/lib/src/url.ddc.js.errors` log file.
[SEVERE] build_web_compilers|ddc on package:angular_router/src/location/platform_location.module:
ProcessException: No such file or directory
Command: /Users/golftocs/PhpstormProjects/flutter/bin/cache/dart-sdk/bin/dartdevc --persistent_worker
[WARNING] build_web_compilers|entrypoint on web/main.dart:
Unable to read angular_router|lib/src/location/platform_location.ddc.js, check your console or the `.dart_tool/build/generated/angular_router/lib/src/location/platform_location.ddc.js.errors` log file.
...
Additionally, I am using WebStorm, actually PHPStorm, and the Pub actions links to 'Get Dependencies, Upgrade...' do not work. I can only execute from terminal.
My desire is to get to:
1) share code between mobile & web similar to https://github.com/apptreesoftware/letsvote/blob/master/README.md
2) run latest Dart2 with Angular5.0.0-alpha and current Flutter master channel
3) WebStorm IDE work seamlessly with either from a combined project
Thanks.
shared_code
|- flutter_project
|- angular_project
where both flutter_project and angular_project have shared-code as a dependency in pubspec.yaml
dependencies:
shared_code:
path: ../shared_code
assuming a directory structure like
my_project/shared_code
my_project/flutter_project
my_project/angular_project
The code in shared_code must not depend in any way on dart:io or flutter:ui otherwise it won't work with either flutter_project or angular_project
If you want to open all 3 at the same time in IntelliJ in the same window, adding them all as module to a single project worked for me.
When I work on the Angular project I need to switch the Dart SDK in the Dart plugin to the Dart SDK, when I work on the Flutter project to the Flutter Dart SDK, otherwise running the app and tests doesn't work.
You can also open each project in its own IntelliJ window which keeps the setting for each window individually and doesn't need to switch depending on what code you're currently working.

Automatically associate Flutter SDK with project in WebStorm

Is there a way to configure WebStorm to automatically associate the Flutter SDK path with an imported project?
I've found out that if I clone a project from GitHub and open it in WebStorm, it doesn't associate with the SDK, rather it says "No Flutter SDK configure". To resolve this, I will have to go to File > Settings > Languages & Frameworks > Flutter to manually specify the path to the SDK for the current project. However, this is not the case with a project started from scratch where Flutter is chosen from the beginning.
Flutter doctor seems to indicate I've installed the SDK. It is not a particularly big problem but it just adds an extra step that is annoying.
[✓] Flutter (on Linux, channel master)
• Flutter at /home/driftavalii/workspace/flutter
• Framework revision c5cf8e0190 (4 days ago), 2017-05-13 11:11:58 -0700
• Engine revision f1bfdddfc8
• Tools Dart version 1.23.0-dev.11.11
[✓] Android toolchain - develop for Android devices (Android SDK 25.0.3)
• Android SDK at /home/driftavalii/Android/Sdk
• Platform android-25, build-tools 25.0.3
• ANDROID_HOME = /home/driftavalii/Android/Sdk
• Java binary at: /usr/local/android-studio/jre/bin/java
• Java version: OpenJDK Runtime Environment (build 1.8.0_112-release-b06)
[✓] Android Studio (version 2.3)
• Android Studio at /usr/local/android-studio
• Gradle version 3.2
• Java version: OpenJDK Runtime Environment (build 1.8.0_112-release-b06)
[✓] IntelliJ IDEA Community Edition (version 2017.1)
• Dart plugin version 171.4424
• Flutter plugin version 13.0
[✓] WebStorm (version 2017.1)
• Flutter plugin version 13.1
[✓] Connected devices
• None
This is likely a bug with our WebStorm support in the flutter plugin. Can you file an issue at https://github.com/flutter/flutter-intellij/issues? Thanks!

Running Sencha Touch app on Java Eclipse & Android Emulator on Windows 8 (without phonegap)

I am getting trouble in running sencha touch 2 app on android emulator (without using cordova/phonegap) on windows 8 using .
Below is the list of packages installed on DEV machine:
1. JRE v1.7
2. Sencha Touch v2.4.1 SDK
3. Sencha SDK Tools 2.0.0 beta
4. Sencha Cmd 5.1.2
5. Ruby 2.0.0
6. Chrome (Browser)
7. Web Server - Both IIS 8 & XAMPP
8. Android SDK 23.0.6
9. Eclipse IDE (integrated with VJET Library & ExtJSTL 4.2)
10. Android ADT Manager (installed emulator snapshots targeting os2.2 & 5.1)
"MyApp" project runs perfectly on chrome browser when hosted on IIS 8 & XAMPP (apache). But not able to figure out steps to run the same on android emulator. So far followed below mentioned steps, leading to unsuccessful attempts:
sencha app build native [Command Successful]
sencha app build -run native [Command Successful]
sencha app build package [Command Successful]
Started emulator instance from eclipse (avd) and executed command sencha app build -run native, but the app doesn't execute on emulator instance.
Followed steps mentioned in post (http://www.sencha.com/forum/showthread.php?215210-how-to-run-sencha-touch-app-on-android-emulator-on-windows) but still facing issues.
Please help!!
do u want to run it as website for mobile?
as u are saying, you don't want to use cordoav/phonegap.
If u just want to run on Mobile Browser U can use Netbeans. It has a very simple feature to allow a html5 application to be run on Mobile browser
all U have to do is
1. Create HTML5 Project in netbeans
2. Run command "sencha app build native"
3. copy all files & folders form directory cordova->www which exist in your sencha app directory
4. Paste it into your HTML5 Project directory
5. Choose The Browser option in netbeans and run
Thanks Nitish for your suggestions. But this is not what my query was all about. I was trying to figure out a way of running sencha touch app on emulator without compiling it to native app following steps mentioned in post: http://www.sencha.com/forum/showthread.php?215210-how-to-run-sencha-touch-app-on-android-emulator-on-windows.
Anyways, to run sencha touch app on emulator I had to create native android app using cordova/phonegap wrapper. To run sencha touch app (which is mobile web portal equivalent), it is required to be wrapped inside native app (android, ios, etc) followed by app signing and APK / IPA file generation.