flutter - 应用程序在连接的真实设备上工作,但不是 APK
问题描述
以下布局在连接的真实设备上运行良好:
但是在构建的 apk 上运行时,它显示以下内容:
我无法找出问题所在,因为它在真实设备上运行应用程序时没有显示错误或警告。有没有办法调试APK?
如果我注释掉 Gridview.builder,则 apk 的工作方式与真实设备上的相同。
这是我实现的代码:
Container myArticles(String imageVal,int index,String univid)
{
return Container(
child:Align(
alignment: Alignment.center,
child: Card(
child:Container(
child: FlatButton(
color: Colors.white,
splashColor: Colors.white,
child:Stack(
children: <Widget>[
Image.asset(imageVal),
Positioned(
top: 120,
left: 8,
child: Center(
child:Container(
width: 130,
child: Text(widget.data[index]["subject_name"],
textAlign: TextAlign.center,
style: TextStyle(
fontSize: 11.0,
fontWeight: FontWeight.bold,
),
),
),
),
),
Positioned(
top: 160,
left: 40,
child: Center(
child: Text("₹"+widget.data[index]["price"],
style: TextStyle(
fontSize: 20.0,
color: Colors.white,
),
),
),
),
],
),
onPressed: ()async {}
},
),
),
),
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: Colors.deepPurple,
body: ListView(
children:<Widget>[
Column(
children: <Widget>[
Column(
children: <Widget>[
Padding(
padding: const EdgeInsets.fromLTRB(0, 10, 100, 0),
child: Container(
padding: EdgeInsets.fromLTRB(0, 30,200,0),
child: IconButton(icon: Icon(Icons.arrow_back,),
color: Colors.black,
onPressed: () {
Navigator.pop(context);
},
),
),
),
SizedBox(height: 20,),
Text('Semester '+ widget.id,
style: TextStyle(color: Colors.white,
fontSize: 35),
),
SizedBox(height: 25,),
Text('Subjects: '+widget.subcount,
style: TextStyle(color: Colors.white,
fontSize: 17),
),
],
),
SizedBox(height: 40,),
Container(
height: MediaQuery.of(context).size.height - 185,
decoration: BoxDecoration(
color: Colors.white,
borderRadius: BorderRadius.only(topLeft: Radius.circular(75.0)),
),
child: Padding(
padding: const EdgeInsets.fromLTRB(0,100,0,50),
child: Expanded(
child: GridView.builder(
physics: ScrollPhysics(),
itemCount: widget.data.length,
shrinkWrap: true,
scrollDirection: Axis.vertical,
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
crossAxisCount: 2,
),
itemBuilder: (BuildContext context, int index){
return Container(
child: myArticles("assets/NewSub/1.png",index,widget.data[index]["univ_spec_sub_id"].toString()),
);
},
),
),
),
),
],
),
],
),
);
}
}
解决方案
构建 apk 后,将其安装在真正的 android 设备中。您仍然可以看到应用程序日志。希望您已正确设置所有 adb 和 sdk(因为您可以在构建时在设备上运行应用程序)按照以下步骤调试 apk。
- 在设备上安装 apk
- 打开应用程序
- 使用 USB 将设备连接到您的系统(用于构建颤振应用程序)。
- 打开你的控制台
- 类型
flutter logs
- 您将在您的 Android 设备上看到来自任何 Flutter 运行应用程序的所有日志。
这不会解决您的列表视图不显示问题,但会让您查看所有日志,了解您为什么无法看到列表,而不是从日志中找出错误所在。
推荐阅读
- woocommerce - Woo Commerce 产品页面更改了布局
- php - CakePHP 4 - 烘烤不会让我使用不同的数据库连接到“默认”
- flutter - 如何在 Flutter 上排列像“May June July August ..”这样的月份?
- jira - 使用来自另一台服务器的 Jira Rest API
- javascript - 在一个特定文件夹的 node_modules 中运行 eslint loader,该文件夹是 npm 链接且未编译的
- firebase - FieldValue.increment 的 Firestore 安全规则
- python - 带有 Python 客户端的 Soap PHP 服务器
- firebase - ML Vision 文本无法纵向工作
- reactjs - 在 React 中渲染嵌套的 JSON 项目
- linux - linux命令中的方括号后跟感叹号是什么意思?