Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Layout child sliver only when expanded #4

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Amir-P
Copy link
Member

@Amir-P Amir-P commented Jan 11, 2025

Fixes #2.

@Zekfad
Copy link
Contributor

Zekfad commented Jan 11, 2025

Hi, when I was fixing extent size, I've tried to fix this as well, but faces issues with layout.
It seems that your fix is also causes this issue, here's reproducible:

Collapse the list and then press regenerate.
This would cause

_AssertionError ('package:flutter/src/rendering/object.dart': Failed assertion: line 3848 pos 12: '!_needsLayout': Updated layout information required for RenderSliverList#1f474 relayoutBoundary=up17 NEEDS-LAYOUT NEEDS-PAINT to calculate semantics.)
// because
// ignore_for_file: unreachable_from_main


import 'dart:math';

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

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

class MainApp extends StatefulWidget {

  const MainApp({super.key});

  @override
  State<MainApp> createState() => _MainAppState();
}

class _MainAppState extends State<MainApp> {
  final rnd = Random(1337);
  bool expanded = true;
  List<String> objects = [];

  @override
  Widget build(BuildContext context) =>
    MaterialApp(
      home: Scaffold(
        body: Center(
          child: CustomScrollView(
            shrinkWrap: true,
            slivers: [
              SliverToBoxAdapter(
                child: ElevatedButton(
                  child: const Text('Regenerate'),
                  onPressed: () => setState(() {
                    objects = List.generate(50 + rnd.nextInt(50), (i) => 'String $i - ${rnd.nextDouble()}');
                  }),
                ),
              ),
              AnimatedSliverExpandable(
                expanded: expanded,
                headerBuilder: (context, animation) => ListTile(
                  onTap: () => setState(() => expanded = !expanded),
                  title: const Text('Example'),
                  trailing: AnimatedBuilder(
                    animation: animation,
                    builder: (context, child) => Transform.rotate(
                      angle: (animation.value - 0.5) * pi,
                      child: child,
                    ),
                    child: const Icon(Icons.chevron_left),
                  ),
                ),
                sliver: SliverList.builder(
                  itemCount: objects.length,
                  itemBuilder: (context, i) => ListTile(
                    title: Text(objects[i]),
                  ),
                ),
              ),
            ],
          ),
        ),
      ),
    );
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Non expanded children are build lazy
2 participants