Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

使用fontSize,Null check operator used on a null value #362

Closed
cjango opened this issue Apr 7, 2022 · 16 comments
Closed

使用fontSize,Null check operator used on a null value #362

cjango opened this issue Apr 7, 2022 · 16 comments

Comments

@cjango
Copy link

cjango commented Apr 7, 2022

style: TextStyle(
color: Colors.black,
fontSize: 16.sp,
),

报错:
_CastError (Null check operator used on a null value)

@lizhuoyuan
Copy link
Collaborator

这应该不会是库的问题吧
再看一下

@cjango
Copy link
Author

cjango commented Apr 8, 2022

只能在 width 和 height 里面使用,fontSize,EdgeInsets.only(left: 16), 这些地方,都没法用计算的属性,完全按照文档来的,很纳闷是怎么回事。

@SumeetMourya
Copy link

This is also happening with me also, when I remove the 16.sp, 20.h or 20.w then code is working fine.
but this issue occurred when we push new screenB then we got these(Null check operator used on a null value) type of error, and come back again to the old screenA then there is an issue on the widget which is using this.

@jonchui
Copy link

jonchui commented Apr 24, 2022

只能在 width 和 height 里面使用,fontSize,EdgeInsets.only(left: 16), 这些地方,都没法用计算的属性,完全按照文档来的,很纳闷是怎么回事。

English:

Just use width and height, fontSize,EdgeInsets.only(left: 16), This area,Metrical attributes for the death method,Completely massage archives,It's very good.

So this null operator crash seems to happen to me when I use width .w or .h

Any ideas?

@BIG-BEARC
Copy link

BIG-BEARC commented Apr 25, 2022

只能在 width 和 height 里面使用,fontSize,EdgeInsets.only(left: 16), 这些地方,都没法用计算的属性,完全按照文档来的,很纳闷是怎么回事。

English:

Just use width and height, fontSize,EdgeInsets.only(left: 16), This area,Metrical attributes for the death method,Completely massage archives,It's very good.

So this null operator crash seems to happen to me when I use width .w or .h

Any ideas?

i used the second way Initialize, and it worked for me by used the global context,hope it can help you

只能在 width 和 height 里面使用,fontSize,EdgeInsets.only(left: 16), 这些地方,都没法用计算的属性,完全按照文档来的,很纳闷是怎么回事。

我采用的第二种初始化方式,使用的全局的context 解决了这个问题,这是我的示例代码

 return StyledToast(
      locale: const Locale('en', 'US'),
      borderRadius: BorderRadius.circular(5.0),
      textPadding: const EdgeInsets.symmetric(horizontal: 17.0, vertical: 10.0),
      toastPositions: StyledToastPosition.bottom,
      dismissOtherOnShow: true,
      toastAnimation: StyledToastAnimation.fade,
      child: GetMaterialApp(
        navigatorKey: Get.key,
        debugShowCheckedModeBanner: false,
        onGenerateRoute: onGenerateRoute,
        home: const SplashPage(),
        initialBinding: BindingsBuilder(
              () => GetControllerUtil.initGetController(),
        ),
      ),
    );

SplashPage

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(Get.key.currentState?.context,
        designSize: const Size(1080, 608),
        deviceSize: Size(MediaQuery.of(Get.context??context).size.width,
            MediaQuery.of(Get.context??context).size.height),
        minTextAdapt: true);

    return Scaffold(
      body: Container(
        color: Colors.blueAccent,
        alignment: Alignment.center,
        child: const Text(
          "Welcome ",
          style: TextAndColorConfig.textStyle16_ffd0d0d0,
        ),
      ),
    );
  }

@junaidlodhi22
Copy link

This issue also happening to us
we needed to initialize screenutil again like this in the Build method of our class

We are using GetX to open navigation

ScreenUtil.init(
      context,
      designSize: const Size(414, 896),
      deviceSize: Size(MediaQuery.of(Get.context ?? context).size.width, MediaQuery.of(Get.context ?? context).size.height),
      minTextAdapt: true,
    );

@lizhuoyuan
Copy link
Collaborator

try latest version

@Mounir-Bouaiche
Copy link
Collaborator

Hello @cjango @SumeetMourya @jonchui @BIG-BEARC , I have recently publish the new version of the library. Go check it out and if it works fine for you please close this issue, or else drop error log here. Thank you.

@junaidlodhi22
Copy link

The issue persists in newer version.
I am using Flutter 3 and flutter_screenutil 5.5.2

The issue comes up after opening and closing BottomSheet

@Mounir-Bouaiche
Copy link
Collaborator

Mounir-Bouaiche commented May 14, 2022

The issue persists in newer version. I am using Flutter 3 and flutter_screenutil 5.5.2

The issue comes up after opening and closing BottomSheet

@junaidlodhi22, If you don't mind, please try with fix-362 branch instead and tell us if it works with you so we can ship a stable version in pub.dev.

dependencies:

  flutter_screenutil: ^5.5.3

@junaidlodhi22
Copy link

The issue persists in newer version. I am using Flutter 3 and flutter_screenutil 5.5.2
The issue comes up after opening and closing BottomSheet

@junaidlodhi22, If you don't mind, please try with fix-362 branch instead and tell us if it works with you so we can ship a stable version in pub.dev.

dependencies:

  flutter_screenutil:
    git:
      url: https://github.com/OpenFlutter/flutter_screenutil
      branch: fix-362

Yes, this is working right now. We will also send this new update in testing and let's see if the Testing department clears it. But So far so good. thanks

@Mounir-Bouaiche
Copy link
Collaborator

Ok @junaidlodhi22 , please let us know whenever your team confirm. Thank you.

@ZyElite
Copy link

ZyElite commented May 15, 2022

只能在 width 和 height 里面使用,fontSize,EdgeInsets.only(left: 16), 这些地方,都没法用计算的属性,完全按照文档来的,很纳闷是怎么回事。

English:
Just use width and height, fontSize,EdgeInsets.only(left: 16), This area,Metrical attributes for the death method,Completely massage archives,It's very good.
So this null operator crash seems to happen to me when I use width .w or .h
Any ideas?

i used the second way Initialize, and it worked for me by used the global context,hope it can help you

只能在 width 和 height 里面使用,fontSize,EdgeInsets.only(left: 16), 这些地方,都没法用计算的属性,完全按照文档来的,很纳闷是怎么回事。

我采用的第二种初始化方式,使用的全局的context 解决了这个问题,这是我的示例代码

 return StyledToast(
      locale: const Locale('en', 'US'),
      borderRadius: BorderRadius.circular(5.0),
      textPadding: const EdgeInsets.symmetric(horizontal: 17.0, vertical: 10.0),
      toastPositions: StyledToastPosition.bottom,
      dismissOtherOnShow: true,
      toastAnimation: StyledToastAnimation.fade,
      child: GetMaterialApp(
        navigatorKey: Get.key,
        debugShowCheckedModeBanner: false,
        onGenerateRoute: onGenerateRoute,
        home: const SplashPage(),
        initialBinding: BindingsBuilder(
              () => GetControllerUtil.initGetController(),
        ),
      ),
    );

SplashPage

  @override
  Widget build(BuildContext context) {
    ScreenUtil.init(Get.key.currentState?.context,
        designSize: const Size(1080, 608),
        deviceSize: Size(MediaQuery.of(Get.context??context).size.width,
            MediaQuery.of(Get.context??context).size.height),
        minTextAdapt: true);

    return Scaffold(
      body: Container(
        color: Colors.blueAccent,
        alignment: Alignment.center,
        child: const Text(
          "Welcome ",
          style: TextAndColorConfig.textStyle16_ffd0d0d0,
        ),
      ),
    );
  }

flutter version 3.0 combined with getx to solve the problem。

@Mounir-Bouaiche
Copy link
Collaborator

@ZyElite, branch fix-362 doesn't work for you?!

@junaidlodhi22
Copy link

Ok @junaidlodhi22 , please let us know whenever your team confirm. Thank you.

Yes, the fix is working fine.

@Mounir-Bouaiche
Copy link
Collaborator

@junaidlodhi22 Thank you for your contribution.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

8 participants