您可以通过将您的孩子嵌入 Widget 来实现这 Row
一点IntrinsicWidth
。
在此示例中,我还将父级嵌入到Row
WidgetIntrinsicHeight
中,以使子Row
级拉伸以匹配Wrap
.
完整的源代码
import 'package:flutter/material.dart';
void main() {
runApp(
MaterialApp(
debugShowCheckedModeBanner: false,
title: 'Flutter Demo',
home: HomePage(),
),
);
}
class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
body: IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Flexible(
child: Wrap(
children: [
Card(
child: Container(
color: Colors.blue.shade200,
padding:
EdgeInsets.symmetric(horizontal: 24.0, vertical: 8.0),
child: Text('Text 1'),
),
),
Card(
child: Container(
color: Colors.blue.shade200,
padding:
EdgeInsets.symmetric(horizontal: 24.0, vertical: 8.0),
child: Text('Text 2'),
),
),
],
),
),
IntrinsicWidth(
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
crossAxisAlignment: CrossAxisAlignment.stretch,
children: [
Card(
child: Container(
color: Colors.green.shade200,
padding:
EdgeInsets.symmetric(horizontal: 24.0, vertical: 8.0),
child: Text('Text A'),
),
),
Card(
child: Container(
color: Colors.green.shade200,
padding:
EdgeInsets.symmetric(horizontal: 24.0, vertical: 8.0),
child: Text('Text B'),
),
),
Card(
child: Container(
color: Colors.green.shade200,
padding:
EdgeInsets.symmetric(horizontal: 24.0, vertical: 8.0),
child: Text('Text C'),
),
),
],
),
),
],
),
),
);
}
}