xuelongqy / flutter_easy_refresh

A flutter widget that provides pull-down refresh and pull-up load.
https://xuelongqy.github.io/flutter_easy_refresh/
MIT License
3.9k stars 635 forks source link

当包裹ListView时,item中使用Column,并且使用Padding做分割线时会报错,Column中最后一个Widget没有Padding就会报错 #666

Closed AWarmHug closed 1 year ago

AWarmHug commented 1 year ago

目前看来不影响使用,只会报错,但是使用RefreshIndicator并不会报错 报错信息如下: ======== Exception caught by rendering library ===================================================== The following assertion was thrown during performLayout(): RenderBox.size accessed beyond the scope of resize, layout, or permitted parent access. RenderBox can always access its own size, otherwise, the only object that is allowed to read RenderBox.size is its parent, if they have said they will. It you hit this assert trying to access a child's size, pass "parentUsesSize: true" to that child's layout(). 'package:flutter/src/rendering/box.dart': Failed assertion: line 2009 pos 13: 'debugDoingThisResize || debugDoingThisLayout || _computingThisDryLayout || (RenderObject.debugActiveLayout == parent && size._canBeUsedByParent)'

Either the assertion indicates an error in the framework itself, or we should provide substantially more information in this error message to help you determine and fix the underlying cause. In either case, please report this assertion by filing a bug on GitHub: https://github.com/flutter/flutter/issues/new?template=2_bug.md

The relevant error-causing widget was: ListView ListView:file:///Users/bin_ren/AndroidStudioProjects/qxb/lib_flutter/lib/page/dimension/equity_pledge/demo.dart:94:35 When the exception was thrown, this was the stack:

2 RenderBox.size. (package:flutter/src/rendering/box.dart:2009:13)

3 RenderBox.size (package:flutter/src/rendering/box.dart:2022:6)

4 Element.size (package:flutter/src/widgets/framework.dart:4229:27)

5 IndicatorNotifier.position= (package:easy_refresh/src/notifier/indicator_notifier.dart:149:27)

====================================================================================================

image

Demo:

import 'dart:async';

import 'package:easy_refresh/easy_refresh.dart';
import 'package:flutter/material.dart';

void main() {
  runZonedGuarded<Future<void>>(() async {
    runApp(const DemoApp());
  }, (error, stackTrace) async {
    debugPrint(error.toString());
  });
}

class DemoApp extends StatelessWidget {
  const DemoApp({Key? key}) : super(key: key);

  @override
  Widget build(BuildContext context) {
    return const MaterialApp(
      home: DemoPage(
        eid: "",
      ),
    );
  }
}

class DemoPage extends StatefulWidget {
  const DemoPage({Key? key, required String eid}) : super(key: key);

  @override
  State<DemoPage> createState() => _DemoPageState();
}

class _DemoPageState extends State<DemoPage> {
  List<String> list = [];

  @override
  void initState() {
    super.initState();
    for (var i = 0; i < 20; i++) {
      list.add("Index = $i");
    }
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text("Demo"),
        centerTitle: true,
        elevation: 0.15,
      ),
      body: NestedScrollView(
        headerSliverBuilder: (BuildContext context, bool innerBoxIsScrolled) {
          return [
            SliverToBoxAdapter(
              child: Container(
                alignment: AlignmentDirectional.centerStart,
                constraints: const BoxConstraints(minHeight: 78),
                child: const Text("头部"),
              ),
            ),
          ];
        },
        body: Column(
          crossAxisAlignment: CrossAxisAlignment.start,
          children: [
            Container(
              color: Color(0xFFF5F5F5),
              width: double.infinity,
              padding: const EdgeInsets.symmetric(vertical: 8.0, horizontal: 16),
              //共15条竞争对手信息
              child: Builder(builder: (context) {
                return const Text("flutter_easy_refresh");
              }),
            ),
            Expanded(
              child: EasyRefresh.builder(
                // refreshEnable: false,
                onRefresh: () async {
                  Future.delayed(const Duration(seconds: 3));
                  setState(() {
                    list.clear();
                    for (var i = 0; i < 20; i++) {
                      list.add("Index = ${list.length + 1}");
                    }
                  });
                },
                childBuilder: (BuildContext context, ScrollPhysics physics) {
                  return ListView.separated(
                      physics: physics,
                      itemBuilder: (context, index) {
                        return Container(
                          padding: const EdgeInsetsDirectional.all(15),
                          color: Colors.white,
                          child: Row(
                            crossAxisAlignment: CrossAxisAlignment.center,
                            children: [
                              Expanded(
                                child: Column(
                                  crossAxisAlignment: CrossAxisAlignment.start,
                                  children: [
                                    Padding(
                                      padding: const EdgeInsets.only(bottom: 5.0),
                                      child: Row(
                                        children: const [
                                          Text("flutter_easy_refresh:"),
                                          Expanded(
                                            child: Text("非常好用"),
                                          ),
                                        ],
                                      ),
                                    ),
                                    Padding(
                                      padding: const EdgeInsets.only(bottom: 5.0),
                                      child: Row(
                                        children: const [
                                          Text("flutter_easy_refresh:"),
                                          Expanded(
                                            child: Text("非常好用"),
                                          ),
                                        ],
                                      ),
                                    ),
                                    Padding(
                                      padding: const EdgeInsets.only(bottom: 5.0),
                                      child: Row(
                                        children: const [
                                          Text("flutter_easy_refresh:"),
                                          Expanded(child: Text("非常好用")),
                                        ],
                                      ),
                                    ),
                                    /// 最后一个没有padding,就会报错,加上padding不会报错
                                    Row(
                                      children: const [
                                        Text("flutter_easy_refresh:"),
                                        Expanded(child: Text("非常好用")),
                                      ],
                                    ),
                                  ],
                                ),
                              ),
                              const Icon(Icons.arrow_right),
                            ],
                          ),
                        );
                      },
                      separatorBuilder: (context, index) {
                        return const Divider(
                          height: 0.5,
                          indent: 15,
                          endIndent: 15,
                          color: Color(0xFFF5F5F5),
                        );
                      },
                      itemCount: list.length);
                },
              ),
            ),
          ],
        ),
      ),
    );
  }
}
xuelongqy commented 1 year ago

3.3.1 已修复