【发布时间】:2022-01-23 06:49:36
【问题描述】:
所以这是我第一个使用 Flutter 的项目。我对项目进行了编码,一切都很好,但是当我为我的手机导出 apk 时,该应用程序看起来很垃圾且无法使用。 The whole project on github
这就是我的应用在我的手机 (Galaxy S21) 上的外观looks on my phone
这就是代码在 Android Emulator(Pixel 3a) looks on the emulator上的样子
我知道有不同的屏幕尺寸,但我认为这是另一个我不明白的问题。 那是我的 main.dart 代码: 我真的不知道为什么我的应用在 android Emulator 中看起来不错,但在我的 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,
),
),
);
}
}
【问题讨论】: