Flutter Release版本页面内容不显示问题求助
Flutter Release版本商品列表页面空白,Debug版本正常
使用flutter build apk构建Flutter应用的Release版本时,发现商品列表页面无法显示任何内容,但Debug版本运行完全正常。
版本效果对比
- Debug版本:

- Release版本:

问题页面代码
class ProductListPage extends Stateful Widget { 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); } }
已尝试的解决方案
- 为API请求添加网络权限
- 修改build.gradle配置
以上方案均未解决问题,希望得到帮助。
内容的提问来源于stack exchange,提问作者Fedy Belaid
相关产品推荐
相关产品推荐

