Mic*_*l S 1 flutter flutter-layout
我喜欢增加小部件“B”的高度,以便橙色使用与绿色相同的空间。我添加了一个代码示例。如果添加了像 Expanded(Container(Text('B'))) 这样的 Extended() ,则会使用屏幕的整个水平空间。如果添加了类似 Column(Expanded(Container(Text('B')))) 的 Extended() ,则会使用屏幕的整个垂直空间。
有人有提示吗?先感谢您!
问候语
迈克尔
问题:
目标:
代码:
import 'package:flutter/material.dart';
void main() {
runApp(DemoX());
}
class DemoX extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
home: Scaffold(
body: SafeArea(
child: Row(
mainAxisSize: MainAxisSize.min,
children: [
Container(
color: Colors.red,
child: Container(
color: Colors.green,
child: Text('A1\nA2'),
),
),
Container(
color: Colors.orange,
child: Text('B'),
),
],
),
),
),
);
}
}
Run Code Online (Sandbox Code Playgroud)
截屏
代码:
@override
Widget build(BuildContext context) {
return Scaffold(
body: SafeArea(
child: IntrinsicHeight(
child: Row(
mainAxisSize: MainAxisSize.min,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Container(
color: Colors.green,
child: Text('A1\nA2'),
),
Container(
color: Colors.orange,
child: Text('B'),
),
],
),
),
),
);
}
Run Code Online (Sandbox Code Playgroud)