flutter_easy_refresh icon indicating copy to clipboard operation
flutter_easy_refresh copied to clipboard

BoxConstraints forces an infinite height --> error-causing HeaderLocator

Open buchen opened this issue 1 year ago • 2 comments

I am getting the following error message

BoxConstraints forces an infinite height. [...] The relevant error-causing widget was HeaderLocator

if and only if

  • I add a search input field to the flexibleSpace of SliverAppBar
  • add const HeaderLocator.sliver() to the CustomScrollView
  • and I then click into the search text field

See below for the full reproducible example and the console output.

Any help, pointers, etc. are very much appreciated. The easy_refresh library is nice and sweet.

Full console output
Restarted application in 250ms.

════════ Exception caught by rendering library ═════════════════════════════════
The following assertion was thrown during performLayout():
BoxConstraints forces an infinite height.

These invalid constraints were provided to RenderStack's layout() function by the following function, which probably computed the invalid constraints in question:
RenderBox.layout

The offending constraints were: BoxConstraints(w=393.0, h=Infinity)
The relevant error-causing widget was
HeaderLocator
When the exception was thrown, this was the stack
#0      BoxConstraints.debugAssertIsValid.<anonymous closure>.throwError
#1      BoxConstraints.debugAssertIsValid.<anonymous closure>
#2      BoxConstraints.debugAssertIsValid
#3      RenderObject.layout
#4      RenderBox.layout
#5      RenderConstrainedBox.performLayout
#6      RenderObject.layout
#7      RenderBox.layout
#8      _HeaderLocatorRenderSliver.performLayout
#9      RenderObject.layout
#10     RenderViewportBase.layoutChildSequence
#11     RenderViewport._attemptLayout
#12     RenderViewport.performLayout
#13     RenderObject._layoutWithoutResize
#14     PipelineOwner.flushLayout
#15     RendererBinding.drawFrame
#16     WidgetsBinding.drawFrame
#17     RendererBinding._handlePersistentFrameCallback
#18     SchedulerBinding._invokeFrameCallback
#19     SchedulerBinding.handleDrawFrame
#20     SchedulerBinding._handleDrawFrame
#21     _invoke (dart:ui/hooks.dart:142:13)
#22     PlatformDispatcher._drawFrame (dart:ui/platform_dispatcher.dart:359:5)
#23     _drawFrame (dart:ui/hooks.dart:112:31)
The following RenderObject was being processed when the exception was fired: RenderConstrainedBox#7a1c0 relayoutBoundary=up2 NEEDS-LAYOUT NEEDS-COMPOSITING-BITS-UPDATE
RenderObject: RenderConstrainedBox#7a1c0 relayoutBoundary=up2 NEEDS-LAYOUT NEEDS-COMPOSITING-BITS-UPDATE
    needs compositing
    parentData: paintOffset=Offset(0.0, -0.0) (can use size)
    constraints: BoxConstraints(w=393.0, 0.0<=h<=Infinity)
    size: Size(393.0, 0.0)
    additionalConstraints: BoxConstraints(w=0.0, h=Infinity)
    child: RenderStack#85c08 NEEDS-LAYOUT NEEDS-COMPOSITING-BITS-UPDATE
        needs compositing
        parentData: <none> (can use size)
        constraints: BoxConstraints(w=393.0, h=0.0)
        size: Size(393.0, 0.0)
        alignment: AlignmentDirectional.topStart
        textDirection: ltr
        fit: loose
        child 1: RenderPositionedBox#d95f1 NEEDS-LAYOUT NEEDS-COMPOSITING-BITS-UPDATE
            needs compositing
            parentData: top=0.0; bottom=0.0; left=-35.0; width=70.0; offset=Offset(0.0, -35.0) (can use size)
            constraints: BoxConstraints(w=393.0, h=70.0)
            size: Size(393.0, 70.0)
            alignment: Alignment.center
            textDirection: ltr
            widthFactor: expand
            heightFactor: expand
            child: RenderConstrainedBox#91c27 relayoutBoundary=up1 NEEDS-LAYOUT NEEDS-COMPOSITING-BITS-UPDATE
                needs compositing
                parentData: offset=Offset(0.0, 0.0) (can use size)
                constraints: BoxConstraints(0.0<=w<=393.0, 0.0<=h<=70.0)
                size: Size(393.0, 70.0)
                additionalConstraints: BoxConstraints(w=70.0, 0.0<=h<=Infinity)
                child: RenderPositionedBox#a62e6 relayoutBoundary=up2 NEEDS-LAYOUT NEEDS-COMPOSITING-BITS-UPDATE
                    needs compositing
                    parentData: <none> (can use size)
                    constraints: BoxConstraints(0.0<=w<=393.0, h=70.0)
                    size: Size(393.0, 70.0)
                    alignment: Alignment.center
                    textDirection: ltr
                    widthFactor: expand
                    heightFactor: expand
════════════════════════════════════════════════════════════════════════════════

