OpenFlutter / flutter_screenutil

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

页面IOS风格返回报错 Another exception was thrown: Null check operator used on a null value #502

Closed AK1118 closed 1 year ago

AK1118 commented 1 year ago

发现一个bug 已使用ScreenUtilInit 页面A和B是同级用PageView包裹的页面,当我在页面A跳转页面 C (IOS风格),随后在页面C半侧滑返回页面A时(没有果断返回,扭扭捏捏那种),返回A页面,当我再跳转B页面时会出现 Another exception was thrown: Null check operator used on a null value 但是当我移除页面B使用的ScreentUtil或是在页面B重新init ScreenUtil后,再次重复上面的动作就不会报错。 flutter版本3.10

Mounir-Bouaiche commented 1 year ago

We accept only issues with minimal reproducable code. Many problems are not related to this library. This issue will be closed within 2 days if no code provided.

ksmks0921 commented 1 year ago

I met same errors. Below is my code. After leave this page, when I come back to this page with back button function Navigator.of(context).popUntil((route) => route.isFirst);, I can see an error [Null check operator used on a null value].

flutter_screenutil: ^5.0.0 I also tried with the latest version. Same error.

`import 'package:flutter/material.dart'; import 'package:flutter_riverpod/flutter_riverpod.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:halen_customer_app/appstate/app_state.dart'; import 'package:halen_customer_app/constants/constants.dart'; import 'package:halen_customer_app/screens/gorcery/components/grocery_home/custom_tabbar.dart'; import 'package:halen_customer_app/screens/homepage/components/custom_appbar.dart'; import 'package:halen_customer_app/screens/homepage/components/headline.dart'; import 'package:halen_customer_app/screens/homepage/components/image_carousel.dart'; import 'package:halen_customer_app/screens/homepage/data.dart';

class GroceryHomeTab extends ConsumerStatefulWidget { const GroceryHomeTab({Key? key}) : super(key: key);

@override ConsumerState createState() => _GroceryHomeTabState(); }

class _GroceryHomeTabState extends ConsumerState { @override Widget build(BuildContext context) { final category = ref.read(categoryProvider); int initialIndex = 0; if (category == Constants.categoryGrocery) { initialIndex = 2; } else if (category == Constants.categoryShop) { initialIndex = 3; } return Stack( children: [ Column( children: [ const HomeAppBar( key: Key("custom_app_bar"), name: 'Edward', location: 'Add Address', image: 'assets/images/illustrations/Profile Image.png', cartItemCount: 0, ), ImageCarousel(images: images), const Headline( headline: groceryHeadline, ), SizedBox( height: 20.h, // Null check operator used on a null value ), Expanded( child: CustomTabBar( initialIndex: initialIndex, ), ), ], ), Positioned( right: 10.w, bottom: 10.h, child: GestureDetector( onTap: () {}, child: Container( width: 64.w, height: 64.h, decoration: BoxDecoration( color: Colors.white, shape: BoxShape.circle, boxShadow: [ BoxShadow( color: Colors.grey.withOpacity(0.5), spreadRadius: 2, blurRadius: 5, offset: const Offset(0, 3), ), ], ), child: Center( child: Container( width: 54.w, height: 54.h, decoration: const BoxDecoration( color: Colors.blue, shape: BoxShape.circle, ), child: Image.asset( "assets/images/grocery/discount.png", width: 30.w, height: 30.h, ), ), ), ), ), ), ], ); } } `

Mounir-Bouaiche commented 1 year ago

@ksmks0921 what version you're using?

ksmks0921 commented 1 year ago

flutter_screenutil: ^5.0.0 I also tried with the latest version. Same error. I downgraded to 5.0.0 https://stackoverflow.com/questions/71493295/exception-null-check-operator-used-on-a-null-value-flutter

Mounir-Bouaiche commented 1 year ago

@ksmks0921 This issue is solved in next releases, I don't think it's related to this library. Anyway, you should provide a code that we can execute, a one file app, or a repo.

ksmks0921 commented 1 year ago

You mean in the higher versions than 5.0.0?

fuadreza commented 1 year ago

@ksmks0921 This issue is solved in next releases, I don't think it's related to this library. Anyway, you should provide a code that we can execute, a one file app, or a repo.

Hi @Mounir-Bouaiche , This Null check happen to me and I tried to upgrade the version from 5.8.4 to 5.9.0. The error is gone.

But

Another bug pops up. When keyboard pop, widget get rebuilds. and making the size of every widget change. Especially when using Tablet landscape mode.