I've inherited a Dart project that has been dormant for about 3 years. When trying to compile the project I get an error from the meta package. I am unsure how to resolve it.
The error is:
[Error from Dart2JS on askbayoucom|web/main.dart]:
web\packages\meta\meta.dart:50:36:
Not a compile-time constant.
const _AlwaysThrows alwaysThrows = _AlwaysThrows();
^^^^^^^^^^^^^^^
I'm using SDK 1.24.3 which I believe is the most recent allowable due to this entry in pubspec.yaml
environment:
sdk: '>=1.0.0 <2.0.0'
When running pub upgrade I get the output:
Resolving dependencies...
args 1.5.1 (1.6.0 available)
async 1.13.3 (2.4.2 available)
barback 0.15.2+15 (0.15.2+16 available)
browser 0.10.0+3
charcode 1.1.2 (1.1.3 available)
collection 1.14.6 (1.14.13 available)
csslib 0.14.3 (0.16.2 available)
dart_config 0.5.0
dart_to_js_script_rewriter 1.0.3
html 0.13.3 (0.14.0+3 available)
js 0.6.1+1 (0.6.2 available)
logging 0.11.3+2 (0.11.4 available)
meta 1.2.2 (1.3.0-nullsafety.2 available)
path 1.5.1 (1.7.0 available)
pool 1.3.4 (1.4.0 available)
source_span 1.5.5 (1.7.0 available)
stack_trace 1.9.3 (1.9.5 available)
string_scanner 1.0.4 (1.0.5 available)
term_glyph 1.1.0 (1.2.0-nullsafety available)
unittest 0.11.7 (0.12.4+1 available)
utf 0.9.0+3 (0.9.0+5 available)
yaml 2.1.13 (2.2.1 available)
No dependencies changed.
That's a bug in the SDK requirements of package meta.
The const _AlwaysThrows alwaysThrows = _AlwaysThrows(); requires a v2.0.0 or later SDK, but the SDK requirement for that meta package incorrectly claims that it works for earlier SDK versions.
See https://github.com/dart-lang/sdk/issues/42935
Related
I shipped a build before the weekend everything works fine, I come back on Monday, impossible to build. I'm stuck on this for the past few days, I've been trying most of the stuff from the internet I can't seem to find a solution.
XCode build is failing specifying missing plugins (form the base Flutter install I'm guessing):
[ ] Xcode build done. 50.6s
[ ] Failed to build iOS app
[ ] Error output from Xcode build:
↳
[ ] 2021-06-10 09:23:10.255 xcodebuild[64069:7134747] [MT] PluginLoading: Required plug-in compatibility UUID F56A1938-53DE-493D-9D64-87EE6C415E4D for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/CocoaPods.xcplugin' not present in DVTPlugInCompatibilityUUIDs
2021-06-10 09:23:10.255 xcodebuild[64069:7134747] [MT] PluginLoading: Required plug-in compatibility UUID F56A1938-53DE-493D-9D64-87EE6C415E4D for plug-in at path '~/Library/Application Support/Developer/Shared/Xcode/Plug-ins/Alcatraz.xcplugin' not present in DVTPlugInCompatibilityUUIDs
** BUILD FAILED **
It then generates error concerning Riverpod
[+5009 ms] ../../flutter/.pub-cache/hosted/pub.dartlang.org/riverpod-0.12.4/lib/src/common.freezed.dart:121:4: Error: Getter not found: 'nullable'.
[ +2 ms] #nullable
[ ] ^^^^^^^^
[ +5 ms] ../../flutter/.pub-cache/hosted/pub.dartlang.org/riverpod-0.12.4/lib/src/common.freezed.dart:121:4: Error: This can't be used as an annotation; an annotation should be a reference to a compile-time constant variable, or a call to a constant constructor.
[ ] #nullable
[ ] ^
[ +1 ms] ../../flutter/.pub-cache/hosted/pub.dartlang.org/riverpod-0.12.4/lib/src/common.freezed.dart:206:4: Error: Getter not found: 'nullable'.
[ ] #nullable
[ ] ^^^^^^^^
[ ] ../../flutter/.pub-cache/hosted/pub.dartlang.org/riverpod-0.12.4/lib/src/common.freezed.dart:206:4: Error: This can't be used as an annotation; an annotation should be a reference to a compile-time constant variable, or a call to a constant constructor.
[ ] #nullable
[ ] ^
What I have tried so far:
flutter clean
flutter pub cache repair
Rebuilding the iOS folder
cleaning the build folder
pod update && pod install
flutter upgrade
check the use of !use_frameworks in podfile
And other configuration changes in XCode such as the script 'for install only', etc...
The only thing I see would be that the problem is coming from a package that I'm using, such as Firebase Core. They had a similar problem a year ago or so where we had to downgrade the package version in order to build and the error was similar, the problem here is that I tried to downgrade from 1.2.1 to 0.7.0 but the problem persists until it generates dependencies issues.
Same kind of issue happended with flutter_svg I think, it was due to a breaking change making it mandatory to either update flutter_svg or downgrade flutter.
Also, could it be that I have not migrated to sound null safety yet ?
If you have an idea on how to debug this, that would be very helpful. (Some stuff that I can run to have more infos regarding the error for example).
Here are my flutter doctor and pubspec files:
Flutter doctor:
[✓] Flutter (Channel stable, 2.2.1, on macOS 11.3 20E232 darwin-x64, locale en-FR)
• Flutter version 2.2.1 at /Users/Wapazz/Development/flutter
• Framework revision 02c026b03c (2 weeks ago), 2021-05-27 12:24:44 -0700
• Engine revision 0fdb562ac8
• Dart version 2.13.1
[✓] Android toolchain - develop for Android devices (Android SDK version 29.0.2)
• Android SDK at /Users/Wapazz/Library/Android/sdk
• 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_202-release-1483-b49-5587405)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS
• Xcode at /Applications/Xcode.app/Contents/Developer
• Xcode 12.5, Build version 12E262
• CocoaPods version 1.10.1
[✓] Chrome - develop for the web
• Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome
[✓] Android Studio (version 3.5)
• Android Studio at /Applications/Android Studio.app/Contents
• Flutter plugin version 42.1.1
• Dart plugin version 191.8593
• Java version OpenJDK Runtime Environment (build 1.8.0_202-release-1483-b49-5587405)
[✓] Connected device (2 available)
• iPhone 11 (mobile) • 519E686E-DEDD-4859-8D8D-EA775DB7149D • ios • com.apple.CoreSimulator.SimRuntime.iOS-14-5 (simulator)
• Chrome (web) • chrome • web-javascript • Google Chrome 91.0.4472.77
• No issues found!
Pubspec.yaml:
dependencies:
flutter:
sdk: flutter
cloud_firestore: ^2.2.2
country_code_picker: ^2.0.1
dropdown_formfield: ^0.1.3
file_picker: ^3.0.2+2
firebase_auth: ^1.4.1
firebase_core: ^1.3.0
firebase_storage: ^8.1.3
flat_segmented_control: ^0.1.0
flutter_dialogs: ^1.1.0
flutter_keyboard_visibility: ^5.0.2
flutter_radar_chart: ^0.2.0
flutter_riverpod: ^0.12.4 #^0.14.0+3
flutter_svg: ^0.22.0
google_fonts: ^2.1.0
image_picker: ^0.8.0+3
introduction_screen: ^2.1.0
modal_bottom_sheet: ^2.0.0
shimmer: ^2.0.0
video_player: ^2.1.6
youtube_player_flutter: ^8.0.0
EDIT: It seems to be coming from riverpod 0.12.4.
Updating it to the latest version generated another error but that requires code refactoring, I will update if the issue is resolved after the refactoring.
After reviewing every dependencies one by one I found the culprit.
The issue was coming from riverpod 0.12.4, updating it to the latest version fixed the issue.
In addition a refactor was necessary in order to make the app working and fix the breaking changes due to the new 0.14.0 version.
Github issue regarding riverpod
Migration guide
I have some issue with ionic CORS on an iOS device. Now, I know that CORS issue should be solved mainly from the server. As I have fool control over the backend I set the following headers on the Apache Vhosts file.
Access-Control-Allow-Origin: *
Access-Control-Allow-Methods: *
Access-Control-Allow-Headers: *
And it works, I have inspected headers and see that they are set. Android app works without any issue both in simulators and live devices. iOS app also works without any issue in any simulator I try. So it seems that the only issue I have is on a real iPhone that doesn't run app and shows CORS error.
As can be seen from the headers I have allowed anything that was possible to allow and don't get why the webview throws the error on an iOS device while all the headers are set correctly.
Here is some more info about my ionic setup
Ionic CLI : 6.10.1 (/usr/local/lib/node_modules/#ionic/cli)
Ionic Framework : ionic-angular 3.9.2
#ionic/app-scripts : 3.2.4
Cordova:
Cordova CLI : 9.0.0 (cordova-lib#9.0.1)
Cordova Platforms : android 8.1.0, ios 4.5.5
Cordova Plugins : cordova-plugin-ionic-keyboard 2.2.0, cordova-plugin-ionic-webview 5.0.0, (and 18 other plugins)
Utility:
cordova-res : not installed
native-run : 1.0.0
System:
Android SDK Tools : 26.1.1 (/Users/someuser/Library/Android/sdk)
NodeJS : v12.18.2 (/usr/local/bin/node)
npm : 6.14.5
OS : macOS Catalina
Xcode : Xcode 11.6 Build version 11E708
Here is the error I get
[Error] Request header field Content-Type is not allowed by Access-Control-Allow-Headers.
[Error] XMLHttpRequest cannot load https://app.example.com/oauth/token due to access control checks.
[Error] Backend returned code 0, body was: {"isTrusted":true}
(anonymous function) (cordova.js:1732)
handleErrors (main.js:2334)
error (vendor.js:68778)
_error (vendor.js:98287)
error (vendor.js:20453)
_error (vendor.js:20479)
error (vendor.js:20453)
_error (vendor.js:20479)
error (vendor.js:20453)
notifyError (vendor.js:22047)
_error (vendor.js:140032)
error (vendor.js:20453)
_error (vendor.js:20479)
error (vendor.js:20453)
onError (vendor.js:62444)
onInvokeTask (vendor.js:5126)
runTask (polyfills.js:3:10845)
invokeTask (polyfills.js:3:16802)
p (polyfills.js:2:27655)
v (polyfills.js:2:27895)
[Error] Failed to load resource: Request header field Content-Type is not allowed by Access-Control-Allow-Headers. (token, line 0)
Here are plugins installed
> cordova plugin ls
com-badrit-base64 0.2.0 "Base64"
cordova-plugin-advanced-http 1.11.1 "Advanced HTTP plugin"
cordova-plugin-app-version 0.1.9 "AppVersion"
cordova-plugin-badge 0.8.8 "Badge"
cordova-plugin-camera 4.1.0 "Camera"
cordova-plugin-device 2.0.3 "Device"
cordova-plugin-dialogs 2.0.2 "Notification"
cordova-plugin-file 6.0.2 "File"
cordova-plugin-file-transfer 1.7.1 "File Transfer"
cordova-plugin-geolocation 4.0.2 "Geolocation"
cordova-plugin-inappbrowser 3.2.0 "InAppBrowser"
cordova-plugin-ionic-keyboard 2.2.0 "cordova-plugin-ionic-keyboard"
cordova-plugin-ionic-webview 5.0.0 "cordova-plugin-ionic-webview"
cordova-plugin-local-notification 0.9.0-beta.3 "LocalNotification"
cordova-plugin-network-information 2.0.2 "Network Information"
cordova-plugin-request-location-accuracy 2.3.0 "Request Location Accuracy"
cordova-plugin-screen-orientation 3.0.2 "Screen Orientation"
cordova-plugin-splashscreen 5.0.4 "Splashscreen"
cordova-plugin-uniquedeviceid 1.3.2 "UniqueDeviceID"
cordova-plugin-whitelist 1.3.4 "Whitelist"
cordova-sqlite-storage 2.6.0 "Cordova sqlite storage plugin"
cordova.plugins.diagnostic 4.0.12 "Diagnostic"
es6-promise-plugin 4.2.2 "Promise"
ionic-plugin-keyboard 2.2.1 "Keyboard"
After spending several hours on debugging, I found out that the issue was that it doesn't accept wildcard for Access-Control-Allow-Methods and Access-Control-Allow-Headers
So the server headers look like this now.
Header set Access-Control-Allow-Origin: "*"
Header set Access-Control-Allow-Methods: "GET, POST, PUT, PATCH, DELETE"
Header set Access-Control-Allow-Headers: "Content-Type, Authorization, Accept, timeout"
The one drawback of this that I had to inspect all the code and include all the HTTP methods and headers that are in use throughout the app.
My understanding is that the issue was because of the Authorization header which cannot be wildcarded. And because it contains credentials, methods should be stated explicitly as well.
Now it works in all devices and simulators.
I'm facing issue using the googleapis package for Flutter/Dart. That's the code that I have...
import 'package:googleapis/gmail/v1.dart' as gMail;
import "package:googleapis_auth/auth_io.dart";
import 'package:flutter/services.dart' show rootBundle;
class Example {
ServiceAccountCredentials credentials;
Future<gMail.GmailApi> getGMailApi() async {
return gMail.GmailApi(await getGoogleClient());
}
Future<AuthClient> getGoogleClient() async {
return await clientViaServiceAccount(await getCredentials(), [
'https://www.googleapis.com/auth/drive',
'https://mail.google.com/',
]);
}
Future<ServiceAccountCredentials> getCredentials() async {
if (credentials == null) {
credentials = ServiceAccountCredentials.fromJson(
json.decode(await rootBundle.loadString('GSuiteServiceAccountInfo.json')));
}
return credentials;
}
String getBase64Email({String source}) {
List<int> bytes = utf8.encode(source);
String base64String = base64UrlEncode(bytes);
return base64StringFormatted;
}
sendEmail({
String from: 'me',
String to: 'someemail#gmail.com',
String subject: 'Some subject',
String contentType: 'text/html',
String charset: 'utf-8',
String contentTransferEncoding: 'base64',
String emailContent: '<table></table>',
}) async {
(await getGMailApi()).users.messages.send(
gMail.Message.fromJson({
'raw': getBase64Email(
source: 'From: $from\r\n'
'To: $to\r\n'
'Subject: $subject\r\n'
'Content-Type: $contentType; charset=$charset\r\n'
'Content-Transfer-Encoding: $contentTransferEncoding\r\n\r\n'
'$emailContent'), // emailContent is HTML table.
}),
from);
}
}
When I call sendEmail function I get DetailedApiRequestError(status: 400, message: Bad Request). But when I try to send the base64UrlEncoded string through the playground it works, the email is sent.
Here is my flutter doctor -v:
[√] Flutter (Channel stable, v1.2.1, on Microsoft Windows [Version 10.0.17763.316], locale en-US)
• Flutter version 1.2.1 at C:\src\flutter-0.7.3\flutter
• Framework revision 8661d8aecd (3 weeks ago), 2019-02-14 19:19:53 -0800
• Engine revision 3757390fa4
• Dart version 2.1.2 (build 2.1.2-dev.0.0 0a7dcf17eb)
[√] Android toolchain - develop for Android devices (Android SDK version 28.0.3)
• Android SDK at C:\Users\bbozhidarov\AppData\Local\Android\Sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-28, build-tools 28.0.3
• ANDROID_HOME = C:\Users\bbozhidarov\AppData\Local\Android\Sdk
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
• All Android licenses accepted.
[√] Android Studio (version 3.3)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 33.3.1
• Dart plugin version 182.5215
• Java version OpenJDK Runtime Environment (build 1.8.0_152-release-1248-b01)
[!] IntelliJ IDEA Community Edition (version 2018.1)
• IntelliJ at C:\Program Files\JetBrains\IntelliJ IDEA Community Edition 2018.1.6
X Flutter plugin not installed; this adds Flutter specific functionality.
X Dart plugin not installed; this adds Dart specific functionality.
• For information about installing plugins, see
https://flutter.io/intellij-setup/#installing-the-plugins
[!] VS Code, 64-bit edition (version 1.30.2)
• VS Code at C:\Program Files\Microsoft VS Code
X Flutter extension not installed; install from
https://marketplace.visualstudio.com/items?itemName=Dart-Code.flutter
[√] Connected device (1 available)
• Android SDK built for x86 • emulator-5554 • android-x86 • Android 8.1.0 (API 27) (emulator)
! Doctor found issues in 2 categories.
And this is my pubspec.yaml:
name: App Mobile
description: App Mobile
version: 1.0.0+1
environment:
sdk: ">=2.0.0-dev.68.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
intl: 0.15.7
cupertino_icons: 0.1.2
http: 0.11.3+17
shared_preferences: ^0.4.2
google_api_availability: 1.0.4
geolocator: 2.1.0
file_picker: 0.1.6
url_launcher: 4.0.3
flutter_calendar_carousel: 1.3.10
date_util: 0.1.4
permission_handler: 2.1.0
simple_permissions: 0.1.9
logging: 0.11.3+2
googleapis: 0.52.0+1
uuid: 2.0.0
googleapis_auth: 0.2.7
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- assets/email_templates/dynamic_form_email_template.html
- assets/email_templates/dynamic_form_email_data_row_template.html
- GSuiteServiceAccountInfo.json
I exclude the possibility of an issue with the credentials. The same credentials/account/client is working well with DriveApi. Any help will be much appreciated. Thanks.
An old one but still relevant!
Service accounts (SA) require a real gsuite account to send emails through and which the SA can impersonate.
Solution...First ensure your SA has domain wide delegation and the authorised scope for mail sending (https://www.googleapis.com/auth/gmail.send) in Manage API Access in Admin Console. Then add the impersonated user variable, supplying an existing gsuite email address to the credentials as below:
ServiceAccountCredentials.fromJson(myJsonCredentials, impersonatedUser: "existing_gsuite_email#yourdomain")
Version: 1.30.0 (system setup)
Commit: c6e592b2b5770e40a98cb9c2715a8ef89aec3d74
Date: 2018-12-11T22:29:11.253Z
Electron: 2.0.12
Chrome: 61.0.3163.100
Node.js: 8.9.3
V8: 6.1.534.41
OS: Windows_NT x64 6.1.7601
Dart VM version: 2.1.0-dev.9.4.flutter-f9ebf21297
(Thu Nov 8 23:00:07 2018 +0100) on "windows_x64"
[Dart_Reformatter] pub get
Resolving dependencies...
The current Dart SDK version is 2.1.0-dev.9.4.flutter-f9ebf21297.
Because Dart_Reformatter depends on stagehand >=3.1.4 which requires SDK version >=2.1.0 <3.0.0, version solving failed.
exit code 1
I'm not sure what I need to do to fix this.
You need to install a version of Dart (or Flutter) where the Dart SDK is >=2.1.0 – in semver, 2.1.0-dev... is < 2.1.0.
Try flutter upgrade?
Currently on
Dart VM version: 2.0.0-dev.49.0
angular ^4.0.0
Linux
Dartium
One of the upgrade requirement for Dart 2 upgrade # https://webdev-dartlang-org-dev.firebaseapp.com/dart-2 is to use build_runner 0.8 which from the error code is not compatible with Angular4.
My pubspec.yaml looks like
name: JRapha
description: A web app that uses AngularDart Components
version: 0.0.1
environment:
sdk: '>=2.0.0-dev.49.0 <2.0.0'
dependencies:
angular: ^4.0.0
dev_dependencies:
angular_test: ^1.0.0
test: ^0.12.30
build_runner: ^0.8.2
build_test: ^0.10.1
build_web_compilers: ^0.3.6
web:
compiler:
debug: dartdevc
The Error when running pub get
Because angular_compiler >=0.2.1 <0.3.0+1 depends on build ^0.10.0 and no versions of angular_compiler match >0.3.0+1 <0.4.0, angular_compiler >=0.2.1 <0.3.0+1 or >0.3.0+1 <0.4.0 requires build ^0.10.0.
And because angular >=4.0.0-beta <5.0.0-alpha depends on angular_compiler ^0.3.0, angular >=4.0.0-beta <5.0.0-alpha requires build ^0.10.0 or angular_compiler 0.3.0+1. And because angular_compiler 0.3.0+1 depends on build >=0.10.0 <0.12.0 and build_web_compilers >=0.2.1 depends on build ^0.12.0, angular >=4.0.0-beta <5.0.0-alpha is incompatible with
build_web_compilers >=0.2.1.
So, because JRapha depends on both angular ^4.0.0 and build_web_compilers ^0.3.6, version solving
failed.
Is there a solution to running AngularDart4 with Dart v2?
No, it is not compatible.
Only AngularDart v5 is compatible with Dart2 and build_runner.