Mockito flutter error: Cannot retrieve modification time - flutter

To prepare mockito Mocks for test, my use case:
import 'package:mockito/annotations.dart';
import 'package:.../repositories/random_activity_repository.dart';
#GenerateMocks([RandomActivityRepository])
void main() {}
When I build with: flutter packages pub run build_runner
Something goes wrong, and for every file I have, I get:
FileSystemException(path:...dart, message=Cannot retrieve modification time) [SEVERE]
I am tired of reading the docs (here: https://pub.dev/packages/mockito and here: https://github.com/mockito/mockito) but I cannot find this kind of error.
Can somebody help me UNDERSTAND what's going on?

Related

Can't release app or build web because of this package: blue_thermal_printer: ^1.1.9

When I run this command
flutter run --release
flutter build web --web-renderer html
I get this error in console:
Launching lib\main.dart on Infinix X656 in release mode...
/C:/Users/Bilal%20Saeed/AppData/Local/Pub/Cache/hosted/pub.dartlang.org/blue_thermal_printer-1.1.9/lib/blue_thermal_printer.dart:34:28: Error: Type 'Registrar' not
found.
static void registerWith(Registrar registrar) {
^^^^^^^^^
/C:/Users/Bilal%20Saeed/AppData/Local/Pub/Cache/hosted/pub.dartlang.org/blue_thermal_printer-1.1.9/lib/blue_thermal_printer.dart:34:28: Error: 'Registrar' isn't a
type.
static void registerWith(Registrar registrar) {
^^^^^^^^^
/C:/Users/Bilal%20Saeed/AppData/Local/Pub/Cache/hosted/pub.dartlang.org/blue_thermal_printer-1.1.9/lib/blue_thermal_printer.dart:35:24: Error: Setter not found: 'i
nstance'.
BlueThermalPrinter.instance = BlueThermalPrinter._();
^^^^^^^^
FAILURE: Build failed with an exception.
* Where:
Script 'D:\All Data\Softwares\Latest Flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1005
* What went wrong:
Execution failed for task ':app:compileFlutterBuildRelease'.
> Process 'command 'D:\All Data\Softwares\Latest Flutter\flutter\bin\flutter.bat'' finished with non-zero exit value 1
* 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 3m 57s
Running Gradle task 'assembleRelease'... 240.3s
Exception: Gradle task assembleRelease failed with exit code 1
This file is also automatically generated with errors:
//
// Generated file. Do not edit.
//
// ignore_for_file: directives_ordering
// ignore_for_file: lines_longer_than_80_chars
import 'package:blue_thermal_printer/';
import 'package:cloud_firestore_web/cloud_firestore_web.dart';
import 'package:cloud_functions_web/cloud_functions_web.dart';
import 'package:connectivity_for_web/connectivity_for_web.dart';
import 'package:firebase_analytics_web/firebase_analytics_web.dart';
import 'package:firebase_auth_web/firebase_auth_web.dart';
import 'package:firebase_core_web/firebase_core_web.dart';
import 'package:firebase_messaging_web/firebase_messaging_web.dart';
import 'package:firebase_storage_web/firebase_storage_web.dart';
import 'package:fluttertoast/fluttertoast_web.dart';
import 'package:geolocator_web/geolocator_web.dart';
import 'package:google_maps_flutter_web/google_maps_flutter_web.dart';
import 'package:google_sign_in_web/google_sign_in_web.dart';
import 'package:image_picker_for_web/image_picker_for_web.dart';
import 'package:maps_launcher/maps_launcher_web.dart';
import 'package:shared_preferences_web/shared_preferences_web.dart';
import 'package:url_launcher_web/url_launcher_web.dart';
import 'package:video_player_web/video_player_web.dart';
import 'package:flutter_web_plugins/flutter_web_plugins.dart';
// ignore: public_member_api_docs
void registerPlugins(Registrar registrar) {
BlueThermalPrinterPlugin.registerWith(registrar);
FirebaseFirestoreWeb.registerWith(registrar);
FirebaseFunctionsWeb.registerWith(registrar);
ConnectivityPlugin.registerWith(registrar);
FirebaseAnalyticsWeb.registerWith(registrar);
FirebaseAuthWeb.registerWith(registrar);
FirebaseCoreWeb.registerWith(registrar);
FirebaseMessagingWeb.registerWith(registrar);
FirebaseStorageWeb.registerWith(registrar);
FluttertoastWebPlugin.registerWith(registrar);
GeolocatorPlugin.registerWith(registrar);
GoogleMapsPlugin.registerWith(registrar);
GoogleSignInPlugin.registerWith(registrar);
ImagePickerPlugin.registerWith(registrar);
MapsLauncherWeb.registerWith(registrar);
SharedPreferencesPlugin.registerWith(registrar);
UrlLauncherPlugin.registerWith(registrar);
VideoPlayerPlugin.registerWith(registrar);
registrar.registerMessageHandler();
}
As well I constantly see these errors in dart analysis :
error: Target of URI doesn't exist: 'package:blue_thermal_printer/'. (uri_does_not_exist at [food_delivery_app] lib\generated_plugin_registrant.dart:8)
error: Undefined name 'BlueThermalPrinterPlugin'. (undefined_identifier at [food_delivery_app] lib\generated_plugin_registrant.dart:31)
However in debug mode, the app works fine.
And when I remove bluetooth_thermal_print package, it works fine as well too.
What could be the issue? How can I release my app with this package?
It seems as if this plugin would not be properly installed.
Make sure the pubspec.yaml has the dependency listed:
dependencies:
blue_thermal_printer: ^any
Then you can let fetch it fetch the files:
flutter packages get
While on the other hand, you're creating a web project
and then install a plugin, which possibly is rather for Android, iOS or HarmonyOS. flutter config --no-enable-web would disable the web support, which is a possible (even quite likely) candidate for the cause of that error message.
And even if some libraries may provide this kind of functionality in a web-browser
any kind of ESC/POS might be easier to handle without all the abstraction layers.
You may want to follow issue #103 ...which only confirms my educated guess.
Heads off to the developer of this package. I contacted him personally by going to his portfolio given on pub.dev and told him the situation. He updated the package from bluetooth_thermal_printer 1.1.9 to 1.2.0 in about minutes and it all worked smoothly once again....

How to Handle "Cannot run with sound null safety" error with Visual Studio AppCenter in Flutter APK Build

I'm trying to add AppCenter to my application but I get build error:
Error: Cannot run with sound null safety, because the following
dependencies don't support null safety:
package:appcenter
package:appcenter_analytics
package:appcenter_crashes
For solutions, see https://dart.dev/go/unsound-null-safety
FAILURE: Build failed with an exception.
I added auto-generated code from AppCenter to my ->app/build.gradle
dependencies {
def appCenterSdkVersion = '4.3.1'
implementation "com.microsoft.appcenter:appcenter-analytics:${appCenterSdkVersion}"
implementation "com.microsoft.appcenter:appcenter-crashes:${appCenterSdkVersion}"
}
Spending some hours in pain, I found my solution and post it here
We should not import appcenter, appcenter_analytics appcenter_crashespackage in main.dart (also not import them into pubspec.yaml)
What we should do is, override "onCreate" method in MainActivity.java and implement appcenter there.
You can find more details in my answer.

Allow to run entire folder of tests in flutter new integration tests - just like normal unit tests

I am having a separate integration test file for each screen and I want to run all the integration tests with a single command like “flutter tests”. I looked into the doc but was not able to find any way to do this. This also causes an issue with the firebase test lab apk. To create an android test apk I can only specify a single test file path to create the apk.
// flutter build generates files in android/ for building the app
flutter build apk
./gradlew app:assembleAndroidTest
./gradlew app:assembleDebug -Ptarget=integration_test/whattodo_tests.dart
For now, I found two workarounds for this.
I’ve moved all my tests to a single dart file with a group test.
But this workaround does not scale well. For the 5-10 test it’s working fine. But let say if we have 50-75 test then it will be a mess to navigate and understand tests in single file.
Create a script to run all tests one by one. This might work on our own CI pipeline, but this won't work in the firebase test lab.
Does anyone able to solve this issue or any better solution?
I have came across one project on GitHub has this kind of structure, I think which may help..
Make common file and import different files, folders or modules on that common file for testing
main.dart
import 'package:integration_test/integration_test.dart';
import 'about_us_page_test.dart' as about;
import 'add_label_page_test.dart' as label;
import 'add_project_page_test.dart' as project;
import 'add_task_page_test.dart' as tasks;
import 'completed_tasks_page_test.dart' as tasks_completed;
import 'home_page_test.dart' as home;
import 'whattodo_tests.dart' as whattodo;
void main() {
IntegrationTestWidgetsFlutterBinding.ensureInitialized();
whattodo.main();
home.main();
tasks.main();
tasks_completed.main();
project.main();
label.main();
about.main();
}
to run all these tests
flutter drive \
--driver=test_driver/integration_test_driver.dart \
--target=integration_test/main.dart
There is now a better way of doing it. Just use the test command like this.
To run all test
flutter test integration_test
To run a specific test
flutter test integration_test/app_test.dart
Reference.

Why the app produced by flutter build web sometimes doesn't work?

I have 2 issues that only appear when executing flutter build web.
Sometimes flutter build web fails complaining (wrongly) about types that were not compatible (see below).
Sometimes the build process finishes but then the web app doesn't work: doesn't display anything and there are no messages in the console.
The error I mention is something like this:
% flutter build web
Target dart2js failed: Exception: lib/main.dart:24:31:
Error: A value of type 'ApiUsersRepository' can't be assigned to a variable of type 'UsersRepository'.
- 'ApiUsersRepository' is from 'package:my_app/api_users_repo.dart' ('lib/api_users_repo.dart').
- 'UsersRepository' is from 'lib/users_repo.dart'.
final UsersRepository usersRepository = ApiUsersRepository();
^
Error: Compilation failed.
The app is working in iOS and web when developing.
The solution
I changed all imports of my files like:
import 'package:my_app/users_repo.dart';
To:
import 'users_repo.dart';
More Details
Investigating the error about types, I found this issue, where the important part is this comment: after changing every import to relative format it resolves my problem.
So I did that, and it solved the 2 issues, the compilation error, and the runtime error.
for me I had to remove a package that was corrupted. c:\src\flutter.pub-cache\hosted\pub.dartlang.org\localstorage-4.0.0+1 Apparently, a file had become corrupted by me invertly. I removed the package and did a flutter pub get then recompiled and it worked.

Migrating to Dart 2 I get a "check imports error" that means that some templates have not been generated

I'm trying to migrate to Dart 2, I have a lot of packages and up to now I could do my job with not so much problems.
Now I'm getting a strange error bot with DDC and dart2js:
[SEVERE] build_web_compilers|entrypoint on web/main.dart (cached):
Unable to find modules for some sources, this is usually the result of either a
bad import, a missing dependency in a package (or possibly a dev_dependency
needs to move to a real dependency), or a build failure (if importing a
generated file).
Please check the following imports:
`import 'package:ledger_web/src/ui/components/main_selection_bar.template.dart';` from ledger_web|lib/src/ui/components/service/main_selection_bar_service.dart at 7:1
`import 'package:ledger_web/src/ui/components/main_selection_bar.template.dart';` from ledger_web|lib/src/ui/components/service/main_selection_bar_service.template.dart at 11:1
... and more
It is correct to signal that there is not the import (MainSelectionBar is an angular component), because the template has not been generated.
Now the problem is, why the template is not there?
I checked the .dart_tool/build/generated directory but the template has not been created.
I have a similar package with a similar component that works fine, so I cannot figure out what's happened.
Is there a place where there is a more detailed error list?
Interestingly enough, there is also a case in which the template exists, but it is listed like if it was not found....
Any hint?
Most likely this is related to a build failure when generating the template, which is not being properly reported on subsequent builds. This pull request should help that https://github.com/dart-lang/build/pull/1834/, but you can also try running pub run build_runner clean and then doing a new build to get the original error back.