OpenFlutter / flutter_screenutil

Flutter screen adaptation, font adaptation, get screen information
https://pub.dartlang.org/packages/flutter_screenutil
Apache License 2.0
3.88k stars 494 forks source link

Null Safety issue #397

Closed christopherayork closed 2 years ago

christopherayork commented 2 years ago

https://github.com/OpenFlutter/flutter_screenutil/blob/7aad18983c07d9c7e855b4bfd71dded457f7badf/lib/src/screen_util.dart#L104

Throws this error due to WidgetsBinding being nullable:

/C:/SDKs/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_screenutil-5.5.3/lib/src/screen_util.dart:104:29: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/C:/SDKs/flutter/flutter/packages/flutter/lib/src/widgets/binding.dart').
package:flutter/…/widgets/binding.dart:1
Try calling using ?. instead.
    WidgetsBinding.instance.addPostFrameCallback((_) {
                            ^^^^^^^^^^^^^^^^^^^^

Can we update this with the nullish access operator? Or a non-null assertion, if we're sure WidgetsBinding is initialized.

Mounir-Bouaiche commented 2 years ago

Thank you, I didn't pay attention to that. In Flutter SDK 3.0.0, WidgetsBinding.instance wouldn't return nullable anymore, that's why I didn't get an error.

diegopq commented 2 years ago

https://github.com/OpenFlutter/flutter_screenutil/blob/7aad18983c07d9c7e855b4bfd71dded457f7badf/lib/src/screen_util.dart#L104

Throws this error due to WidgetsBinding being nullable:

/C:/SDKs/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_screenutil-5.5.3/lib/src/screen_util.dart:104:29: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/C:/SDKs/flutter/flutter/packages/flutter/lib/src/widgets/binding.dart').
package:flutter/…/widgets/binding.dart:1
Try calling using ?. instead.
    WidgetsBinding.instance.addPostFrameCallback((_) {
                            ^^^^^^^^^^^^^^^^^^^^

Can we update this with the nullish access operator? Or a non-null assertion, if we're sure WidgetsBinding is initialized.

Same error in iOS

Mounir-Bouaiche commented 2 years ago

https://github.com/OpenFlutter/flutter_screenutil/blob/7aad18983c07d9c7e855b4bfd71dded457f7badf/lib/src/screen_util.dart#L104

Throws this error due to WidgetsBinding being nullable:

/C:/SDKs/flutter/flutter/.pub-cache/hosted/pub.dartlang.org/flutter_screenutil-5.5.3/lib/src/screen_util.dart:104:29: Error: Method 'addPostFrameCallback' cannot be called on 'WidgetsBinding?' because it is potentially null.
- 'WidgetsBinding' is from 'package:flutter/src/widgets/binding.dart' ('/C:/SDKs/flutter/flutter/packages/flutter/lib/src/widgets/binding.dart').
package:flutter/…/widgets/binding.dart:1
Try calling using ?. instead.
    WidgetsBinding.instance.addPostFrameCallback((_) {
                            ^^^^^^^^^^^^^^^^^^^^

Can we update this with the nullish access operator? Or a non-null assertion, if we're sure WidgetsBinding is initialized.

Same error in iOS

Use latest. V5.5.3+1

github-actions[bot] commented 2 years ago

This issue is stale because it has been open for 30 days with no activity.

github-actions[bot] commented 2 years ago

This issue was closed because it has been inactive for 14 days since being marked as stale.