letsar / gap

Flutter widgets for easily adding gaps inside Flex widgets such as Columns and Rows or scrolling views
MIT License
211 stars 20 forks source link

How to use Gap in ListView's children? #2

Closed mono0926 closed 4 years ago

mono0926 commented 4 years ago

How to use Gap in ListView's children?

Neither Gap nor SliverGap not seems works with ListView πŸ€”

ListView x Gap

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ListView(
        children: const [
          Gap.expand(100, color: Colors.red),
        ],
      ),
    );
  }
I/flutter (12403): ══║ EXCEPTION CAUGHT BY RENDERING LIBRARY β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
I/flutter (12403): The following assertion was thrown during performLayout():
I/flutter (12403): A Gap widget must be placed directly inside a Flex widget
I/flutter (12403): 
I/flutter (12403): The relevant error-causing widget was:
I/flutter (12403):   Gap file:///Users/mono/Git/gap/example/lib/main.dart:31:15
I/flutter (12403): 
I/flutter (12403): When the exception was thrown, this was the stack:
I/flutter (12403): #0      RenderGap.performLayout (package:gap/src/rendering/gap.dart:95:7)
I/flutter (12403): #1      RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter (12403): #2      RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter (12403): #3      RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter (12403): #4      RenderProxyBoxMixin.performLayout (package:flutter/src/rendering/proxy_box.dart:111:13)
I/flutter (12403): #5      RenderObject.layout (package:flutter/src/rendering/object.dart:1767:7)
I/flutter (12403): #6      RenderSliverList.performLayout (package:flutter/src/rendering/sliver_list.dart:193:27)

ListView x SliverGap

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: ListView(
        children: const [
          SliverGap(100, color: Colors.red),
        ],
      ),
    );
  }
I/flutter (12403): ══║ EXCEPTION CAUGHT BY WIDGETS LIBRARY β•žβ•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•β•
I/flutter (12403): The following assertion was thrown building NotificationListener<KeepAliveNotification>:
I/flutter (12403): A RenderRepaintBoundary expected a child of type RenderBox but received a child of type
I/flutter (12403): RenderSliverGap.
I/flutter (12403): RenderObjects expect specific types of children because they coordinate with their children during
I/flutter (12403): layout and paint. For example, a RenderSliver cannot be the child of a RenderBox because a
I/flutter (12403): RenderSliver does not understand the RenderBox layout protocol.
I/flutter (12403): 
I/flutter (12403): The RenderRepaintBoundary that expected a RenderBox child was created by:
I/flutter (12403):   RepaintBoundary ← IndexedSemantics ← NotificationListener<KeepAliveNotification> ← KeepAlive ←
I/flutter (12403):   AutomaticKeepAlive ← KeyedSubtree ← SliverList ← MediaQuery ← SliverPadding ← Viewport ←
I/flutter (12403):   IgnorePointer-[GlobalKey#633e1] ← Semantics ← β‹―
I/flutter (12403): 
I/flutter (12403): The RenderSliverGap that did not match the expected child type was created by:
I/flutter (12403):   SliverGap ← RepaintBoundary ← IndexedSemantics ← NotificationListener<KeepAliveNotification> ←
I/flutter (12403):   KeepAlive ← AutomaticKeepAlive ← KeyedSubtree ← SliverList ← MediaQuery ← SliverPadding ← Viewport
I/flutter (12403):   ← IgnorePointer-[GlobalKey#633e1] ← β‹―
I/flutter (12403): 
I/flutter (12403): The relevant error-causing widget was:
I/flutter (12403):   ListView file:///Users/mono/Git/gap/example/lib/main.dart:29:13
I/flutter (12403): 
I/flutter (12403): When the exception was thrown, this was the stack:
I/flutter (12403): #0      RenderObjectWithChildMixin.debugValidateChild.<anonymous closure> (package:flutter/src/rendering/object.dart:2916:9)
I/flutter (12403): #1      RenderObjectWithChildMixin.debugValidateChild (package:flutter/src/rendering/object.dart:2943:6)
I/flutter (12403): #2      SingleChildRenderObjectElement.insertChildRenderObject (package:flutter/src/widgets/framework.dart:5848:25)
letsar commented 4 years ago

Yep this is expected, since I created it only for Rows and Columns in the first time. But I have a working solution in my mind! Wait for me to have some time and I will update this package πŸ˜‰.

letsar commented 4 years ago

Landed in the v1.2.0 πŸš€