i’m trying to build a release version of my flutter app using the cmd flutter build apk
, the problem is that one page does not show any content. In the debug version it all works fine, but in the release version that page does not work properly.
The 2 images below show the output for the 2 versions.
Debug version:
Release version:
Code of the page in which the bug occurs:
class ProductListPage extends StatefulWidget {
ProductListPage(
{Key? key,
Title? title,
required this.subCatId,
required this.subCatName})
: super(key: key);
final String title = '';
static const String page_id = 'Product List';
int subCatId;
String subCatName;
@override
State<ProductListPage> createState() => _ProductListPageState();
}
class _ProductListPageState extends State<ProductListPage> {
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.white,
appBar: AppBar(
elevation: 0,
backgroundColor: Colors.white,
automaticallyImplyLeading: true,
iconTheme: IconThemeData(color: style.appColor),
title: Text(widget.subCatName),
centerTitle: false,
titleTextStyle: style.pageTitle(),
actions: [
IconButton(onPressed: () {}, icon: Icon(Icons.search)),
IconButton(onPressed: () {}, icon: Icon(Icons.share_outlined))
],
),
body:
_buildBody(), // This trailing comma makes auto-formatting nicer for build methods.
);
}
Widget _buildBody() {
return SingleChildScrollView(
child: Container(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
decoration: style.bottomBorder(),
child: Row(
children: [
Expanded(
child: ElevatedButton.icon(
onPressed: () {},
icon: Icon(Icons.filter_alt_outlined),
label: Text('Filter'),
style: simpleButton(),
)),
Expanded(
child: ElevatedButton.icon(
onPressed: () {},
icon: Icon(Icons.sort_outlined),
label: Text('Sort'),
style: simpleButton(),
)),
],
),
),
GetBuilder<ProductsController>(builder: (prodsBySub) {
Get.find<ProductsController>()
.getProductsBySubCategory(widget.subCatId);
return GridView.count(
crossAxisCount: 2,
shrinkWrap: true,
physics: ScrollPhysics(),
mainAxisSpacing: 16,
crossAxisSpacing: 16,
childAspectRatio: 70 / 100,
padding: EdgeInsets.all(16),
children: List.generate(
prodsBySub.productsListBySubCategory.length, (index) {
return _buildSingleProduct(
index,
ProductModel.fromJson(
prodsBySub.productsListBySubCategory[index]));
}),
);
})
],
),
),
);
}
Widget _buildSingleProduct(int position, ProductModel product) {
return InkWell(
onTap: () {
Get.toNamed(RouteHelper.getProduct(position, product.id));
},
child: Container(
width: double.infinity,
height: double.infinity,
padding: EdgeInsets.all(8),
decoration: style.shadowContainer(),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Container(
width: double.infinity,
height: 140,
decoration: BoxDecoration(
image: DecorationImage(
image: AssetImage('assets/images/mango.png'),
fit: BoxFit.contain)),
),
SizedBox(height: 8),
Text(
product.title,
style: TextStyle(fontSize: 14, fontFamily: 'medium'),
),
Text(
'50g/pack',
style: TextStyle(fontSize: 13, color: Colors.grey),
),
SizedBox(height: 8),
Row(
children: [
Expanded(
child: Row(
children: [
Container(
padding: EdgeInsets.symmetric(horizontal: 6, vertical: 1),
margin: EdgeInsets.only(right: 8),
decoration: style.offContainer(),
child: Text('10%', style: style.offLabel()),
),
Text(
'${product.price} €',
style: TextStyle(fontSize: 16, fontFamily: 'medium'),
),
],
)),
Container(
height: 30,
width: 30,
decoration: BoxDecoration(
borderRadius: BorderRadius.all(Radius.circular(5)),
color: style.appColor),
child: Icon(Icons.add, color: Colors.white),
),
],
),
],
),
),
);
}
simpleButton() {
return ElevatedButton.styleFrom(
onPrimary: Colors.grey,
padding: EdgeInsets.symmetric(vertical: 12),
elevation: 0,
primary: Colors.transparent);
}
}
I have tried some solutions found on the internet like adding Internet permission for the APIs, or editing the build.gradle file. None of these solutions worked for me. I would love to get some help, thanks in advance.
2
Answers
Solved it thanks to @Amanpreet Kaur's comment, actually I used flutter run --release and it showed me where the error was located, fixed it and it's all good now!
just add expanded around the gridview and everything is work