Flutter Code to reproduce the issue
import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';

void main() {
  runApp(const MyApp());
}

class MyApp extends StatelessWidget {
  const MyApp({super.key});

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      title: 'Flutter Demo',
      home: MyHomePage(),
    );
  }
}

class MyHomePage extends StatelessWidget {
  const MyHomePage({super.key});

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: EasyRefresh(
        header: const ClassicHeader(position: IndicatorPosition.locator),
        onRefresh: () {},
        child: SafeArea(
          child: CustomScrollView(
            slivers: [
              const SliverAppBar(
                expandedHeight: kToolbarHeight + 60,
                floating: true,
                title: Text('My Title'),
                flexibleSpace: FlexibleSpaceBar(
                  background: Column(
                    children: [
                      SizedBox(height: kToolbarHeight),
                      _Search(),
                    ],
                  ),
                ),
              ),
             const HeaderLocator.sliver(),
             SliverList.builder(
                itemCount: 100,
                itemBuilder: (_, ii) => ColoredBox(
                  color: Colors.primaries[ii % Colors.primaries.length],
                  child: const SizedBox(height: 50),
                ),
              )
            ],
          ),
        ),
      ),
    );
  }
}

class _Search extends StatefulWidget {
  const _Search();

  @override
  __SearchState createState() => __SearchState();
}

class __SearchState extends State<_Search> {
  late TextEditingController _editingController;

  @override
  void initState() {
    super.initState();
    _editingController = TextEditingController();
  }

  @override
  Widget build(BuildContext context) {
    return Padding(
      padding: const EdgeInsets.fromLTRB(10, 0, 10, 0),
      child: TextField(
        controller: _editingController,
        decoration: InputDecoration(
          isDense: true,
          border: OutlineInputBorder(
            borderRadius: BorderRadius.circular(10),
          ),
          hintText: 'Search',
        ),
        onChanged: (_) => setState(() {}),
      ),
    );
  }
}
Doctor output
[✓] Flutter (Channel stable, 3.10.6, on macOS 13.5 22G74 darwin-arm64, locale de-DE)
    • Flutter version 3.10.6 on channel stable at /Users/asbn/Tools/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision f468f3366c (3 weeks ago), 2023-07-12 15:19:05 -0700
    • Engine revision cdbeda788a
    • Dart version 3.0.6
    • DevTools version 2.23.1

[✓] Android toolchain - develop for Android devices (Android SDK version 33.0.0)
    • Android SDK at /Users/asbn/Library/Android/sdk
    • Platform android-33, build-tools 33.0.0
    • ANDROID_HOME = /Users/asbn/Library/Android/sdk
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 14.3.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 14E300c
    • CocoaPods version 1.12.1

[✓] Chrome - develop for the web
    • Chrome at /Applications/Google Chrome.app/Contents/MacOS/Google Chrome

[✓] Android Studio (version 2022.2)
    • Android Studio at /Applications/Android Studio.app/Contents
    • Flutter plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/9212-flutter
    • Dart plugin can be installed from:
      🔨 https://plugins.jetbrains.com/plugin/6351-dart
    • Java version OpenJDK Runtime Environment (build 17.0.6+0-17.0.6b802.4-9586694)

[✓] VS Code (version 1.81.0)
    • VS Code at /Applications/Visual Studio Code.app/Contents
    • Flutter extension version 3.70.0

[✓] Connected device (4 available)
    • bPhone2022 (mobile)    • 00008120-00064D543E9B401E            • ios            • iOS 16.6 20G75
    • iPhone 14 Pro (mobile) • ECFAAC86-BAD1-4A40-8064-B460F12EB213 • ios            • com.apple.CoreSimulator.SimRuntime.iOS-16-4 (simulator)
    • macOS (desktop)        • macos                                • darwin-arm64   • macOS 13.5 22G74 darwin-arm64
    • Chrome (web)           • chrome                               • web-javascript • Google Chrome 115.0.5790.170
    ! Error: bPhone2022 is busy: Fetching debug symbols for bPhone2022. Xcode will continue when bPhone2022 is finished. (code -10)
    ! Error: Apple Watch von Andreas needs to connect to determine its availability. Check the connection between the device and its companion iPhone,
      and the connection between the iPhone and Xcode. Both devices may also need to be restarted and unlocked. (code 1)

[✓] Network resources
    • All expected network resources are available.

• No issues found!

This is how the reproducible code looks like:

https://github.com/xuelongqy/flutter_easy_refresh/assets/587976/47ce3c78-0b3c-4e73-b4f5-c33c8ada3673

buchen avatar Aug 04 '23 07:08 buchen

Same problem, but i get this every time when i'm trying to pull down to refresh. HeaderLocator/FooterLocator both seem to be buggy and not working well... haven't found anything useful in documentation or examples about this...

eastsss avatar Oct 10 '23 10:10 eastsss

any solution ?

popooff avatar Feb 09 '24 23:02 popooff