firebase RenderViewport需要RenderSliver类型的子级,但收到的却是RenderPositionedBox类型的子级

dy2hfwbg  于 2022-12-14  发布在  其他
关注(0)|答案(1)|浏览(81)

我在更改一些标签后遇到此错误,我甚至不记得更改了小部件:
我知道这是一个银和框的问题,但我试图改变和删除小部件,以解决这个问题无济于事

return Scaffold(
      backgroundColor: Colors.grey[200],
      floatingActionButton: Column(
        mainAxisAlignment: MainAxisAlignment.end,
        children: [
          FloatingActionButton(
            onPressed: () {
              //PATIENT.
              if (currTab == 0) {
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => const AddPatient(),
                  ),
                );
              } else {
                //SHIPMENT.
                Navigator.push(
                  context,
                  MaterialPageRoute(
                    builder: (context) => const AddShipment(),
                  ),
                );
              }
            },
            heroTag: null,
            child: Icon(currTab == 0
                ? Icons.person_add
                : Icons.add_shopping_cart_rounded),
          ),
          const SizedBox(
            height: 10,
          ),
          currTab == 0 ? _getFAB() : const SizedBox(),
          // FloatingActionButton(
          //   onPressed: () {},
          //   heroTag: null,
          //   child: const Icon(Icons.sort_rounded),
          // ),
        ],
      ),
      resizeToAvoidBottomInset: true,
      body: DefaultTabController(
        length: 2,
        child: NestedScrollView(
          body: TabBarView(
            controller: _tabController,
            physics: const NeverScrollableScrollPhysics(),
            children: [
              StreamBuilder<List<Patient>>(
                stream: readPatients(orderTypePatients),
                builder: (context, snapshot) {
                  if (snapshot.hasData) {
                    countPatients = snapshot.data!.length;
                  } else {
                    countPatients = 0;
                  }
                  return CustomScrollView(
                    slivers: [
                      if (snapshot.hasData)
                        SliverList(
                          delegate: SliverChildBuilderDelegate(
                            (BuildContext context, int index) {
                              if (snapshot.hasData) {
                                final patient = snapshot.data;
                                return makeCardPatient(patient![index]);
                              } else if (!snapshot.hasData) {
                                return const Center(
                                  child: CircularProgressIndicator(
                                      color: Colors.green),
                                );
                              } else if (snapshot.hasError) {
                                return const SliverToBoxAdapter(
                                    child: Center(child: Text('has err')));
                              } else {
                                return const Center(
                                  child: CircularProgressIndicator(
                                      color: Colors.green),
                                );
                              }
                            },
                            childCount: snapshot.data?.length,
                          ),
                        )
                      else if (snapshot.hasError)
                        Center(
                          child: Text(
                            snapshot.error.toString(),
                            style: const TextStyle(fontWeight: FontWeight.bold),
                          ),
                        )
                      else
                        const SliverToBoxAdapter(
                          child: Padding(
                            padding: EdgeInsets.all(10.0),
                            child: Center(
                              child: CircularProgressIndicator(
                                color: Colors.green,
                              ),
                            ),
                          ),
                        ),
                      SliverToBoxAdapter(
                        child: Padding(
                          padding: const EdgeInsets.all(12.0),
                          child: Row(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                            children: [
                              Text(
                                'Total:\n$totalSumPatients',
                                textAlign: TextAlign.center,
                                style: const TextStyle(
                                  color: Colors.black,
                                  fontWeight: FontWeight.bold,
                                  fontSize: 21,
                                ),
                              ),
                            ],
                          ),
                        ),
                      ),
                    ],
                  );
                },
              ),
              StreamBuilder<List<Shipment>>(
                stream: readShipments(orderTypeShipments),
                builder: (context, snapshot) {
                  if (snapshot.hasData) {
                    countShipments = snapshot.data!.length;
                  } else {
                    countShipments = 0;
                  }
                  return CustomScrollView(
                    slivers: [
                      if (snapshot.hasData)
                        SliverList(
                          delegate: SliverChildBuilderDelegate(
                            (BuildContext context, int index) {
                              if (snapshot.hasData) {
                                final shipment = snapshot.data;
                                return makeCardShipment(shipment![index]);
                              } else if (!snapshot.hasData) {
                                return const Center(
                                  child: CircularProgressIndicator(
                                      color: Colors.green),
                                );
                              } else if (snapshot.hasError) {
                                return const SliverToBoxAdapter(
                                    child: Center(child: Text('has err')));
                              } else {
                                return const Center(
                                  child: CircularProgressIndicator(
                                      color: Colors.green),
                                );
                              }
                            },
                            childCount: snapshot.data?.length,
                          ),
                        )
                      else if (snapshot.hasError)
                        SliverToBoxAdapter(
                            child: Center(
                          child: Text(
                            snapshot.error.toString(),
                            style: const TextStyle(fontWeight: FontWeight.bold),
                          ),
                        ))
                      else
                        const SliverToBoxAdapter(
                          child: Padding(
                            padding: EdgeInsets.all(10.0),
                            child: Center(
                              child: CircularProgressIndicator(
                                color: Colors.green,
                              ),
                            ),
                          ),
                        ),
                      SliverToBoxAdapter(
                        child: Padding(
                          padding: const EdgeInsets.all(12.0),
                          child: Center(
                            child: Text(
                              'Total:\n$totalSumShipment',
                              textAlign: TextAlign.center,
                              style: const TextStyle(
                                color: Colors.black,
                                fontWeight: FontWeight.w900,
                                fontSize: 21,
                              ),
                            ),
                          ),
                        ),
                      ),
                    ],
                  );
                },
              ),
            ],
          ),
          headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
            return [
              SliverAppBar(
                stretch: true,
                bottom: TabBar(
                  controller: _tabController,
                  indicatorSize: TabBarIndicatorSize.tab,
                  indicatorColor: Colors.green,
                  indicatorWeight: 5,
                  labelColor: Colors.green,
                  labelStyle: const TextStyle(
                    color: Colors.black,
                    fontWeight: FontWeight.bold,
                  ),
                  unselectedLabelColor: Colors.grey,
                  overlayColor:
                      MaterialStateProperty.all<Color>(Colors.grey[300]!),
                  onTap: (value) {
                    totalSumShipment = 0;
                    totalSumPatients = 0;
                    searchController.clear();
                    FocusManager.instance.primaryFocus?.unfocus();
                    currTab = value;
                    setState(() {});
                  },
                  tabs: [
                    Tab(
                      icon: Stack(
                        children: [
                          Icon(
                            Icons.supervised_user_circle_rounded,
                            color: currTab == 0 ? Colors.green : Colors.grey,
                            size: 36,
                          ),
                          countPatients == 0
                              ? const SizedBox(
                                  height: 1,
                                )
                              : Positioned(
                                  right: 0,
                                  child: Container(
                                    padding: const EdgeInsets.all(1),
                                    decoration: BoxDecoration(
                                      color: Colors.red,
                                      borderRadius: BorderRadius.circular(7),
                                    ),
                                    constraints: const BoxConstraints(
                                      minWidth: 15,
                                      minHeight: 15,
                                      maxHeight: 15,
                                      maxWidth: 15,
                                    ),
                                    child: Text(
                                      countPatients.toInt().toString(),
                                      style: const TextStyle(
                                        color: Colors.white,
                                        fontSize: 10,
                                      ),
                                      textAlign: TextAlign.center,
                                    ),
                                  ),
                                ),
                        ],
                      ),
                      text: 'Patients',
                    ),
                    Tab(
                      icon: Stack(
                        children: [
                          Icon(
                            Icons.shopping_bag_rounded,
                            color: currTab == 1 ? Colors.green : Colors.grey,
                            size: 36,
                          ),
                          countShipments == 0
                              ? const SizedBox(
                                  height: 1,
                                )
                              : Positioned(
                                  right: 0,
                                  child: Container(
                                    padding: const EdgeInsets.all(1),
                                    decoration: BoxDecoration(
                                      color: Colors.red,
                                      borderRadius: BorderRadius.circular(7),
                                    ),
                                    constraints: const BoxConstraints(
                                      minWidth: 15,
                                      minHeight: 15,
                                      maxHeight: 15,
                                      maxWidth: 15,
                                    ),
                                    child: Text(
                                      countShipments.toInt().toString(),
                                      style: const TextStyle(
                                        color: Colors.white,
                                        fontSize: 10,
                                      ),
                                      textAlign: TextAlign.center,
                                    ),
                                  ),
                                ),
                        ],
                      ),
                      text: 'Orders',
                    ),
                  ],
                ),
                pinned: true,
                snap: false,
                floating: true,
                elevation: 10,
                expandedHeight: 300.0,
                stretchTriggerOffset: 150.0,
                backgroundColor: Colors.grey.shade200,
                flexibleSpace: FlexibleSpaceBar(
                  stretchModes: const [
                    StretchMode.zoomBackground,
                    StretchMode.fadeTitle,
                    StretchMode.blurBackground,
                  ],
                  titlePadding: const EdgeInsetsDirectional.all(0),
                  background: SafeArea(
                    child: Stack(
                      alignment: AlignmentDirectional.topCenter,
                      fit: StackFit.loose,
                      children: [
                        Positioned(
                          top: 5,
                          right: 5,
                          child: IconButton(
                              onPressed: () {
                                Navigator.push(
                                  context,
                                  MaterialPageRoute(
                                    builder: (context) => const SettingsPage(),
                                  ),
                                );
                              },
                              icon: const Icon(Icons.settings_rounded)),
                        ),
                        Positioned(
                          top: 10,
                          right: 1,
                          left: 1,
                          child: Padding(
                            padding: const EdgeInsets.all(50.0),
                            child: GestureDetector(
                              onTap: () {
                                log(countShipments.toString());
                                setState(() {});
                              },
                              child: Image.asset(
                                'assets/images/my_Logo.png',
                                fit: BoxFit.fitWidth,
                              ),
                            ),
                          ),
                        ),
                        Positioned(
                          top: 120,
                          left: 10,
                          right: 10,
                          child: Padding(
                            padding: const EdgeInsets.all(30.0),
                            child: searchField(),
                          ),
                        ),
                      ],
                    ),
                  ),
                  centerTitle: true,
                  collapseMode: CollapseMode.pin,
                ),
              )
            ];
          },
        ),
      ),
    );

