【问题标题】:Why does my App look good in Emulator but not on the phone?为什么我的应用在模拟器中看起来不错,但在手机上却不行?
【发布时间】: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,
        ),
      ),
    );
  }
} 

【问题讨论】:

    标签: android flutter


    【解决方案1】:

    您可以使用响应式代码方法

    你可以搜索一下这个小部件

    MediaQuery.of(context)..
    Flexible(),
    Expanded(),
    Card()
    

    并且您的 Text() 小部件不会从屏幕或 listtile 溢出,您可以将 Card() 小部件包装在您的文本中

    【讨论】:

    • 不工作,我想一定是APK错误,因为debug App在手机上工作。
    猜你喜欢
    • 2020-09-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-03
    • 1970-01-01
    • 2023-03-10
    • 1970-01-01
    • 1970-01-01
    • 2017-09-13
    相关资源
    最近更新 更多