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

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

Closed cjango closed 2 years ago

cjango commented 2 years ago

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

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

lizhuoyuan commented 2 years ago

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

cjango commented 2 years ago

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

SumeetMourya commented 2 years ago

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 commented 2 years ago

只能在 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 commented 2 years ago

只能在 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 commented 2 years ago

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 commented 2 years ago

try latest version

Mounir-Bouaiche commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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 commented 2 years ago

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

ZyElite commented 2 years ago

只能在 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 commented 2 years ago

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

junaidlodhi22 commented 2 years ago

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

Yes, the fix is working fine.

Mounir-Bouaiche commented 2 years ago

@junaidlodhi22 Thank you for your contribution.