↑为支架

Card makeCardPatient(Patient patient) {
    totalSumPatients = totalSumPatients + patient.balance;
    return Card(
      elevation: 8.0,
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(25.0),
      ),
      margin: const EdgeInsets.symmetric(
        horizontal: 10.0,
        vertical: 6.0,
      ),
      child: Container(
        decoration: BoxDecoration(
          color: const Color.fromARGB(228, 64, 96, 72),
          borderRadius: BorderRadius.circular(25),
        ),
        child: makeListTilePatient(patient),
      ),
    );
  }

↑是在streambuilder中调用以创建Card小部件的card小部件

ListTile makeListTilePatient(Patient patient) {
    return ListTile(
      shape: RoundedRectangleBorder(
        borderRadius: BorderRadius.circular(25),
      ),
      contentPadding: const EdgeInsets.symmetric(
        horizontal: 20.0,
        vertical: 10.0,
      ),
      leading: Container(
        padding: const EdgeInsets.only(right: 12.0),
        decoration: const BoxDecoration(
          border: Border(
            right: BorderSide(
              width: 1.0,
              color: Colors.white24,
            ),
          ),
        ),
        child: CircleAvatar(
          radius: 25,
          backgroundColor: patient.balance == 0 ? Colors.blue : Colors.red,
          child: Text(
            patient.balance.toStringAsFixed(2).toUpperCase(),
            style: const TextStyle(
              fontWeight: FontWeight.bold,
              fontSize: 18,
            ),
          ),
        ),
      ),
      title: Text(
        patient.name,
        style: const TextStyle(
          color: Colors.white,
          fontWeight: FontWeight.bold,
        ),
      ),
      subtitle: Row(
        mainAxisAlignment: MainAxisAlignment.spaceBetween,
        children: <Widget>[
          Expanded(
            flex: 1,
            child: Text(
              DateFormat('yyyy/MM/dd').format(patient.lastvisit) == '1986/09/25'
                  ? ' '
                  : timeAgo(patient.lastvisit),
              style: const TextStyle(
                fontWeight: FontWeight.bold,
                color: Colors.black,
              ),
            ),
          ),
          Expanded(
            flex: 1,
            child: Padding(
              padding: const EdgeInsets.only(left: 10.0),
              child: Text(
                DateFormat('yyyy/MM/dd').format(patient.appointment) ==
                        '1986/09/25'
                    ? ' '
                    : timeFromNow(patient.appointment),
                style: const TextStyle(
                  color: Colors.white,
                  fontWeight: FontWeight.bold,
                ),
              ),
            ),
          )
        ],
      ),
      trailing: const Icon(
        Icons.keyboard_arrow_right,
        color: Colors.white,
        size: 30.0,
      ),
      onTap: () {
        totalSumPatients = 0;
        Navigator.push(
          context,
          MaterialPageRoute(
            builder: (context) => Details(
              patient: patient,
            ),
          ),
        );
        setState(() {});
      },
    );
  }

