Flutter 2: problem in Intl null safety library - flutter

I upgrade my flutter sdk to flutter 2.0.0. After updating sdk I have changed almost all libraries to null safety version:
environment:
sdk: '>=2.12.0 <3.0.0'
dependencies:
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
cupertino_icons: ^0.1.3
encrypt: ^4.1.0
flutter_hooks: ^0.15.0
flutter_map: ^0.11.0
flutter_password_strength: ^0.1.5
flutter_svg: ^0.18.0
geolocator: ^7.0.1
get: ^3.25.6
get_it: ^6.0.0
injectable: ^1.1.2
local_auth: ^1.1.0
moor_flutter: ^3.1.0
provider: ^5.0.0
shared_preferences: ^2.0.3
supercharged: ^1.12.0
intl: ^0.17.0
after updating I run dart $ dart migrate command. But It shows these problem about intl plugin:
Analyzing project...
[---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------/]
5 analysis issues found:
error • A value of type 'Null' can't be returned from the function '_findExact' because it has a return type of 'MessageLookupByLibrary' at lib/generated/intl/messages_all.dart:34:14 • (return_of_invalid_type)
error • A value of type 'Null' can't be returned from the function '_findGeneratedMessagesFor' because it has a return type of 'MessageLookupByLibrary' at lib/generated/intl/messages_all.dart:65:36 • (return_of_invalid_type)
error • Non-nullable instance field 'current' must be initialized at lib/generated/l10n.dart:16:3 • (not_initialized_non_nullable_instance_field)
error • The non-nullable variable 'current' must be initialized at lib/generated/l10n.dart:18:12 • (not_initialized_non_nullable_variable)
error • A value of type 'S?' can't be returned from the method 'of' because it has a return type of 'S' at lib/generated/l10n.dart:35:12 • (return_of_invalid_type)
The migration tool didn't start, due to analysis errors.
I am using last version of intl ? How can I fix that?
Doctor summary (to see all details, run flutter doctor -v):
[✓] Flutter (Channel stable, 2.0.0, on Linux, locale en_US.UTF-8)
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.0-rc1)
[✓] Chrome - develop for the web
[✓] Android Studio (version 4.0)
[✓] VS Code (version 1.53.2)
[✓] Connected device (2 available)
• No issues found!

I had the same issue. Here are 3 steps to troubleshoot this:
First of all, update intl dependency in pubspec.yaml to this:
intl: 0.17.0-nullsafety.2
If still doesn't work, then add these 2 fields in the root.
dependency_overrides:
intl: 0.17.0-nullsafety.2
Generation also can happen via plugin in Android Studio. I used old one (v 0.12) and after I updated to (v 0.14) it started to generate null safety dart files for localization.
I think I stepped on every rock here.

Related

error G7AD6136F: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null

