-1

我正在尝试使用flutter中的future builder构建一个列表,我成功了。但是现在列表没有滚动,当我们滚动侧面周围的小空间(图像中显示的深色肤色)时,它会滚动并显示完整的列表不会从其他任何地方滚动。 屏幕截图

如屏幕截图所示,当您尝试向下滚动时,它不会执行任何操作,但当我将鼠标放在容器两侧(较深的白色肤色)时,它会滚动浏览所有列表。

完整的代码。

Scaffold(
  backgroundColor: Color.fromRGBO(242, 242, 242, 1),
  appBar: AppBar(
    backgroundColor: Color(0xFF000080),
    title: Text(
      'Medication List',
      style: TextStyle(
          fontSize: 20,
          color: Colors.grey[100],
          fontWeight: FontWeight.w600),
    ),
    leading: IconButton(
      onPressed: () {
        Navigator.pop(context);
      },
      icon: Icon(
        Icons.arrow_back_ios,
        color: Colors.grey[100],
      ),
    ),
    actions: [
      FlatButton(
        onPressed: () {
          vari.medication = Medication();
          Navigator.push(
              context,
              MaterialPageRoute(
                  builder: (context) => ListNew(
                        decision: widget.decison,
                      ))).then((value) {
            if (widget.decison == false) {
              setState(() {
                medicationList = vari.database.listFromAllMedication();
              });
            } else {
              setState(() {
                medicationList =
                    vari.database.listFromMedication(vari.member);
              });
            }
          });
        },
        child: Text(
          'NEW',
          style: TextStyle(fontSize: 16, color: Colors.grey[100]),
        ),
      ),
      PopupMenuButton<String>(
        itemBuilder: (context) => [
          PopupMenuItem(
            value: '1',
            child: Text("List by Physician"),
          ),
          PopupMenuItem(
            value: '2',
            child: Text("List all Meds"),
          ),
          PopupMenuItem(
            value: '3',
            child: Text("Send List"),
          ),
        ],
        onSelected: (value) async => {
          if (value == '1')
            {
              Navigator.push(context,
                  MaterialPageRoute(builder: (context) => PhysicianList()))
            }
          else if (value == '2')
            {
              if (widget.decison == false)
                {
                  setState(() {
                    medicationList = vari.database.listFromAllMedication();
                  })
                }
              else
                {
                  setState(() {
                    medicationList =
                        vari.database.listFromMedication(vari.member);
                  })
                }
            }
          else if (value == '3')
            {writeMedication()}
        },
      ),
    ],
  ),
  body: SingleChildScrollView(
    child: Container(
      child: widget.decison == true
          ? Column(
              children: [
                Center(
                  child: Padding(
                    padding: EdgeInsets.only(
                      top: 10,
                    ),
                    child: Text(
                      familymember,
                      style: TextStyle(
                        fontSize: 28,
                        color: Colors.grey[700],
                      ),
                    ),
                  ),
                ),
                Container(
                    margin: EdgeInsets.symmetric(
                      vertical: 10,
                      horizontal: w * 0.07,
                    ),
                    child: Divider(
                      color: Color(0xFF000080),
                      thickness: 2,
                    )),
                SizedBox(
                  height: 20,
                ),
                Container(
                  width: MediaQuery.of(context).size.width * 0.9,
                  margin: EdgeInsets.only(top: 20),
                  child: FutureBuilder(
                      future: medicationList,
                      builder: (BuildContext context,
                          AsyncSnapshot<List> snapshot) {
                        if (!snapshot.hasData) return Text("");
                        return Container(
                          //height: 225 * snapshot.data.length.toDouble(),
                          child: ListView.builder(
                              scrollDirection: Axis.vertical,
                              shrinkWrap: true,
                              itemCount: snapshot.data.length,
                              itemBuilder: (context, index) {
                                return Container(
                                  child: InkWell(
                                    onTap: () {
                                      vari.medication =
                                          snapshot.data[index];
                                      if (vari.medication.medImage == '') {
                                        vari.medication.medImage = null;
                                      }
                                      if (vari.medication.presImage == '') {
                                        vari.medication.presImage = null;
                                      }
                                      Navigator.push(
                                          context,
                                          MaterialPageRoute(
                                              builder: (context) => ListNew(
                                                    decision:
                                                        widget.decison,
                                                  ))).then((value) {
                                        if (widget.decison == false) {
                                          setState(() {
                                            medicationList = vari.database
                                                .listFromAllMedication();
                                          });
                                        } else {
                                          setState(() {
                                            medicationList = vari.database
                                                .listFromMedication(
                                                    vari.member);
                                          });
                                        }
                                      });
                                    },
                                    child: Card(
                                      child: Padding(
                                        padding: const EdgeInsets.all(15),
                                        child: Column(
                                          mainAxisAlignment:
                                              MainAxisAlignment.start,
                                          crossAxisAlignment:
                                              CrossAxisAlignment.start,
                                          children: [
                                            Row(
                                              mainAxisAlignment:
                                                  MainAxisAlignment.start,
                                              children: [
                                                Text('Generic: '),
                                                Text(
                                                  '${snapshot.data[index].genName}',
                                                  style: TextStyle(
                                                      fontSize: 16,
                                                      color: Color(
                                                          0xff031e41)),
                                                ),
                                              ],
                                            ),
                                            SizedBox(
                                              height: 5,
                                            ),
                                            Row(
                                              mainAxisAlignment:
                                                  MainAxisAlignment.start,
                                              children: [
                                                Text('Brand: '),
                                                Text(
                                                  '${snapshot.data[index].mfgName}',
                                                  style: TextStyle(
                                                      fontSize: 16,
                                                      color: Color(
                                                          0xff031e41)),
                                                ),
                                              ],
                                            ),
                                            SizedBox(
                                              height: 5,
                                            ),
                                            Row(
                                              mainAxisAlignment:
                                                  MainAxisAlignment.start,
                                              children: [
                                                Text('Strength: '),
                                                Text(
                                                  '${snapshot.data[index].strength} ${snapshot.data[index].unit}',
                                                  style: TextStyle(
                                                      fontSize: 16,
                                                      color: Color(
                                                          0xff031e41)),
                                                ),
                                              ],
                                            ),
                                            SizedBox(
                                              height: 5,
                                            ),
                                            Row(
                                              mainAxisAlignment:
                                                  MainAxisAlignment.start,
                                              children: [
                                                Text('Qty: '),
                                                Text(
                                                  '${snapshot.data[index].quantity}',
                                                  style: TextStyle(
                                                      fontSize: 16,
                                                      color: Color(
                                                          0xff031e41)),
                                                ),
                                              ],
                                            ),
                                            SizedBox(
                                              height: 5,
                                            ),
                                            Row(
                                              mainAxisAlignment:
                                                  MainAxisAlignment.start,
                                              children: [
                                                Text('Route: '),
                                                Text(
                                                  '${snapshot.data[index].route}',
                                                  style: TextStyle(
                                                      fontSize: 16,
                                                      color: Color(
                                                          0xff031e41)),
                                                ),
                                              ],
                                            ),
                                            SizedBox(
                                              height: 5,
                                            ),
                                            Row(
                                              mainAxisAlignment:
                                                  MainAxisAlignment.start,
                                              children: [
                                                Text('Form: '),
                                                Text(
                                                  '${snapshot.data[index].form}',
                                                  style: TextStyle(
                                                      fontSize: 16,
                                                      color: Color(
                                                          0xff031e41)),
                                                ),
                                              ],
                                            ),
                                            SizedBox(
                                              height: 5,
                                            ),
                                            Row(
                                              mainAxisAlignment:
                                                  MainAxisAlignment.start,
                                              children: [
                                                Text('Family Member: '),
                                                AutoSizeText(
                                                  '${snapshot.data[index].memberStr}',
                                                  maxLines: 1,
                                                  style: TextStyle(
                                                      fontSize: 16,
                                                      color: Color(
                                                          0xff031e41)),
                                                ),
                                              ],
                                            ),
                                            Row(
                                              mainAxisAlignment:
                                                  MainAxisAlignment.start,
                                              children: [
                                                Text('Physician: '),
                                                AutoSizeText(
                                                  '${snapshot.data[index].physicianStr}',
                                                  maxLines: 1,
                                                  style: TextStyle(
                                                      fontSize: 16,
                                                      color: Color(
                                                          0xff031e41)),
                                                ),
                                              ],
                                            ),
                                          ],
                                        ),
                                      ),
                                    ),
                                  ),
                                );
                              }),
                        );
                      }),
                ),
              ],
            )
          : Center(
              child: Container(
                width: MediaQuery.of(context).size.width * 0.9,
                margin: EdgeInsets.only(top: 20),
                child: FutureBuilder(
                    future: medicationList,
                    builder: (BuildContext context,
                        AsyncSnapshot<List> snapshot) {
                      if (!snapshot.hasData) return Text("");
                      return Container(
                        //height: 225 * snapshot.data.length.toDouble(),
                        child: ListView.builder(
                            shrinkWrap: true,
                            scrollDirection: Axis.vertical,
                            itemCount: snapshot.data.length,
                            itemBuilder: (context, index) {
                              return InkWell(
                                onTap: () {
                                  vari.medication = snapshot.data[index];
                                  Navigator.push(
                                      context,
                                      MaterialPageRoute(
                                          builder: (context) => ListNew(
                                                decision: widget.decison,
                                              ))).then((value) {
                                    if (widget.decison == false) {
                                      setState(() {
                                        medicationList = vari.database
                                            .listFromAllMedication();
                                      });
                                    } else {
                                      setState(() {
                                        medicationList = vari.database
                                            .listFromMedication(
                                                vari.member);
                                      });
                                    }
                                  });
                                },
                                child: Card(
                                  child: Padding(
                                    padding: const EdgeInsets.all(15),
                                    child: Column(
                                      mainAxisAlignment:
                                          MainAxisAlignment.start,
                                      crossAxisAlignment:
                                          CrossAxisAlignment.start,
                                      children: [
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.start,
                                          children: [
                                            Text('Generic: '),
                                            Text(
                                              '${snapshot.data[index].genName}',
                                              style: TextStyle(
                                                  fontSize: 16,
                                                  color: Color(0xff031e41)),
                                            ),
                                          ],
                                        ),
                                        SizedBox(
                                          height: 5,
                                        ),
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.start,
                                          children: [
                                            Text('Brand: '),
                                            Text(
                                              '${snapshot.data[index].mfgName}',
                                              style: TextStyle(
                                                  fontSize: 16,
                                                  color: Color(0xff031e41)),
                                            ),
                                          ],
                                        ),
                                        SizedBox(
                                          height: 5,
                                        ),
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.start,
                                          children: [
                                            Text('Strength: '),
                                            Text(
                                              '${snapshot.data[index].strength} ${snapshot.data[index].unit}',
                                              style: TextStyle(
                                                  fontSize: 16,
                                                  color: Color(0xff031e41)),
                                            ),
                                          ],
                                        ),
                                        SizedBox(
                                          height: 5,
                                        ),
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.start,
                                          children: [
                                            Text('Qty: '),
                                            Text(
                                              '${snapshot.data[index].quantity}',
                                              style: TextStyle(
                                                  fontSize: 16,
                                                  color: Color(0xff031e41)),
                                            ),
                                          ],
                                        ),
                                        SizedBox(
                                          height: 5,
                                        ),
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.start,
                                          children: [
                                            Text('Route: '),
                                            Text(
                                              '${snapshot.data[index].route}',
                                              style: TextStyle(
                                                  fontSize: 16,
                                                  color: Color(0xff031e41)),
                                            ),
                                          ],
                                        ),
                                        SizedBox(
                                          height: 5,
                                        ),
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.start,
                                          children: [
                                            Text('Form: '),
                                            Text(
                                              '${snapshot.data[index].form}',
                                              style: TextStyle(
                                                  fontSize: 16,
                                                  color: Color(0xff031e41)),
                                            ),
                                          ],
                                        ),
                                        SizedBox(
                                          height: 5,
                                        ),
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.start,
                                          children: [
                                            Text('Family Member: '),
                                            AutoSizeText(
                                              '${snapshot.data[index].memberStr}',
                                              maxLines: 1,
                                              style: TextStyle(
                                                  fontSize: 16,
                                                  color: Color(0xff031e41)),
                                            ),
                                          ],
                                        ),
                                        Row(
                                          mainAxisAlignment:
                                              MainAxisAlignment.start,
                                          children: [
                                            Text('Physician: '),
                                            AutoSizeText(
                                              '${snapshot.data[index].physicianStr}',
                                              maxLines: 1,
                                              style: TextStyle(
                                                  fontSize: 16,
                                                  color: Color(0xff031e41)),
                                            ),
                                          ],
                                        ),
                                      ],
                                    ),
                                  ),
                                ),
                              );
                            }),
                      );
                    }),
              ),
            ),
    ),
  ),
);
4

1 回答 1

1

您在同一个小部件树中同时SingleChildScrollView使用两者。ListView

您可以尝试删除SingleChildScrollView,或者如果您仍想SingleChildScrollView用作滚动控制器,ListView请将物理属性更改为 NeverScrollableScrollPhysics() - 这将禁用列表视图中的滚动并允许 SingleChildScrollView 正常运行。

ListView.builder(
   physics: NeverScrollableScrollPhysics();
)
于 2020-11-07T22:48:31.267 回答