[英]Why does my App look good in Emulator but not on the phone?
所以这是我第一个使用 flutter 的项目。 我对项目进行了编码,一切都很好,但是当我为我的手机导出 apk 时,该应用程序看起来很垃圾且无法使用。 github上的整个项目
这就是我的应用在我的手机上的外观(Galaxy S21)在我的手机上的外观
这是代码在 Android 仿真器(像素 3a)上的外观
我知道有不同的屏幕尺寸,但我认为这是另一个我不明白的问题。 那是我的主要代码。dart 代码:我真的不知道为什么我的应用程序在 android 模拟器中看起来不错,但在我的 Galaxy S21 上却是垃圾。
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: StreamBuilder<QuerySnapshot>(
stream:
FirebaseFirestore.instance.collection("Einkaufsliste").snapshots(),
builder: (context, snapshot) {
if (snapshot.hasError) {
return const Text('Etwas ist schief gelaufen!');
} else if (snapshot.hasData || snapshot.data != null) {
return ListView.builder(
shrinkWrap: true,
itemCount: snapshot.data?.docs.length,
itemBuilder: (BuildContext context, int index) {
QueryDocumentSnapshot<Object?>? documentSnapshot =
snapshot.data?.docs[index];
return Dismissible(
key: Key(index.toString()),
child: Card(
elevation: 4,
child: ListTile(
title: Text((documentSnapshot != null)
? (documentSnapshot["todoTitle"])
: ""),
subtitle: Text((documentSnapshot != null)
? ((documentSnapshot["todoDesc"] != null)
? documentSnapshot["todoDesc"]
: "")
: ""),
trailing: Wrap(
children: <Widget>[
Text((documentSnapshot != null)
? ((documentSnapshot["todoStatus"] != null)
? documentSnapshot["todoStatus"]
: "")
: ""),
const Spacer(),
IconButton(
icon: const Icon(Icons.edit),
color: Colors.blue,
onPressed: () {
if (documentSnapshot != null) {
title_edit = documentSnapshot["todoTitle"];
subtitle_edit =
documentSnapshot["todoDesc"];
status_edit =
documentSnapshot["todoStatus"];
deleteTodo((documentSnapshot != null)
? (documentSnapshot["todoTitle"])
: "");
}
MaterialPageRoute materialPageRoute =
MaterialPageRoute(
builder: (context) => edit_product(),
);
Navigator.of(context).push(materialPageRoute);
},
),
IconButton(
icon: const Icon(Icons.delete),
color: Colors.red,
onPressed: () {
setState(() {
deleteTodo((documentSnapshot != null)
? (documentSnapshot["todoTitle"])
: "");
});
},
),
],
),
),
));
});
}
return const Center(
child: CircularProgressIndicator(
valueColor: AlwaysStoppedAnimation<Color>(
Colors.red,
),
),
);
},
),
floatingActionButton: FloatingActionButton(
onPressed: () {
MaterialPageRoute materialPageRoute = MaterialPageRoute(
builder: (context) => product(),
);
Navigator.of(context).push(materialPageRoute);
},
child: const Icon(
Icons.add,
color: Colors.white,
),
),
);
}
}
您可以使用响应式代码方法
你可以搜索一下这个小部件
MediaQuery.of(context)..
Flexible(),
Expanded(),
Card()
并且您的 Text() 小部件不会从屏幕或列表中溢出,您可以包装 Card() 小部件您的文本
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.