am running my desktop application using flutter 2.10.0 and am getting this error type.
following is my flutter doctor output:
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.10.0, on Microsoft Windows [Version 10.0.19044.1766],
locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
[√] Chrome - develop for the web
[√] Visual Studio - develop for Windows (Visual Studio Community 2022 17.2.6)
[√] Android Studio (version 2021.2)
[√] IntelliJ IDEA Community Edition (version 2021.3)
[√] VS Code, 64-bit edition (version 1.69.2)
[√] Connected device (4 available)
[√] HTTP Host Availability
• No issues found!
the error is as follows:
20.1.58/lib/src/calendar/sfcalendar.dart(2867,31): error G7AD6136F: Method
'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null. [E:\SPACING\marmanet\Forest-Inventory-Desktop-master\Forest-Inventory-Desktop-master\build\windows\flutter\flutter_assemble.vcxproj]
/C:/scr/flutter/.pub-cache/hosted/pub.dartlang.org/syncfusion_flutter_calendar-20.1.58/lib/src/calendar/sfcalendar.dart(4157,35): error G7AD6136F: Method 'addPostFrameCallback' cannot be called on 'SchedulerBinding?' because it is potentially null. [E:\SPACING\marmanet\Forest-Inventory-Desktop-master\Forest-Inventory-Desktop-master\build\windows\flutter\flutter_assemble.vcxproj]
/C:/scr/flutter/.pub-cache/hosted/pub.dartlang.org/syncfusion_flutter_calendar-20.1.58/lib/src/calendar/sfcalendar.dart(4176,37): error G7AD6136F: Method 'addPostFrameCallback' cannot be called on 'SchedulerBinding?' because it is potentially null. [E:\SPACING\marmanet\Forest-Inventory-Desktop-master\Forest-Inventory-Desktop-master\build\windows\flutter\flutter_assemble.vcxproj]
/C:/scr/flutter/.pub-cache/hosted/pub.dartlang.org/syncfusion_flutter_calendar-20.1.58/lib/src/calendar/sfcalendar.dart(4322,33): error G7AD6136F: Method 'addPostFrameCallback' cannot be called on 'SchedulerBinding?' because it is potentially null. [E:\SPACING\marmanet\Forest-Inventory-Desktop-master\Forest-Inventory-Desktop-master\build\windows\flutter\flutter_assemble.vcxproj]
here is also part of my pubspec.yaml file:
sdk: ">=2.12.0 <3.0.0"
dependencies:
flutter_test:
sdk: flutter
flutter:
sdk: flutter
flutter_localizations:
sdk: flutter
url_launcher: ^6.0.2
path_provider: ^2.0.1
path_provider_macos: ^2.0.0
desktop_window: 0.4.0
syncfusion_localizations: ^20.1.47
syncfusion_flutter_datagrid_export: ^20.1.47-beta
syncfusion_flutter_calendar: ^20.1.47
syncfusion_flutter_datepicker: ^20.1.47
syncfusion_flutter_charts: ^20.1.47
syncfusion_flutter_gauges: ^20.1.47
syncfusion_flutter_sliders: ^20.1.47
syncfusion_flutter_pdf: ^20.1.47-beta
syncfusion_flutter_barcodes: ^20.1.47
syncfusion_officechart: ^20.1.47-beta
syncfusion_flutter_maps: ^20.1.47
syncfusion_flutter_signaturepad: ^20.1.47
syncfusion_flutter_pdfviewer: ^20.1.47-beta
syncfusion_flutter_treemap: ^20.1.47-beta
cloud_firestore: ^3.2.1
firebase_core: ^1.19.1`
I have tried many options without valid output, what might the problem?
You can include '?'
WidgetsBinding.instance?.addPostFrameCallback((timeStamp) { })
But I recommend the upgrade, the flutter.
For upgrade do flutter upgrade, use the latest version packages and you can use like bellow on current version
WidgetsBinding.instance.addPostFrameCallback((timeStamp) { })
This is a bug in the syncfusion_flutter_calendar package; they released a version that uses code that only works in Flutter 3.0 or later, but didn't set the package's minimum version to Flutter 3.0.
You can work around it by either upgrading to Flutter 3.0 or using a version of the package from before they made that incompatible change, but you should also report it to the developers of the package.

I am getting error while trying to run my flutter project

When I try to run my flutter project I get the error below. What could be the cause? ......................................................................................................................................................................................................................................................................................................................................................................................................................
Launching lib\main.dart on Android SDK built for x86 in debug mode...
Running Gradle task 'assembleDebug'...
/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/carousel_slider-4.1.1/lib/carousel_slider.dart:268:7: Error: No named parameter with the name 'padEnds'.
padEnds: widget.options.padEnds,
^^^^^^^
/C:/src/flutter/flutter/packages/flutter/lib/src/widgets/page_view.dart:664:3: Context: Found this candidate, but the arguments don't match.
PageView.builder({
^^^^^^^^^^^^^^^^
/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging_platform_interface-3.2.0/lib/src/method_channel/utils/exception.dart:13:11: Error: Method not found: 'Error.throwWithStackTrace'.
Error.throwWithStackTrace(exception, stackTrace);
^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging_platform_interface-3.2.0/lib/src/method_channel/utils/exception.dart:16:9: Error: Method not found: 'Error.throwWithStackTrace'.
Error.throwWithStackTrace(
^^^^^^^^^^^^^^^^^^^
/C:/src/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/firebase_messaging_platform_interface-3.2.0/lib/src/method_channel/utils/exception.dart:11:7: Error: A non-null value must be returned since the return type 'Never' doesn't allow null.
Never convertPlatformException(Object exception, StackTrace stackTrace) {
^
FAILURE: Build failed with an exception.
* Where:
Script 'C:\src\flutter\flutter\packages\flutter_tools\gradle\flutter.gradle' line: 1035
* What went wrong:
Execution failed for task ':app:compileFlutterBuildDebug'.
> Process 'command 'C:\src\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 41s
Exception: Gradle task assembleDebug failed with exit code 1
These are my dependencies in my pubspec.yaml
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^1.0.3
# google_fonts: ^2.1.0
google_fonts: 2.2.0
flutter_icons_nullsafty: ^1.0.0
http: ^0.13.3
cached_network_image: ^3.1.0
encrypt: ^5.0.1
flutter_svg: ^0.22.0
qr_flutter: ^4.0.0
clipboard: ^0.1.3
share: ^2.0.4
qr_code_scanner: ^0.5.2
fluro: ^2.0.3
url_launcher: ^6.0.10
image_picker: ^0.8.4
country_code_picker: ^2.0.2
introduction_screen: ^2.1.0
pin_code_fields: ^7.3.0
provider: ^6.0.0
hive: ^2.0.4
hive_flutter: ^1.1.0
flutter_secure_storage: ^4.2.1
local_auth: ^1.1.7
permission_handler: ^8.1.4+2
fl_chart: ^0.40.0
carousel_slider: ^4.0.0
web3dart: ^2.3.1
device_info_plus: ^2.1.0
package_info_plus: ^1.3.0
intl: ^0.17.0
timeago: ^3.1.0
razorpay_flutter: ^1.2.7
flutter_paystack: ^1.0.5+1
flutter_braintree: ^2.0.0+1
loading_overlay: ^0.3.0
lazy_load_scrollview: ^1.3.0
shimmer: ^2.0.0
in_app_review: ^2.0.3
image_cropper: ^1.4.1
ntp: ^2.0.0
uuid: ^3.0.4
cron: ^0.3.2
dotted_border: ^2.0.0+1
translator: ^0.1.7
firebase_core: ^1.6.0
firebase_messaging: ^10.0.9
firebase_analytics: ^8.3.4
firebase_dynamic_links: ^3.0.1
flutter doctor -v response
C:\Users\USER>flutter doctor -v
[√] Flutter (Channel unknown, 2.2.0, on Microsoft Windows [Version 10.0.19041.264], locale en-US)
• Flutter version 2.2.0 at C:\src\flutter\flutter
• Framework revision b22742018b (1 year ago), 2021-05-14 19:12:57 -0700
• Engine revision a9d88a4d18
• Dart version 2.13.0
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.2)
• Android SDK at C:\Users\USER\Documents\Sdk
• Platform android-31, build-tools 30.0.2
• ANDROID_HOME = C:\Users\USER\Documents\Sdk
• 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\Google\Chrome\Application\chrome.exe
[√] Android Studio (version 4.1.0)
• 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)
[√] VS Code (version 1.67.1)
• VS Code at C:\Users\USER\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.23.0
[√] Connected device (2 available)
• Android SDK built for x86 (mobile) • emulator-5554 • android-x86 • Android 6.0 (API 23) (emulator)
• Chrome (web) • chrome • web-javascript • Google Chrome 100.0.4896.127
• No issues found!
You are using a too old flutter version. You are using version 2.2.0
padEnds only became exposed in version 2.5.0 as you can see here:
https://docs.flutter.dev/development/tools/sdk/release-notes/release-notes-2.5.0
78558 Expose padEnds on PageView widget
You need to upgrade your flutter. You can do that by writing
flutter upgrade
though it says in your flutter doctor that you are on an unknown channel so maybe you need to do
flutter channel stable
first
My guess is that some dependencies are using deprecated methods (which are removed in the newer Flutter version).
Try the following commands (WARNING: you will most likely have to update your codebase after this, and your packages as well.)
Update Flutter - flutter upgrade
Get dependencies - flutter pub get
Update dependencies flutter pub upgrade
Re-fetch dependencies - flutter pub get
Update your code to the newest version.
Rebuild

I keep on getting pubsepc.yaml error when running flutter

This is my pubsepc.yaml code
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
rxdart: ^0.27.1
path_provider: ^2.0.2
image_picker: ^0.8.0+3
pendatic: ^1.8.0
cupertino_icons: ^1.0.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
To add assets to your application, add an assets section, like this:
assets:
- assets/images/apple-in-hand.jpg
- assets/images/apricots.jpg
- assets/images/asparagus.jpg
The error message I keep on getting is like below
PS C:\Users\Geon-Young.Hong\e_commerce> flutter packages get
Error detected in pubspec.yaml:
Unexpected child "To add assets to your application, add an assets section, like this" found under "flutter".
Please correct the pubspec.yaml file at C:\Users\Geon-Young.Hong\e_commerce\pubspec.yaml
There is no issue found when I run flutter doctor
PS C:\Users\Geon-Young.Hong\e_commerce> flutter doctor
Doctor summary (to see all details, run flutter doctor -v):
[√] Flutter (Channel stable, 2.0.4, on Microsoft Windows [Version 10.0.19042.1052], locale en-US)
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
[√] Chrome - develop for the web
[√] Android Studio (version 4.1.0)
[√] VS Code (version 1.57.0)
[√] Connected device (2 available)
This is flutter & dart version info
Flutter 2.0.4 • channel stable • https://github.com/flutter/flutter.git
Framework • revision b1395592de (2 months ago) • 2021-04-01 14:25:01 -0700
Engine • revision 2dce47073a
Tools • Dart 2.12.2
I cannot import rxdart, image_picker package. (There is an assets directory outside of lib)
it could be a version-related issue or something else.
Is there anybody who can help me out with this matter?
Thank you so so much!
Delete the section To add assets to your application, add an assets section, like this: from the pubspec.yaml
The error its telling you that there is an unexpected child, "To add assets to your application, add an assets section, like this:" that line should not be there, comment it out, or delete it ang pub get should run fine
Replace this code to your pubsepc.yaml all my code bellow.
version: 1.0.0+1
environment:
sdk: ">=2.7.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
rxdart: ^0.27.1
path_provider: ^2.0.2
image_picker: ^0.8.0+3
pendatic: ^1.8.0
cupertino_icons: ^1.0.2
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
# To add assets to your application, add an assets section, like this:
assets:
- assets/images/apple-in-hand.jpg
- assets/images/apricots.jpg
- assets/images/asparagus.jpg

TrustManager vulnerability when flutter app published in Google Play

I recently published an application on google play, and I received an email from the google play team which says: ...and found that your app uses software that contains security vulnerabilities for users. Apps with these vulnerabilities can expose user information or damage a user’s device, and may be considered to be in violation of our Malicious Behavior policy.
Below is the list of issues and the corresponding APK versions that were detected in your recent submission. Please migrate your apps to use the updated software as soon as possible and increment the version number of the upgraded APK.
Vulnerability : TrustManager
My application was developed with Flutter...
I really don't know how to fix this, if you can help me.
pubspec.yaml
name: ...
description: ...
version: 1.0.1+2
environment:
sdk: ">=2.1.0 <3.0.0"
dependencies:
flutter:
sdk: flutter
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons class for iOS style icons.
cupertino_icons: ^0.1.2
#bottom_navy_bar: ^5.3.2
http: ^0.12.2
shared_preferences: ^0.5.6+1
location: ^2.3.5
sqflite: ^1.2.0
path_provider: ^1.6.0
image_picker: ^0.6.3+1
intl: ^0.16.1
country_code_picker: ^1.2.4
multi_image_picker: ^4.6.1
firebase_auth: ^0.16.1
image_cropper: ^1.2.1
validators: ^2.0.0+1
firebase_messaging: ^6.0.9
esys_flutter_share: ^1.0.2
photo_view: ^0.9.1
material_design_icons_flutter: ^3.4.4895
url_launcher: ^5.4.1
cached_network_image: ^2.0.0
encrypt: ^4.0.0
flutter_local_notifications: ^1.1.6
r_scan: ^0.1.3+2
permission_handler: ^4.2.0+hotfix.3
native_contact_picker: ^0.0.6
qr_utils:
path: packages/qr_utils
libphonenumber: ^1.0.1
flutter_cache_manager: ^1.1.3
csv: ^4.0.3
excel: ^1.0.2
pdf: ^1.5.0
printing: any
flutter_swiper: ^1.1.6
flutter_rating_bar: ^3.0.1+1
flutter_native_admob: ^2.1.0
dev_dependencies:
flutter_test:
sdk: flutter
flutter:
uses-material-design: true
assets:
- assets/images/
code
String url = "https://exemple.com/resources/users/1";
try {
final response = await http.get(url);
if (response.statusCode == 200) {
//parse user
}
} on SocketException {
} catch (ex) {
print(ex.toString());
}
return null;
flutter doctor
[√] Flutter (Channel stable, v1.17.3, on Microsoft Windows [version 10.0.10240], locale fr-FR)
• Flutter version 1.17.3 at C:\souces\flutter
• Framework revision b041144f83 (8 weeks ago), 2020-06-04 09:26:11 -0700
• Engine revision ee76268252
• Dart version 2.8.4
[√] Android toolchain - develop for Android devices (Android SDK version 30.0.0)
• Android SDK at D:\android\android-sdk-windows
• Platform android-30, build-tools 30.0.0
• ANDROID_HOME = D:\android\android-sdk-windows
• Java binary at: C:\Program Files\Android\Android Studio\jre\bin\java
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
• All Android licenses accepted.
[√] Android Studio (version 4.0)
• Android Studio at C:\Program Files\Android\Android Studio
• Flutter plugin version 46.0.2
• Dart plugin version 193.7361
• Java version OpenJDK Runtime Environment (build 1.8.0_242-release-1644-b01)
[√] VS Code (version 1.46.0)
• VS Code at C:\Users\User\AppData\Local\Programs\Microsoft VS Code
• Flutter extension version 3.12.2
[√] Connected device (1 available)
• TECNO WX4 • 0257309828005184 • android-arm • Android 7.0 (API 24)
• No issues found!
It's probably caused by the r_scan library as it uses custom implementation of the X509TrustManager. See this issue.

Flutter After Upgrade can't run application version solving failed

Nope. This answer doesn't work this time for me.
My flutter doctor -v
[✓] Flutter (Channel master, v0.5.9-pre.68, on Linux, locale en_US.UTF-8)
• Flutter version 0.5.9-pre.68 at /home/khophi/.flutterSetup
• Framework revision 5cd97f0004 (2 hours ago), 2018-08-16 14:10:22 -0700
• Engine revision 4ee648914f
• Dart version 2.1.0-dev.0.0.flutter-be6309690f
[✓] Android toolchain - develop for Android devices (Android SDK 27.0.3)
• Android SDK at /home/khophi/Android/sdk
• Android NDK location not configured (optional; useful for native profiling support)
• Platform android-27, build-tools 27.0.3
• ANDROID_HOME = /home/khophi/Android/sdk
• Java binary at: /usr/bin/java
• Java version OpenJDK Runtime Environment (build 1.8.0_171-8u171-b11-0ubuntu0.18.04.1-b11)
• All Android licenses accepted.
[✗] Android Studio (not installed)
• Android Studio not found; download from https://developer.android.com/studio/index.html
(or visit https://flutter.io/setup/#android-setup for detailed instructions).
[✓] VS Code (version 1.26.0)
• VS Code at /usr/share/code
• Flutter extension version 2.17.1
[✓] Connected devices (1 available)
• klte • 956e8b90 • android-arm • Android 8.1.0 (API 27)
! Doctor found issues in 1 category.
When I run flutter run, I get:
Running "flutter packages get" in townsquare...
The current Dart SDK version is 2.1.0-dev.0.0.flutter-be6309690f.
Because flutter_circular_chart 0.0.3 requires SDK version >=1.19.0 <2.0.0 and no versions of flutter_circular_chart match >0.0.3 <0.1.0, flutter_circular_chart ^0.0.3 is forbidden.
So, because mobile depends on flutter_circular_chart ^0.0.3, version solving failed.
pub get failed (1)
This is my pubspec.yaml
name: mobile
description: A new Flutter project.
version: 1.0.0+1
dependencies:
flutter:
sdk: flutter
cupertino_icons: ^0.1.2
carousel: ^0.0.1
http: "^0.11.3+16"
validate: "^1.6.0"
url_launcher: "^3.0.2"
shared_preferences: "^0.4.2"
font_awesome_flutter: "^7.0.0"
flutter_circular_chart: "^0.0.3"
flutter_local_notifications: ^0.3.6
dev_dependencies:
flutter_test:
sdk: flutter
assets:
- images/flutter.jpg
- images/logo.png
- images/bg_viewer.jpg
With the above, please enlighten me, what's wrong?
That's is because you are using : Dart version 2.1.0-dev.0.0.flutter-be6309690f and the plugin named flutter_circular_chart has a constraint
https://github.com/xqwzts/flutter_circular_chart/blob/master/pubspec.yaml
environment:
sdk: '>=1.19.0 <2.0.0'
You can fork the project and update the sdk constraint and ref to your repository:
Like this:
flutter_circular_chart:
git: https://github.com/your_repo/flutter_circular_chart.git
Note
Also would be fine if you open an issue in their repo to notify the devs about the issue that you have.
Use devendency_override with same version witch need for same for other dependency.
Like google_maps_flutter: ^0.5.28+1 needs intl to be 0.16.0
then craete dependency_overrides:
intl: ^0.16.0
below of dev_dependencies:
flutter_test:
sdk: flutter
run project until it not run on device.
Enjoy. Thanks..