flutter / flutter

Flutter makes it easy and fast to build beautiful apps for mobile and beyond
https://flutter.dev
BSD 3-Clause "New" or "Revised" License
165.71k stars 27.36k forks source link

ListView inside several Containers inside Column ignores parent constraints #151023

Closed Kaltt-github closed 3 months ago

Kaltt-github commented 3 months ago

Steps to reproduce

  1. Create a Scaffold
  2. Create a Column inside the Scaffold
  3. Create a Container and more Containers inside of it
  4. Give fixed heights to the Container, each one smaller than its parent
  5. Create a ListView inside the smallest container

Expected results

A list view taking the height of the direct parent. Note: This situation came up from a bigger screen, with more widgets involved, the posted code is the minimized version of the classes and widget in the tree for an easy visualization of the bug. It is not possible to remove the Containers "in the way" from the Column to the ListView due widgets and state managment.

Actual results

A list view taking the height of closest Container to the Column, ignoring all constraints and stretching all the parents involved.

Code sample

Code sample ```dart import 'package:flutter/material.dart'; void main() { runApp(const MyApp()); } class MyApp extends StatelessWidget { const MyApp({super.key}); // This widget is the root of your application. @override Widget build(BuildContext context) { return MaterialApp( title: 'Flutter Demo', theme: ThemeData( useMaterial3: true, colorScheme: ColorScheme.fromSeed( seedColor: Colors.blue, brightness: Brightness.light, ), ), home: const WidgetTest(), ); } } class WidgetTest extends StatefulWidget { const WidgetTest({super.key}); @override State createState() => _WidgetTestState(); } class _WidgetTestState extends State { @override Widget build(BuildContext context) { return Scaffold( body: Column( children: [ Container( color: Colors.amber, height: 200, child: Container( color: Colors.green, height: 50, child: ListView.builder( itemCount: 100, itemBuilder: (context, index) => Container( height: 20, color: Colors.red[(index * 100) % 900 + 100], child: Text('$index'), ), ), ), ), ], )); } } ```

Screenshots or Video

Screenshots / Video demonstration Expected ![image](https://github.com/flutter/flutter/assets/115120050/66fec572-40c2-4277-9b30-87f860f30cb8) Actual ![image](https://github.com/flutter/flutter/assets/115120050/257001eb-bf11-4964-8dcc-a3eff25c84be)

Logs

Logs ```console Launching lib\main.dart on Windows in debug mode... √ Built build\windows\x64\runner\Debug\production.exe Connecting to VM Service at ws://127.0.0.1:62387/vlgefRs0g98=/ws```

Flutter Doctor output

Doctor output ```console flutter doctor -v [√] Flutter (Channel stable, 3.22.0, on Microsoft Windows [Versi¢n 10.0.19045.4412], locale es-ES) • Flutter version 3.22.0 on channel stable at C:\src\flutter • Upstream repository https://github.com/flutter/flutter.git • Framework revision 5dcb86f68f (7 weeks ago), 2024-05-09 07:39:20 -0500 • Engine revision f6344b75dc • Dart version 3.4.0 • DevTools version 2.34.3 [√] Windows Version (Installed version of Windows is version 10 or higher) [√] Android toolchain - develop for Android devices (Android SDK version 33.0.1) • Android SDK at C:\Users\Emanuel\AppData\Local\Android\sdk • Platform android-34, build-tools 33.0.1 • Java binary at: C:\Program Files\Android\Android Studio\jbr\bin\java • Java version OpenJDK Runtime Environment (build 17.0.9+0--11185874) • All Android licenses accepted. [√] Chrome - develop for the web • Chrome at C:\Program Files\Google\Chrome\Application\chrome.exe [√] Visual Studio - develop Windows apps (Visual Studio Professional 2022 17.5.4) • Visual Studio at C:\Program Files\Microsoft Visual Studio\2022\Professional • Visual Studio Professional 2022 version 17.5.33530.505 • Windows 10 SDK version 10.0.22000.0 [√] Android Studio (version 2023.2) • Android Studio at C:\Program Files\Android\Android Studio • 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.9+0--11185874) [√] VS Code (version 1.90.2) • VS Code at C:\Users\Emanuel\AppData\Local\Programs\Microsoft VS Code • Flutter extension version 3.90.0 [√] Connected device (3 available) • Windows (desktop) • windows • windows-x64 • Microsoft Windows [Versi¢n 10.0.19045.4412] • Chrome (web) • chrome • web-javascript • Google Chrome 126.0.6478.127 • Edge (web) • edge • web-javascript • Microsoft Edge 126.0.2592.68 [√] Network resources • All expected network resources are available. • No issues found! ```
Kaltt-github commented 3 months ago

Sorry for the issue! It was not a LIstView problem, the bug was at the Container, they need position and size, adding an Align fix it!

github-actions[bot] commented 3 months ago

This thread has been automatically locked since there has not been any recent activity after it was closed. If you are still experiencing a similar issue, please open a new bug, including the output of flutter doctor -v and a minimal reproduction of the issue.