fix(runtime): late top-level/instance vars used with ??= (mediaQuery/screenHeight/etc) -> nullable. Fixes LateInitializationError on /me /shop /product-detail

This commit is contained in:
2026-08-01 02:06:07 +08:00
parent 0526baa3c8
commit 147ab866e1
4 changed files with 41 additions and 41 deletions

View File

@@ -20,9 +20,9 @@ import '../../utils/util_web.dart'
if (dart.library.io) '../../utils/util_io.dart';
import '../../utils/utils.dart';
late MediaQueryData mediaQuery;
late double statusBarHeight;
late double screenHeight;
MediaQueryData? mediaQuery;
double? statusBarHeight;
double? screenHeight;
class MobileMe extends StatefulWidget {
final Key? key;
@@ -43,7 +43,7 @@ class MobileMeState extends State<MobileMe> {
User? _user;
late ShopScrollCoordinator _shopCoordinator;
late ShopScrollController _pageScrollController;
ShopScrollController? _pageScrollController;
final double _sliverAppBarInitHeight = 165.0;
final double _appBarHeight = 85.0;
@@ -65,13 +65,13 @@ class MobileMeState extends State<MobileMe> {
}
mediaQuery ??= MediaQuery.of(context);
screenHeight ??= mediaQuery.size.height;
statusBarHeight ??= mediaQuery.padding.top;
screenHeight ??= mediaQuery!.size.height;
statusBarHeight ??= mediaQuery!.padding.top;
_pageScrollController ??=
_shopCoordinator.pageScrollController(_sliverAppBarInitHeight * -1.0);
_shopCoordinator.pinnedHeaderSliverHeightBuilder ??= () {
return statusBarHeight + kToolbarHeight + _appBarHeight;
return statusBarHeight! + kToolbarHeight + _appBarHeight;
};
_listScrollController1 = _shopCoordinator.newChildScrollController();

View File

@@ -23,10 +23,10 @@ import '../../widgets/general/add_remove_button.dart';
import '../../widgets/general/carousel.dart';
import '../../widgets/general/show_price.dart';
late MediaQueryData mediaQuery;
late double statusBarHeight;
late double screenHeight;
late double screenWidth;
MediaQueryData? mediaQuery;
double? statusBarHeight;
double? screenHeight;
double? screenWidth;
class MobileProductDetailPage extends StatefulWidget {
final Business business;
@@ -45,12 +45,12 @@ class MobileProductDetailPage extends StatefulWidget {
class MobileProductDetailPageState extends State<MobileProductDetailPage>
with SingleTickerProviderStateMixin {
late ShopScrollCoordinator _shopCoordinator;
late ShopScrollController _pageScrollController;
ShopScrollController? _pageScrollController;
late TabController _tabController;
late double _sliverAppBarInitHeight;
late double _sliverAppBarMaxHeight;
double? _sliverAppBarInitHeight;
double? _sliverAppBarMaxHeight;
final double _tabBarHeight = 50;
ProductDetail? productDetail;
@@ -75,18 +75,18 @@ class MobileProductDetailPageState extends State<MobileProductDetailPage>
refresh = false;
mediaQuery ??= MediaQuery.of(context);
screenHeight ??= mediaQuery.size.height;
screenWidth ??= mediaQuery.size.width;
statusBarHeight ??= mediaQuery.padding.top;
screenHeight ??= mediaQuery!.size.height;
screenWidth ??= mediaQuery!.size.width;
statusBarHeight ??= mediaQuery!.padding.top;
_sliverAppBarInitHeight ??= screenWidth;
_sliverAppBarMaxHeight ??= screenWidth;
_pageScrollController ??= _shopCoordinator
.pageScrollController(_sliverAppBarMaxHeight - _sliverAppBarInitHeight);
.pageScrollController(_sliverAppBarMaxHeight! - _sliverAppBarInitHeight!);
_shopCoordinator.pinnedHeaderSliverHeightBuilder ??= () {
return statusBarHeight + kToolbarHeight + _tabBarHeight;
return statusBarHeight! + kToolbarHeight + _tabBarHeight;
};
return Scaffold(
@@ -110,10 +110,10 @@ class MobileProductDetailPageState extends State<MobileProductDetailPage>
},
),
backgroundColor: Theme.of(context).primaryColor,
expandedHeight: _sliverAppBarMaxHeight - 30.0,
expandedHeight: _sliverAppBarMaxHeight! - 30.0,
flexibleSpace: FlexibleSpaceBar(
background: Carousel(
height: _sliverAppBarInitHeight + 0.0,
height: _sliverAppBarInitHeight! + 0.0,
pages: _getProductPictures(context),
autoPlay: false,
),

View File

@@ -37,10 +37,10 @@ import 'product_item.dart';
import 'product_search.dart';
import 'shopping_cart_bar.dart';
late MediaQueryData mediaQuery;
late double statusBarHeight;
late double screenWidth;
late double screenHeight;
MediaQueryData? mediaQuery;
double? statusBarHeight;
double? screenWidth;
double? screenHeight;
class Shop extends StatefulWidget {
final int? businessId;
@@ -80,11 +80,11 @@ class ShopState extends State<Shop>
bool refresh = false;
late ShopScrollCoordinator _shopCoordinator;
late ShopScrollController _pageScrollController;
ShopScrollController? _pageScrollController;
late TabController _tabController;
final double _sliverAppBarInitHeight = 150.0;
final double _tabBarHeight = 50.0;
late double _sliverAppBarMaxHeight;
double? _sliverAppBarMaxHeight;
ShopScrollController? _listScrollController1;
late ShopScrollController _listScrollController2;
@@ -204,17 +204,17 @@ class ShopState extends State<Shop>
}
mediaQuery ??= MediaQuery.of(context);
screenWidth ??= mediaQuery.size.width;
screenHeight ??= mediaQuery.size.height;
statusBarHeight ??= mediaQuery.padding.top;
screenWidth ??= mediaQuery!.size.width;
screenHeight ??= mediaQuery!.size.height;
statusBarHeight ??= mediaQuery!.padding.top;
_sliverAppBarMaxHeight ??= screenHeight - 150.0;
_sliverAppBarMaxHeight ??= screenHeight! - 150.0;
_pageScrollController ??= _shopCoordinator
.pageScrollController(_sliverAppBarMaxHeight - _sliverAppBarInitHeight);
.pageScrollController(_sliverAppBarMaxHeight! - _sliverAppBarInitHeight);
_shopCoordinator.pinnedHeaderSliverHeightBuilder ??= () {
return statusBarHeight + kToolbarHeight + _tabBarHeight;
return statusBarHeight! + kToolbarHeight + _tabBarHeight;
};
refresh = false;
@@ -513,8 +513,8 @@ class ShopState extends State<Shop>
Positioned(
top: 0,
right: 0,
left: screenWidth - 100,
bottom: screenHeight - 100,
left: screenWidth! - 100,
bottom: screenHeight! - 100,
child: Image.asset(
'assets/images/under_renovation.png',
width: 200.0,
@@ -953,7 +953,7 @@ class ShopState extends State<Shop>
color: Colors.white,
)),
Container(
width: mediaQuery.size.width - 30.0,
width: mediaQuery!.size.width - 30.0,
padding: EdgeInsets.only(right: 10.0, bottom: 10.0),
child: new Text(
_business!.bulletin!.isEmpty ? '' : _business!.bulletin!,