↑是平铺小部件,详细说明卡片中的内容。
我知道有些东西我没有看到,但我试着搜索和编辑了很长一段时间,我没有找到我错过了什么。
我是新来的,所以你能帮帮我吗?
我尝试用Slivertoboxadapter Package 一些小部件,但没有工作。
使用了额外的功能,我认为它们与问题无关,但它们在这里:

Stream<List<Shipment>> readShipments(String orderTypeShipments) {
    return FirebaseFirestore.instance
        .collection('shipments')
        .orderBy(
          orderTypeShipments,
          descending: sortOrder,
        )
        .snapshots()
        .map((snapshot) => snapshot.docs
            .map((doc) => Shipment.fromJson(doc.data()))
            .where(
              (element) =>
                  element.userId.toUpperCase() ==
                      Helper.currUserID.toUpperCase() &&
                  element.type.toUpperCase().contains(
                        searchController.text.toUpperCase(),
                      ),
            )
            .toList());
  }

  Future<int> getPatientCount() async {
    var x = FirebaseFirestore.instance
        .collection('patients')
        .orderBy(
          orderTypePatients.toUpperCase(),
          descending: sortOrder,
        )
        .snapshots()
        .map((snapshot) => snapshot.docs
            .map((doc) => Patient.fromJson(doc.data()))
            .where((element) =>
                element.user == Helper.currUserID &&
                (element.name
                    .toUpperCase()
                    .contains(searchController.text.toUpperCase())))
            .toList());
    setState(() {});
    return x.length;
  }
rkue9o1l

rkue9o1l1#

正如“耶辛谢赫”所建议的那样,我忽略了这句话,愚蠢的我。谢谢你。
我只需要在快照中使用SliverToBoxAdapter Package Center小部件。错误:
SliverToBoxAdapter(子项:中心(...

相关问题