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

Issue with displaying a list inside ShadSheet - Unbounded height error #191

Closed
brunosemfio opened this issue Nov 7, 2024 · 7 comments · Fixed by #192 or #193
Closed

Issue with displaying a list inside ShadSheet - Unbounded height error #191

brunosemfio opened this issue Nov 7, 2024 · 7 comments · Fixed by #192 or #193
Assignees
Labels
bug Something isn't working

Comments

@brunosemfio
Copy link

brunosemfio commented Nov 7, 2024

Steps to reproduce

I'm encountering an issue when trying to display a list inside ShadSheet. The following code snippet demonstrates my setup.

Expected results

The list should be displayed correctly within the ShadSheet, occupying the available space and allowing vertical scrolling without any constraint issues.

Actual results

When pressing the "OPEN" button, the following error appears:

"Vertical viewport was given unbounded height."

If I wrap the list in a LayoutBuilder, the error changes to:

"BoxConstraints forces an infinite height."

The ShadSheet fails to display the list properly and seems unable to handle the height constraints required by the ListView.

shadcn_ui version

0.15.1

Platform

MacOS, Android, iOS, Web

Code sample

Code sample
import 'package:flutter/material.dart';
import 'package:shadcn_ui/shadcn_ui.dart';

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

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

  @override
  Widget build(BuildContext context) {
    return ShadApp(
      home: Scaffold(
        body: LayoutBuilder(
          builder: (context, constraints) {
            return Center(
              child: ShadButton.ghost(
                onPressed: () {
                  showShadSheet(
                    context: context,
                    side: ShadSheetSide.right,
                    builder: (_) {
                      return ShadSheet(
                        constraints: BoxConstraints(
                          maxWidth: constraints.maxWidth * .8,
                          maxHeight: constraints.maxHeight,
                        ),
                        // scrollable: true,
                        // isScrollControlled: true,
                        child: ListView.builder(
                          itemBuilder: (_, __) => const Text('test'),
                        ),
                      );
                    },
                  );
                },
                child: const Text('OPEN'),
              ),
            );
          },
        ),
      ),
    );
  }
}

Flutter Doctor output

Doctor output
[✓] Flutter (Channel stable, 3.24.4, on macOS 15.1 24B83 darwin-arm64, locale pt-BR)
    • Flutter version 3.24.4 on channel stable at /Users/bruno/flutter
    • Upstream repository https://github.com/flutter/flutter.git
    • Framework revision 603104015d (2 weeks ago), 2024-10-24 08:01:25 -0700
    • Engine revision db49896cf2
    • Dart version 3.5.4
    • DevTools version 2.37.3

[✓] Android toolchain - develop for Android devices (Android SDK version 34.0.0)
    • Android SDK at /Users/bruno/Library/Android/sdk
    • Platform android-34, build-tools 34.0.0
    • Java binary at: /Applications/Android Studio.app/Contents/jbr/Contents/Home/bin/java
    • Java version OpenJDK Runtime Environment (build 17.0.7+0-17.0.7b1000.6-10550314)
    • All Android licenses accepted.

[✓] Xcode - develop for iOS and macOS (Xcode 16.1)
    • Xcode at /Applications/Xcode.app/Contents/Developer
    • Build 16B40
    • CocoaPods version 1.15.2

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

[✓] Android Studio (version 2023.1)
    • 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.7+0-17.0.7b1000.6-10550314)

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

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

• No issues found!
@brunosemfio brunosemfio added the bug Something isn't working label Nov 7, 2024
@nank1ro nank1ro self-assigned this Nov 8, 2024
@nank1ro
Copy link
Owner

nank1ro commented Nov 8, 2024

Fixed in the v0.15.2

@brunosemfio
Copy link
Author

@nank1ro Thank you for addressing the previous issue. The fix has helped, but a new problem has arisen.

When I add a widget in ShadSheet.title and/or ShadSheet.description, the list inside the ShadSheet no longer fills the available space as expected.

After reviewing the changes, I believe this issue could be resolved by removing the Flexible widget on lines 372 and 378, or by adding flex: 0 to the Flexible widgets in those lines. This adjustment should allow the list to use the available space correctly.

Thank you again for your help, and I appreciate your time looking into this!

Captura de Tela 2024-11-08 às 14 03 13

Captura de Tela 2024-11-08 às 14 02 57

@nank1ro
Copy link
Owner

nank1ro commented Nov 8, 2024

Can you share your code please?

@nank1ro nank1ro reopened this Nov 8, 2024
@brunosemfio
Copy link
Author

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

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

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

  @override
  Widget build(BuildContext context) {
    return ShadApp(
      home: Scaffold(
        body: LayoutBuilder(
          builder: (context, constraints) {
            return Center(
              child: ShadButton.ghost(
                onPressed: () {
                  showShadSheet(
                    context: context,
                    side: ShadSheetSide.right,
                    builder: (_) {
                      return ShadSheet(
                        title: const Text('title test'),
                        description: const Text('description test'),
                        constraints: BoxConstraints(
                          maxWidth: constraints.maxWidth * .8,
                          maxHeight: constraints.maxHeight,
                        ),
                        child: ListView.builder(
                          itemBuilder: (_, __) => const Text('test'),
                        ),
                      );
                    },
                  );
                },
                child: const Text('OPEN'),
              ),
            );
          },
        ),
      ),
    );
  }
}

@nank1ro
Copy link
Owner

nank1ro commented Nov 8, 2024

Can you try the following branch?

shadcn_ui:
    git:
      url: https://github.com/nank1ro/flutter-shadcn-ui
      ref: fix/dialog-child-constraints

Let me know if everything seems good now

@brunosemfio
Copy link
Author

Thank you for making the adjustments! I tested the widget with and without title and description, and also with and without actions. Everything is now working perfectly.

@nank1ro
Copy link
Owner

nank1ro commented Nov 8, 2024

Released the new version, v0.15.3

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants