FlutterError(BoxConstraints强制无限高,这些约束提供给RenderSemanticsAnnotations的layout()函数

hgqdbh6s  于 2023-03-13  发布在  Flutter
关注(0)|答案(1)|浏览(146)

我试图为flutter应用程序创建一个浮动搜索栏,但它抛出了以下异常:

Exception has occurred.
FlutterError (BoxConstraints forces an infinite height.
These invalid constraints were provided to RenderSemanticsAnnotations's layout() function by the following function, which probably computed the invalid constraints in question:
  RenderBox.layout (package:flutter/src/rendering/box.dart:2430:11)
The offending constraints were:
  BoxConstraints(w=411.4, h=Infinity))

下面分别是函数代码和我试图在其中显示它的视图的主体:

Widget buildFloatingSearchBar(BuildContext context) {
  final isPortrait = MediaQuery.of(context).orientation == Orientation.portrait;

  return FloatingSearchBar(
    hint: 'Search...',
    scrollPadding: const EdgeInsets.only(top: 16, bottom: 56),
    transitionDuration: const Duration(milliseconds: 800),
    transitionCurve: Curves.easeInOut,
    physics: const BouncingScrollPhysics(),
    axisAlignment: isPortrait ? 0.0 : -1.0,
    openAxisAlignment: 0.0,
    width: isPortrait ? 600 : 500,
    debounceDelay: const Duration(milliseconds: 500),
    onQueryChanged: (query) {
      // Call your model, bloc, controller here.
    },
    // Specify a custom transition to be used for
    // animating between opened and closed stated.
    transition: CircularFloatingSearchBarTransition(),
    actions: [
      FloatingSearchBarAction(
        showIfOpened: false,
        child: CircularButton(
          icon: const Icon(Icons.place),
          onPressed: () {},
        ),
      ),
      FloatingSearchBarAction.searchToClear(
        showIfClosed: false,
      ),
    ],
    builder: (context, transition) {
      return ClipRRect(
        borderRadius: BorderRadius.circular(8),
        child: Material(
          color: Colors.white,
          elevation: 4.0,
          child: Column(
            mainAxisSize: MainAxisSize.min,
            children: Colors.accents.map((color) {
              return Container(height: 112, color: color);
            }).toList(),
          ),
        ),
      );
    },
  );
}

机构:

body: SingleChildScrollView(
        //scroll widget

        child: Column(
          children: [
            Stack(
              fit: StackFit.expand,
              //stack widgets on top of each other
              children: <Widget>[
                Image.asset(
                  //loads an image on to the app
                  'images/map.png',
                ),
                SizedBox(
                  //a box of dimensions 400x400 and an x-y scale of 200 starting from the top left and going downwards and right
                  width: 400,
                  height: 400,

                  child: CustomPaint(
                    //paint
                    painter: LocationCircles(),
                  ),
                ),
                buildFloatingSearchBar(context),
              ],
            ),
          ],
        ),
      ),

我尝试将buildFloatingSearchBar函数放入Flexible()小部件中,但也不起作用

blmhpbnm

blmhpbnm1#

尝试使用singleChildScroll视图,它将允许扩展

body: Column(
  children: [
    Expanded(
      child: SingleChildScrollView(
        child: Stack(
          fit: StackFit.expand,
          children: <Widget>[
            Image.asset(
              'images/map.png',
            ),
            SizedBox(
              width: 400,
              height: 400,
              child: CustomPaint(
                painter: LocationCircles(),
              ),
            ),
          ],
        ),
      ),
    ),
    buildFloatingSearchBar(context),
  ],
),

相关问题