dart 使处于 Flutter 状态的endDrawer可滚动

wljmcqd8  于 2023-10-13  发布在  Flutter
关注(0)|答案(1)|浏览(93)

我想使抽屉的Flutter滚动,使用户可以看到所有的数据在一个抽屉。我调用endDrawer为:

endDrawer:  ExperienceCustomDrawer()

ExperienceCustomDrawer类是:

import 'package:flutter/material.dart';

class ExperienceCustomDrawer extends StatelessWidget {
   ExperienceCustomDrawer({
     super.key,
   });

  @override
  Widget build(BuildContext context) {

    return Drawer(
      width: MediaQuery.of(context).size.width * 0.6,
    child:Container(
      color: Colors.black,
      child: Column(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: [
          Flexible(
            flex: 1,
            child: Padding(
              padding: const EdgeInsets.fromLTRB(0, 15, 30, 15),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.end,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  InkWell(
                      onTap:(){
                        Navigator.of(context).pop();
                      },
                      child: const Icon(Icons.close, color: Color(0xffF1C452),))
                ],
              ),
            ),
          ),
          Flexible(
            flex: 1,
            child: Padding(
              padding: const EdgeInsets.fromLTRB(30, 15, 30, 15),
              child: FittedBox(
                fit: BoxFit.scaleDown,
                child: Text("Sea Food Experience",
                  style: TextStyle(
                    color: Color(0xffFFFFFF),
                    fontSize: 28,
                  ),
                ),
              ),
            ),
          ),
          Flexible(
            flex: 1,
            child: Container(
              width: MediaQuery.of(context).size.width,
              color: const Color(0xff4B4B52),
              padding: const EdgeInsets.fromLTRB(30, 15, 30, 15),
              child: Text("Custom tabbar here",
                style: TextStyle(
                  color: Color(0xffFFFFFF),
                  fontSize: 28,
                ),
              ),
            ),
          ),

          Flexible(
            flex: 2,

            child: Padding(
              padding:const EdgeInsets.fromLTRB(30, 15, 30, 15),
              child: Column(
                children: [

                  Flexible(
                    child: Row(
                      children: [
                        Flexible(
                          child: Container(
                            width: 8,
                            height: 1,
                            color: const Color(0xffF1C452),
                          ),
                        ),
                        Flexible(
                          child: Padding(
                            padding: const EdgeInsets.only(left: 8.0),
                            child: FittedBox(
                              fit: BoxFit.scaleDown,
                              child: Text("Experience",
                                style: TextStyle(
                                  color: Color(0xffF1C452),
                                  fontSize: 24,
                                ),
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                  Flexible(
                    child: Padding(
                      padding:  EdgeInsets.only(left: 16.0, top: 2,bottom: 2, right: 2),
                      child: Text(
                          "The sizzle and taste of authentic BBQ flavors in a cozy bistro setting. "
                              "Savor slow-cooked meats, homemade sauces, and sides made with "
                              "fresh ingredients.",

                          style: TextStyle(
                            color: Color(0xffFFFFFF),
                            fontSize: 16,
                          ),
                        ),
                    ),
                  ),
                ],
              ),
            ),
          ),
          Flexible(
            flex: 2,
            child: Padding(
              padding:const EdgeInsets.fromLTRB(30, 15, 30, 15),
              child: Column(
                children: [

                  Flexible(
                    child: Row(
                      children: [
                        Flexible(
                          child: Container(
                            width: 8,
                            height: 1,
                            color: const Color(0xffF1C452),
                          ),
                        ),
                        Flexible(
                          child: Padding(
                            padding: const EdgeInsets.only(left: 8.0),
                            child: FittedBox(
                              fit: BoxFit.scaleDown,
                              child: Text("WOW Factors",
                                style: TextStyle(
                                  color: Color(0xffF1C452),
                                  fontSize: 24,
                                ),
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                  Flexible(
                    child: Padding(
                      padding:  EdgeInsets.only(left: 16.0),

                      child: Wrap(
                        spacing: 30,
                        children: [
                          CircleAvatar(
                            radius: 20,
                            backgroundColor: Colors.red,
                          ),
                          CircleAvatar(
                            radius: 20,
                            backgroundColor: Colors.red,
                          ),CircleAvatar(
                            radius: 20,
                            backgroundColor: Colors.red,
                          ),
                          CircleAvatar(
                            radius: 20,
                            backgroundColor: Colors.red,
                          ),

                          CircleAvatar(
                            radius: 20,
                            backgroundColor: Colors.red,
                          ),
                          CircleAvatar(
                            radius: 20,
                            backgroundColor: Colors.red,
                          ),CircleAvatar(
                            radius: 20,
                            backgroundColor: Colors.red,
                          ),
                          CircleAvatar(
                            radius: 20,
                            backgroundColor: Colors.red,
                          ),
                          CircleAvatar(
                            radius: 20,
                            backgroundColor: Colors.red,
                          ),
                          CircleAvatar(
                            radius: 20,
                            backgroundColor: Colors.red,
                          ),CircleAvatar(
                            radius: 20,
                            backgroundColor: Colors.red,
                          ),
                          CircleAvatar(
                            radius: 20,
                            backgroundColor: Colors.red,
                          ),
                          CircleAvatar(
                            radius: 20,
                            backgroundColor: Colors.red,
                          ),
                          CircleAvatar(
                            radius: 20,
                            backgroundColor: Colors.red,
                          ),CircleAvatar(
                            radius: 20,
                            backgroundColor: Colors.red,
                          ),
                          CircleAvatar(
                            radius: 20,
                            backgroundColor: Colors.red,
                          ),
                          CircleAvatar(
                            radius: 20,
                            backgroundColor: Colors.red,
                          ),
                          CircleAvatar(
                            radius: 20,
                            backgroundColor: Colors.red,
                          ),CircleAvatar(
                            radius: 20,
                            backgroundColor: Colors.red,
                          ),
                          CircleAvatar(
                            radius: 20,
                            backgroundColor: Colors.red,
                          ),

                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
          Flexible(
            flex: 1,
            child: Padding(
              padding:const EdgeInsets.fromLTRB(30, 6, 30, 6),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Row(
                    mainAxisAlignment: MainAxisAlignment.start,
                    children: [
                      Flexible(
                        child: Container(
                          width: 8,
                          height: 1,
                          color: const Color(0xffF1C452),
                        ),
                      ),
                      Flexible(
                        child: Padding(
                          padding: const EdgeInsets.only(left: 8.0),
                          child: Text("Location",
                            style: TextStyle(
                              color: Color(0xffF1C452),
                              fontSize: 24,
                            ),
                          ),
                        ),
                      ),
                    ],
                  ),
                  Flexible(
                    child: Padding(
                      padding:  EdgeInsets.only(left: 16.0),
                      child: Text("House # 11, Street # 65 F-11/4, Islamabad",
                        style: TextStyle(
                          color: Color(0xffFFFFFF),
                          fontSize: 16,
                        ),
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),
          Flexible(
            flex: 1,
            child: Padding(
              padding:const EdgeInsets.fromLTRB(30, 6, 30, 6),
              child: Column(
                mainAxisAlignment: MainAxisAlignment.center,
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  Flexible(
                    flex: 1,
                    child: Row(
                      children: [
                        Flexible(
                          child: Container(
                            width: 8,
                            height: 1,
                            color: const Color(0xffF1C452),
                          ),
                        ),
                        Flexible(
                          flex: 4,
                          child: Padding(
                            padding: const EdgeInsets.only(left: 8.0),
                            child: Text("Sub Host",
                              style: TextStyle(
                                color: Color(0xffF1C452),
                                fontSize: 24,
                              ),
                            ),
                          ),
                        ),
                      ],
                    ),
                  ),
                  Flexible(
                    child: Padding(
                      padding:  EdgeInsets.only(left: 16.0, top: 9),
                      child: Row(
                        children: [
                          Text(
                              "Zoya Khan",
                            style: TextStyle(
                              color: Color(0xffFFFFFF),
                              fontSize: 16,
                            ),
                          ),

                          Padding(
                            padding: EdgeInsets.symmetric(horizontal: 16),
                            child: Container(
                              height: 16,
                              width: 1,
                              color: Color(0xffFFFFFF),
                            ),
                          ),
                          Text(
                            "0300 000 0000",
                            style: TextStyle(
                              color: Color(0xffFFFFFF),
                              fontSize: 16,
                            ),
                          ),
                        ],
                      ),
                    ),
                  ),
                ],
              ),
            ),
          ),

        ],
      ),
    )
    );
  }
}

我尝试将第一个容器 Package 在singleChildScrollView和ListView中,但它不起作用。做这些修改会导致抛出渲染errors.as你可以看到:

return Drawer(
        width: MediaQuery.of(context).size.width * 0.6,
        child:Container(
          color: Colors.black,
          child: SingleChildScrollView(
            scrollDirection: Axis.vertical,
            child: Column(
              mainAxisAlignment: MainAxisAlignment.start,
              crossAxisAlignment: CrossAxisAlignment.start,
              children: [
             

              ],
            ),
          ),
        )
    );

误差是:

======== Exception caught by rendering library =====================================================
The following assertion was thrown during performLayout():
RenderFlex children have non-zero flex but incoming height constraints are unbounded.

When a column is in a parent that does not provide a finite height constraint, for example if it is in a vertical scrollable, it will try to shrink-wrap its children along the vertical axis. Setting a flex on a child (e.g. using Expanded) indicates that the child is to expand to fill the remaining space in the vertical direction.
These two directives are mutually exclusive. If a parent is to shrink-wrap its child, the child cannot simultaneously expand to fit its parent.

Consider setting mainAxisSize to MainAxisSize.min and using FlexFit.loose fits for the flexible children (using Flexible rather than Expanded). This will allow the flexible children to size themselves to less than the infinite remaining space they would otherwise be forced to take, and then will cause the RenderFlex to shrink-wrap the children rather than expanding to fit the maximum constraints provided by the parent.

If this message did not help you determine the problem, consider using debugDumpRenderTree():
  https://flutter.dev/debugging/#rendering-layer
  http://api.flutter.dev/flutter/rendering/debugDumpRenderTree.html
The affected RenderFlex is: RenderFlex#dc3b5 relayoutBoundary=up3 NEEDS-LAYOUT NEEDS-PAINT NEEDS-COMPOSITING-BITS-UPDATE
  parentData: offset=Offset(0.0, 0.0) (can use size)
  constraints: BoxConstraints(0.0<=w<=697.2, 0.0<=h<=Infinity)
  size: MISSING
  direction: vertical
  mainAxisAlignment: start
  mainAxisSize: max
  crossAxisAlignment: center
vxqlmq5t

vxqlmq5t1#

您正在尝试在SingleChildScrollView中添加带有flexible小部件的column,这导致了问题。
您可以
1.删除flexible小部件并使用SingleChildScrollView Package 列

1.删除columnflexible小部件,并将列替换为ListView

相关问题