【问题标题】:FLUTTER: Displaying problem between IOS and ANDROIDFLUTTER:在 IOS 和 ANDROID 之间显示问题
【发布时间】:2020-05-14 18:05:07
【问题描述】:

我做了一个应用程序,但我遇到了问题,我在 ios 和 android 上运行了该应用程序,但是一个屏幕不是我想要的,我在SizedBox 中的所有孩子都没有完全显示(仅在 IOS 上),我认为是 IOS 中 Sizedbox 的问题,但我不知道如何解决它。 我尝试使用其他小部件,但没有一个可以工作。

    Widget build(BuildContext context) {
    return Scaffold(
        backgroundColor: Theme.of(context).backgroundColor,
        body: StreamBuilder(
          stream: Firestore.instance
              .collection('rooms')
              .document(pincode)
              .snapshots(),
          builder: (BuildContext context, AsyncSnapshot snapshot) {
            if (snapshot.hasData) {
              int result =
                  snapshot.data['Votes'][0] - snapshot.data['Votes'][1];
              if (result <= 0)
                perdantID = snapshot.data['Nominés'][1];
              else
                perdantID = snapshot.data['Nominés'][0];
              leperdant = perdantID;
              if (snapshot.data['nb screen'] == 2 && gotdata == 0) {
                gotdata++;
                gonext(context, perdantID);
              }
              return Center(
                child: FutureBuilder(
                  future: Firestore.instance
                      .collection('rooms')
                      .document(pincode)
                      .collection('users')
                      .document(perdantID)
                      .get(),
                  builder: (BuildContext context, AsyncSnapshot snapshot) {
                    if (snapshot.hasData) {
                      var prenomperdant = snapshot.data['prénom'];
                      return Center(
                          child: Column(
                        children: <Widget>[
                          SizedBox(height: 30),
                          Text('$prenomperdant',
                              style: TextStyle(fontSize: 50)),
                          Padding(
                            padding: const EdgeInsets.fromLTRB(80, 0, 0, 0),
                            child: Text(' $subquestion',
                                style: TextStyle(fontSize: 35)),
                          ),
                          StreamBuilder(
                            stream: Firestore.instance
                                .collection('rooms')
                                .document(pincode)
                                .collection('users')
                                .snapshots(),
                            builder: (BuildContext context,
                                AsyncSnapshot<QuerySnapshot> snapshot) {
                              if (snapshot.hasData) {
                                return Column(
                                  children: <Widget>[
                                    SizedBox(
                                      height: 140,
                                      child: GridView.count(
                                          crossAxisCount: 2,
                                          children: snapshot.data.documents.map(
                                              (DocumentSnapshot document) {
                                            if (document['id'] == nomines[0] ||
                                                document['id'] == nomines[1])
                                              return Container(
                                                child: OvalPic(
                                                    document['photo'],
                                                    document['couleur']),
                                              );
                                            else
                                              return null;
                                          }).toList()
                                            ..removeWhere((el) => el == null)),
                                    ),
                                    SizedBox(
                                        height: 190,
                                        child: GridView.count(
                                          crossAxisCount: 2,
                                          children: <Widget>[
                                            ListView.builder(
                                              physics:
                                                  NeverScrollableScrollPhysics(),
                                              itemCount: nbvotes[0],
                                              reverse: true,
                                              itemBuilder:
                                                  (BuildContext context,
                                                      int index) {
                                                return Align(
                                                    alignment: Alignment.center,
                                                    heightFactor: 0.94,
                                                    child: Image(
                                                      image: AssetImage(
                                                          'assets/images/results/green.png'),
                                                    ));
                                              },
                                            ),
                                            ListView.builder(
                                              physics:
                                                  NeverScrollableScrollPhysics(),
                                              itemCount: nbvotes[1],
                                              reverse: true,
                                              itemBuilder:
                                                  (BuildContext context,
                                                      int index) {
                                                return Align(
                                                    alignment: Alignment.center,
                                                    heightFactor: 0.94,
                                                    child: Image(
                                                      image: AssetImage(
                                                          'assets/images/results/green.png'),
                                                    ));
                                              },
                                            ),
                                          ],
                                        )),
                                  ],
                                );
                              } else
                                return CircularProgressIndicator();
                            },
                          ),
                          (perdantID == nameid)
                              ? Column(
                                  children: <Widget>[
                                    rbutton(mygreen, 'PASSER AU DEFI', context,
                                        perdantID, ledefi),
                                    SizedBox(height: 5),
                                    Text('OU'),
                                    SizedBox(height: 5),
                                    rbutton(mypink, 'BOIRE', context, perdantID,
                                        legage),
                                  ],
                                )
                              : SizedBox(height: 1)
                        ],
                      ));
                    } else
                      return Center(child: CircularProgressIndicator());
                  },
                ),
              );
            } else
              return Center(child: CircularProgressIndicator());
          },
        ));
  }
}

【问题讨论】:

    标签: android ios flutter widget


    【解决方案1】:

    尝试使用

    ConstrainedBox(
      constraints: const BoxConstraints(minHeight: 140),
      child:GridView....,
    )
    

    而不是

    SizedBox(
       height: 190,
       child: GridView...
    )
    

    【讨论】:

      猜你喜欢
      • 2018-03-29
      • 2022-06-20
      • 2013-10-05
      • 1970-01-01
      • 2023-02-02
      • 2020-12-21
      • 1970-01-01
      • 1970-01-01
      • 2021-01-13
      相关资源
      最近更新 更多