-
Notifications
You must be signed in to change notification settings - Fork 30.1k
Description
Setting IndexedStack.sizing to StackFit.expand does not cause children to expand to fill the space. The sizing constructor argument is passed to super as Stack.fit, but IndexedStack uses a different RenderObject that doesn't use the value.
A working workaround is to wrap children with Positioned.fill.
Steps to Reproduce
- Execute
flutter runon the code sample
Expected results: The child should be expanded to fit the size of the IndexedStack.

Actual results: The child renders at its intrinsic size.

Code sample
import 'package:flutter/material.dart';
void main() {
runApp(const MyApp());
}
class MyApp extends StatelessWidget {
const MyApp({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: const MyHomePage(),
);
}
}
class MyHomePage extends StatelessWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) => Scaffold(
body: IndexedStack(
index: 0,
// StackFit.expand does not give desired result:
sizing: StackFit.expand,
children: const [
ContentWidget(),
// wrapping with Positioned.fill gives desired result:
// Positioned.fill(child: ContentWidget()),
],
),
);
}
class ContentWidget extends StatelessWidget {
const ContentWidget({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) => Container(
color: Colors.deepPurpleAccent,
child: const Text('Some Content'),
);
}
Logs
[I] ➜ flutter doctor -v
[✓] Flutter (Channel stable, 3.0.5, on macOS 12.4 21F79 darwin-arm, locale en-US)
• Flutter version 3.0.5 at /opt/homebrew/Caskroom/flutter/2.2.2/flutter
• Upstream repository https://github.com/flutter/flutter.git
• Framework revision f1875d5 (4 weeks ago), 2022-07-13 11:24:16 -0700
• Engine revision e85ea0e79c
• Dart version 2.17.6
• DevTools version 2.12.2
[✓] Android toolchain - develop for Android devices (Android SDK version 30.0.3)
• Android SDK at /Users/austin/Library/Android/sdk
• Platform android-33, build-tools 30.0.3
• ANDROID_HOME = /Users/austin/Library/Android/sdk
• ANDROID_SDK_ROOT = /Users/austin/Library/Android/sdk
• Java binary at: /Library/Java/JavaVirtualMachines/zulu-16.jdk/Contents/Home/bin/java
• Java version OpenJDK Runtime Environment Zulu16.30+19-CA (build 16.0.1+9)
• All Android licenses accepted.
[✓] Xcode - develop for iOS and macOS (Xcode 13.4.1)
• Xcode at /Applications/Xcode.app/Contents/Developer
• CocoaPods version 1.11.3
[✓] Android Studio (version 2021.2)
• 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 11.0.12+0-b1504.28-7817840)
[✓] IntelliJ IDEA Ultimate Edition (version 2021.2.1)
• IntelliJ at /Applications/IntelliJ IDEA.app
• Flutter plugin version 59.0.4
• Dart plugin version 212.5080.8
[✓] VS Code (version 1.58.2)
• VS Code at /Users/austin/Downloads/Visual Studio Code.app/Contents
• Flutter extension version 3.25.0
[✓] Connected device (2 available)
• Austin’s iPad (mobile) • 00008020-000D0C4E2105002E • ios • iOS 15.5 19F77
• macOS (desktop) • macos • darwin-arm64 • macOS 12.4 21F79 darwin-arm
[✓] HTTP Host Availability
• All required HTTP hosts are available
• No issues found!