fix(runtime): 37 late fields with == null checks were wrongly migrated -> nullable. Fixes LateInitializationError crashes on page navigation (shop/checkout/comment/data pages)
This commit is contained in:
@@ -56,8 +56,8 @@ class ShopState extends State<Shop>
|
||||
|
||||
GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
|
||||
|
||||
late Business _business;
|
||||
late List<CategoryProducts> _categoryProducts;
|
||||
Business? _business;
|
||||
List<CategoryProducts>? _categoryProducts;
|
||||
late List<Product> _featuredProducts;
|
||||
late List<Product> _hotSaleProducts;
|
||||
|
||||
@@ -86,7 +86,7 @@ class ShopState extends State<Shop>
|
||||
final double _tabBarHeight = 50.0;
|
||||
late double _sliverAppBarMaxHeight;
|
||||
|
||||
late ShopScrollController _listScrollController1;
|
||||
ShopScrollController? _listScrollController1;
|
||||
late ShopScrollController _listScrollController2;
|
||||
late ShopScrollController _listScrollController3;
|
||||
|
||||
@@ -94,7 +94,7 @@ class ShopState extends State<Shop>
|
||||
GlobalKey stackKey = GlobalKey();
|
||||
GlobalKey endKey = GlobalKey();
|
||||
|
||||
late List<Comment> comments;
|
||||
List<Comment>? comments;
|
||||
int _commentPage = 1;
|
||||
int _commentPageCount = 1;
|
||||
bool _commentLoadingFinish = false;
|
||||
@@ -140,7 +140,7 @@ class ShopState extends State<Shop>
|
||||
'page': _commentPage.toString(),
|
||||
'size': Constants.ORDERS_PER_PAGE.toString(),
|
||||
},
|
||||
businessId: _business.id!,
|
||||
businessId: _business!.id!,
|
||||
).then((data) {
|
||||
if (isRefresh) {
|
||||
_commentRefreshController.refreshCompleted();
|
||||
@@ -226,7 +226,7 @@ class ShopState extends State<Shop>
|
||||
isDraggable: true,
|
||||
backdropEnabled: true,
|
||||
panel: ShoppingCartBar(
|
||||
business: _business,
|
||||
business: _business!,
|
||||
endKey: endKey,
|
||||
onEmptyCartListener: () {
|
||||
Future.delayed(Duration(seconds: 1), () {
|
||||
@@ -247,7 +247,7 @@ class ShopState extends State<Shop>
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: <Widget>[],
|
||||
);
|
||||
for (var i = 0; i < _business.promoProducts!.length; i++) {
|
||||
for (var i = 0; i < _business!.promoProducts!.length; i++) {
|
||||
promotRow.children.add(Container(
|
||||
padding: EdgeInsets.only(
|
||||
left: 10.0,
|
||||
@@ -286,17 +286,17 @@ class ShopState extends State<Shop>
|
||||
GestureDetector(
|
||||
child: Container(
|
||||
child: Util.showImage(
|
||||
_business.promoProducts![i].imagePath!,
|
||||
_business!.promoProducts![i].imagePath!,
|
||||
width: 110.0,
|
||||
),
|
||||
),
|
||||
onTap: () {
|
||||
_showProductDetail(_business.promoProducts![i]);
|
||||
_showProductDetail(_business!.promoProducts![i]);
|
||||
},
|
||||
),
|
||||
Container(
|
||||
child: Text(
|
||||
_business.promoProducts![i].name!,
|
||||
_business!.promoProducts![i].name!,
|
||||
maxLines: 2,
|
||||
overflow: TextOverflow.ellipsis,
|
||||
style: TextStyle(fontSize: 14.0),
|
||||
@@ -306,13 +306,13 @@ class ShopState extends State<Shop>
|
||||
mainAxisAlignment: MainAxisAlignment.spaceBetween,
|
||||
children: <Widget>[
|
||||
ShowPrice(
|
||||
_business.promoProducts![i].price!,
|
||||
_business!.promoProducts![i].price!,
|
||||
currencySign: '\$',
|
||||
regularPrice: _business.promoProducts![i].regularPrice,
|
||||
regularPrice: _business!.promoProducts![i].regularPrice,
|
||||
),
|
||||
Container(
|
||||
child: AddRemoveButton(
|
||||
product: _business.promoProducts![i],
|
||||
product: _business!.promoProducts![i],
|
||||
business: _business,
|
||||
addOnly: true,
|
||||
),
|
||||
@@ -392,7 +392,7 @@ class ShopState extends State<Shop>
|
||||
onTap: () {
|
||||
Navigator.push(context,
|
||||
MaterialPageRoute(builder: (BuildContext context) {
|
||||
return ProductSearch(_business);
|
||||
return ProductSearch(_business!);
|
||||
}));
|
||||
},
|
||||
),
|
||||
@@ -403,13 +403,13 @@ class ShopState extends State<Shop>
|
||||
child: new Icon(Icons.phone),
|
||||
onTap: () {
|
||||
Utils.launchURL(
|
||||
'tel:${Utils.getFirstNumberFromString(_business.phone!)}');
|
||||
'tel:${Utils.getFirstNumberFromString(_business!.phone!)}');
|
||||
},
|
||||
),
|
||||
),
|
||||
],
|
||||
title: Text(
|
||||
_business != null ? _business.name! : '',
|
||||
_business != null ? _business!.name! : '',
|
||||
style: TextStyle(
|
||||
color: Colors.white,
|
||||
),
|
||||
@@ -446,7 +446,7 @@ class ShopState extends State<Shop>
|
||||
Tab(
|
||||
child: Badge(
|
||||
badgeContent: Text(
|
||||
'${_business.commentsCount}',
|
||||
'${_business!.commentsCount}',
|
||||
style: TextStyle(color: Colors.white, fontSize: 11.0),
|
||||
),
|
||||
badgeStyle: BadgeStyle(badgeColor: Colors.lightBlueAccent),
|
||||
@@ -508,7 +508,7 @@ class ShopState extends State<Shop>
|
||||
|
||||
stack.children.addAll(children);
|
||||
|
||||
if (_business.isPublic != true) {
|
||||
if (_business!.isPublic != true) {
|
||||
stack.children.add(
|
||||
Positioned(
|
||||
top: 0,
|
||||
@@ -571,12 +571,12 @@ class ShopState extends State<Shop>
|
||||
Widget commentWidget = Center(
|
||||
child: Text(S.of(context).no_comments_yet),
|
||||
);
|
||||
if (comments != null && comments.length > 0) {
|
||||
if (comments != null && comments!.length > 0) {
|
||||
commentWidget = ListView.builder(
|
||||
controller: _listScrollController3,
|
||||
itemCount: comments.length,
|
||||
itemCount: comments!.length,
|
||||
itemBuilder: (BuildContext context, int position) {
|
||||
Comment comment = comments[position];
|
||||
Comment comment = comments![position];
|
||||
Row imageRow = Row(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
children: <Widget>[],
|
||||
@@ -772,18 +772,18 @@ class ShopState extends State<Shop>
|
||||
children: <Widget>[],
|
||||
);
|
||||
addressColumn.children.add(new Text(
|
||||
_business.address!.addressLine1! +
|
||||
(_business.address!.addressLine2!.isNotEmpty
|
||||
? ' ' + _business.address!.addressLine2!
|
||||
_business!.address!.addressLine1! +
|
||||
(_business!.address!.addressLine2!.isNotEmpty
|
||||
? ' ' + _business!.address!.addressLine2!
|
||||
: ''),
|
||||
style: new TextStyle(fontSize: 13.0, color: const Color(0xFFEEEEEE)),
|
||||
));
|
||||
addressColumn.children.add(new Text(
|
||||
_business.address!.city! +
|
||||
_business!.address!.city! +
|
||||
', ' +
|
||||
_business.address!.state! +
|
||||
_business!.address!.state! +
|
||||
', ' +
|
||||
_business.address!.zip!,
|
||||
_business!.address!.zip!,
|
||||
style: new TextStyle(fontSize: 13.0, color: const Color(0xFFEEEEEE)),
|
||||
));
|
||||
|
||||
@@ -793,23 +793,23 @@ class ShopState extends State<Shop>
|
||||
crossAxisAlignment: CrossAxisAlignment.center,
|
||||
children: <Widget>[],
|
||||
);
|
||||
if (_business.distanceInfo != null) {
|
||||
if (_business!.distanceInfo != null) {
|
||||
distanceRow.children.add(new Icon(
|
||||
Icons.directions_car,
|
||||
size: 14.0,
|
||||
color: Colors.white,
|
||||
));
|
||||
distanceRow.children.add(new Text(
|
||||
_business.distanceInfo!.distance != null
|
||||
? _business.distanceInfo!.distance!.text!
|
||||
_business!.distanceInfo!.distance != null
|
||||
? _business!.distanceInfo!.distance!.text!
|
||||
: '***' + ' / ',
|
||||
style: new TextStyle(color: const Color(0xFFEEEEEE), fontSize: 13.0),
|
||||
));
|
||||
var duration = Duration(
|
||||
seconds: (_business.distanceInfo!.duration != null
|
||||
? _business.distanceInfo!.duration!.value
|
||||
seconds: (_business!.distanceInfo!.duration != null
|
||||
? _business!.distanceInfo!.duration!.value
|
||||
: 30)! +
|
||||
_business.shippingTime! * 60);
|
||||
_business!.shippingTime! * 60);
|
||||
var hours = duration.inHours.remainder(60);
|
||||
var minutes = duration.inMinutes.remainder(60);
|
||||
distanceRow.children.add(new Text(
|
||||
@@ -825,7 +825,7 @@ class ShopState extends State<Shop>
|
||||
distanceRow.children.add(
|
||||
new Text(
|
||||
' / ' +
|
||||
S.of(context).min_order_amount_token(_business.minPrice!) +
|
||||
S.of(context).min_order_amount_token(_business!.minPrice!) +
|
||||
' ',
|
||||
style: new TextStyle(fontSize: 13.0, color: const Color(0xFFEEEEEE)),
|
||||
),
|
||||
@@ -853,7 +853,7 @@ class ShopState extends State<Shop>
|
||||
bottom: 0.0,
|
||||
child: GestureDetector(
|
||||
child: Util.showImage(
|
||||
'${_business.picUrl}',
|
||||
'${_business!.picUrl}',
|
||||
width: 72.0,
|
||||
height: 72.0,
|
||||
fit: BoxFit.fill,
|
||||
@@ -895,7 +895,7 @@ class ShopState extends State<Shop>
|
||||
color: Colors.white,
|
||||
),
|
||||
new Text(
|
||||
_business.phone!,
|
||||
_business!.phone!,
|
||||
style: new TextStyle(
|
||||
fontSize: 13.0, color: const Color(0xFFEEEEEE)),
|
||||
)
|
||||
@@ -910,9 +910,9 @@ class ShopState extends State<Shop>
|
||||
color: Colors.white,
|
||||
),
|
||||
new Text(
|
||||
_business.openingTime![0].openTime! +
|
||||
_business!.openingTime![0].openTime! +
|
||||
':00 - ' +
|
||||
_business.openingTime![0].closeTime! +
|
||||
_business!.openingTime![0].closeTime! +
|
||||
':00',
|
||||
style: new TextStyle(
|
||||
fontSize: 13.0, color: const Color(0xFFEEEEEE)),
|
||||
@@ -941,7 +941,7 @@ class ShopState extends State<Shop>
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
mainAxisSize: MainAxisSize.min,
|
||||
children: <Widget>[
|
||||
_business.bulletin!.isNotEmpty ? Row(
|
||||
_business!.bulletin!.isNotEmpty ? Row(
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: <Widget>[
|
||||
Container(
|
||||
@@ -956,7 +956,7 @@ class ShopState extends State<Shop>
|
||||
width: mediaQuery.size.width - 30.0,
|
||||
padding: EdgeInsets.only(right: 10.0, bottom: 10.0),
|
||||
child: new Text(
|
||||
_business.bulletin!.isEmpty ? '' : _business.bulletin!,
|
||||
_business!.bulletin!.isEmpty ? '' : _business!.bulletin!,
|
||||
softWrap: true,
|
||||
style: new TextStyle(
|
||||
fontSize: 12.0, color: const Color(0xFFDDDDDD)),
|
||||
@@ -965,7 +965,7 @@ class ShopState extends State<Shop>
|
||||
),
|
||||
],
|
||||
) : SizedBox.shrink(),
|
||||
_business.description!.isNotEmpty ? Column(
|
||||
_business!.description!.isNotEmpty ? Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -996,7 +996,7 @@ class ShopState extends State<Shop>
|
||||
padding:
|
||||
EdgeInsets.only(left: 10.0, right: 10.0, top: 5.0, bottom: 5.0),
|
||||
child: Text(
|
||||
_business.description!,
|
||||
_business!.description!,
|
||||
style: TextStyle(
|
||||
color: Colors.lightGreen,
|
||||
fontSize: 12.0,
|
||||
@@ -1009,7 +1009,7 @@ class ShopState extends State<Shop>
|
||||
padding: EdgeInsets.only(left: 10.0, right: 10.0, bottom: 10.0),
|
||||
child: slidingGellery,
|
||||
) : SizedBox.shrink(),
|
||||
_business.policy!.isNotEmpty ? Column(
|
||||
_business!.policy!.isNotEmpty ? Column(
|
||||
mainAxisAlignment: MainAxisAlignment.start,
|
||||
crossAxisAlignment: CrossAxisAlignment.start,
|
||||
children: [
|
||||
@@ -1040,7 +1040,7 @@ class ShopState extends State<Shop>
|
||||
padding: EdgeInsets.only(left: 10.0, right: 10.0, bottom: 10.0),
|
||||
child: SingleChildScrollView(
|
||||
child: Text(
|
||||
_business.policy!,
|
||||
_business!.policy!,
|
||||
softWrap: true,
|
||||
style: TextStyle(
|
||||
fontSize: 10.0,
|
||||
@@ -1062,7 +1062,7 @@ class ShopState extends State<Shop>
|
||||
right: 0,
|
||||
bottom: 0,
|
||||
child: Util.showImage(
|
||||
_business.bannerImageUrl!,
|
||||
_business!.bannerImageUrl!,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
@@ -1098,11 +1098,11 @@ class ShopState extends State<Shop>
|
||||
|
||||
List<Widget> _buildBanners(BuildContext context) {
|
||||
var pages = <Widget>[];
|
||||
for (var i = 0; i < _business.slideImages!.length; i++) {
|
||||
for (var i = 0; i < _business!.slideImages!.length; i++) {
|
||||
pages.add(new GestureDetector(
|
||||
child: new Container(
|
||||
child: Util.showImage(
|
||||
_business.slideImages![i].imageUrl!,
|
||||
_business!.slideImages![i].imageUrl!,
|
||||
fit: BoxFit.cover,
|
||||
),
|
||||
),
|
||||
@@ -1132,14 +1132,14 @@ class ShopState extends State<Shop>
|
||||
child: new ListView.builder(
|
||||
physics: ClampingScrollPhysics(),
|
||||
controller: _listScrollController2,
|
||||
itemCount: _categoryProducts == null ? 0 : _categoryProducts.length,
|
||||
itemCount: _categoryProducts == null ? 0 : _categoryProducts!.length,
|
||||
itemBuilder: (BuildContext context, int i) {
|
||||
CategoryProducts cp = _categoryProducts[i];
|
||||
CategoryProducts cp = _categoryProducts![i];
|
||||
int qtyInCategory = 0;
|
||||
CartInfo cartInfo =
|
||||
Utils.getCartInfoByBusiness(store.state.cartInfos, _business)!;
|
||||
Utils.getCartInfoByBusiness(store.state.cartInfos, _business!)!;
|
||||
if (cartInfo != null &&
|
||||
cartInfo.businessInfo!.id == _business.id &&
|
||||
cartInfo.businessInfo!.id == _business!.id &&
|
||||
cartInfo.productList != null) {
|
||||
for (var i = 0; i < cartInfo.productList!.length; i++) {
|
||||
if (cartInfo.productList![i].product!.categoryId == cp.id) {
|
||||
@@ -1213,21 +1213,21 @@ class ShopState extends State<Shop>
|
||||
}
|
||||
|
||||
void _selectCategory(int index) {
|
||||
if (displayProductByCategoryClick && _categoryProducts[index].id! > 0) {
|
||||
categoryId = _categoryProducts[index].id!;
|
||||
if (displayProductByCategoryClick && _categoryProducts![index].id! > 0) {
|
||||
categoryId = _categoryProducts![index].id!;
|
||||
loadProducts();
|
||||
return;
|
||||
}
|
||||
double height = 0.0;
|
||||
for (int i = 0; i < index; ++i) {
|
||||
height += _categoryDescHeight +
|
||||
_categoryProducts[i].products!.length * _productHeight;
|
||||
_categoryProducts![i].products!.length * _productHeight;
|
||||
}
|
||||
if (height > _listScrollController1.position.maxScrollExtent) {
|
||||
height = _listScrollController1.position.maxScrollExtent;
|
||||
if (height > _listScrollController1!.position.maxScrollExtent) {
|
||||
height = _listScrollController1!.position.maxScrollExtent;
|
||||
}
|
||||
_categoryIndexChange = true;
|
||||
_listScrollController1
|
||||
_listScrollController1!
|
||||
.animateTo(height,
|
||||
duration: new Duration(
|
||||
microseconds: 200,
|
||||
@@ -1237,7 +1237,7 @@ class ShopState extends State<Shop>
|
||||
_categoryIndexChange = false;
|
||||
});
|
||||
print(
|
||||
'height: $height, index: $index, ${_categoryProducts[0].products!.length}');
|
||||
'height: $height, index: $index, ${_categoryProducts![0].products!.length}');
|
||||
if (mounted) {
|
||||
setState(() {
|
||||
_categoryIndex = index;
|
||||
@@ -1246,7 +1246,7 @@ class ShopState extends State<Shop>
|
||||
}
|
||||
|
||||
CategoryProducts? getCategoryProductByCategoryId(int cid) {
|
||||
for (CategoryProducts cp in _categoryProducts) {
|
||||
for (CategoryProducts cp in _categoryProducts!) {
|
||||
if (cp.id == cid) {
|
||||
return cp;
|
||||
}
|
||||
@@ -1256,8 +1256,8 @@ class ShopState extends State<Shop>
|
||||
|
||||
void _resetProductListScroll() {
|
||||
if (_listScrollController1 != null &&
|
||||
_listScrollController1.positions.isNotEmpty) {
|
||||
_listScrollController1.animateTo(
|
||||
_listScrollController1!.positions.isNotEmpty) {
|
||||
_listScrollController1!.animateTo(
|
||||
0,
|
||||
duration: new Duration(
|
||||
microseconds: 200,
|
||||
@@ -1270,9 +1270,9 @@ class ShopState extends State<Shop>
|
||||
int _getCategoryIndexByRightScrollHeight(double height) {
|
||||
double cHeight = 0.0;
|
||||
if (height > 0) {
|
||||
for (int i = 0; i < _categoryProducts.length; ++i) {
|
||||
for (int i = 0; i < _categoryProducts!.length; ++i) {
|
||||
double categoryHeight = _categoryDescHeight +
|
||||
_categoryProducts[i].products!.length * _productHeight;
|
||||
_categoryProducts![i].products!.length * _productHeight;
|
||||
if (height >= cHeight && height < cHeight + categoryHeight) {
|
||||
return i;
|
||||
}
|
||||
@@ -1280,7 +1280,7 @@ class ShopState extends State<Shop>
|
||||
}
|
||||
}
|
||||
if (height > cHeight) {
|
||||
return _categoryProducts.length - 1;
|
||||
return _categoryProducts!.length - 1;
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
@@ -1310,7 +1310,7 @@ class ShopState extends State<Shop>
|
||||
|
||||
int numCategoriesHasProducts() {
|
||||
int num = 0;
|
||||
for (CategoryProducts cp in _categoryProducts) {
|
||||
for (CategoryProducts cp in _categoryProducts!) {
|
||||
if (cp.products!.length > 0) {
|
||||
num += 1;
|
||||
}
|
||||
@@ -1340,21 +1340,21 @@ class ShopState extends State<Shop>
|
||||
_categoryProducts == null ? 0 : numCategoriesHasProducts(),
|
||||
itemBuilder: (BuildContext context, int i) {
|
||||
CategoryProducts cp;
|
||||
cp = _categoryProducts[i];
|
||||
cp = _categoryProducts![i];
|
||||
|
||||
int index = -1;
|
||||
if (displayProductByCategoryClick) {
|
||||
if (categoryId > 0) {
|
||||
for (var j = 0; j < _categoryProducts.length; j++) {
|
||||
if (_categoryProducts[j].id == categoryId) {
|
||||
cp = _categoryProducts[j];
|
||||
for (var j = 0; j < _categoryProducts!.length; j++) {
|
||||
if (_categoryProducts![j].id == categoryId) {
|
||||
cp = _categoryProducts![j];
|
||||
index = j;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (cp == null) {
|
||||
index = 0;
|
||||
cp = _categoryProducts[0];
|
||||
cp = _categoryProducts![0];
|
||||
}
|
||||
}
|
||||
WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
|
||||
@@ -1424,7 +1424,7 @@ class ShopState extends State<Shop>
|
||||
pStack.children.add(Container(
|
||||
// width: MediaQuery.of(context).size.width - 100.0,
|
||||
child: ProductItem(
|
||||
p, _business,
|
||||
p, _business!,
|
||||
horizontal: true,
|
||||
imageWidth: 80.0,
|
||||
),
|
||||
@@ -1498,9 +1498,9 @@ class ShopState extends State<Shop>
|
||||
_listScrollController2 = _shopCoordinator.newChildScrollController();
|
||||
_listScrollController3 = _shopCoordinator.newChildScrollController();
|
||||
|
||||
_listScrollController1.addListener(() {
|
||||
if (_listScrollController1.position.atEdge) {
|
||||
if (_listScrollController1.position.pixels == 0) {
|
||||
_listScrollController1!.addListener(() {
|
||||
if (_listScrollController1!.position.atEdge) {
|
||||
if (_listScrollController1!.position.pixels == 0) {
|
||||
print('product list at top');
|
||||
} else {
|
||||
print('product list at bottom');
|
||||
@@ -1567,7 +1567,7 @@ class ShopState extends State<Shop>
|
||||
'',
|
||||
'',
|
||||
_hotSaleProducts);
|
||||
_categoryProducts.insert(0, hs);
|
||||
_categoryProducts!.insert(0, hs);
|
||||
}
|
||||
|
||||
if (_featuredProducts.length > 0) {
|
||||
@@ -1578,7 +1578,7 @@ class ShopState extends State<Shop>
|
||||
'',
|
||||
'',
|
||||
_featuredProducts);
|
||||
_categoryProducts.insert(0, fe);
|
||||
_categoryProducts!.insert(0, fe);
|
||||
}
|
||||
|
||||
checkActionAndClose(context);
|
||||
|
||||
Reference in New Issue
Block a user