使用IntrinsicHeight
小部件包装您的Row
,然后使用Expanded
小部件包装使这些点形状的小部件。
那么,您的项目将如下所示:
Widget _buildItem(String text) {
return IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [Text('01:59 AM'), Text('07:30 PM')]),
Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 7,
height: 7,
decoration: BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
),
),
Expanded(
child: Container(width: 2, color: Colors.grey),
),
Container(
width: 7,
height: 7,
decoration: BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
),
),
],
),
Text(text)
],
),
);
}
这里是输出的用户界面:
![最终输出的用户界面](https://istack.dev59.com/t3sIt.webp)
完整的代码示例:
import 'package:flutter/material.dart';
void main() => runApp(MyApp());
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
debugShowCheckedModeBanner: false,
theme: ThemeData(
primarySwatch: Colors.blue,
),
home: MyHomePage(),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key}) : super(key: key);
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
body: ListView(
padding: EdgeInsets.all(8),
children: [
_buildItem('''texttexttexttexttexttexttexttexttexttexttexttexttexttext
texttexttexttexttexttexttexttexttexttexttexttexttexttext
texttexttexttexttexttexttexttexttexttexttexttexttexttext
texttexttexttexttexttexttexttexttexttexttexttexttexttext
texttexttexttexttexttexttexttexttexttexttexttexttexttext
texttexttexttexttexttexttexttexttexttexttexttexttexttext'''),
Divider(
color: Colors.grey,
thickness: .5,
),
_buildItem('''texttexttexttexttexttexttexttexttexttexttexttexttexttext
texttexttexttexttexttexttexttexttexttexttexttexttexttext
texttexttexttexttexttexttexttexttexttexttexttexttexttext'''),
Divider(
color: Colors.grey,
thickness: .5,
),
_buildItem('''texttexttexttexttexttexttexttexttexttexttexttexttexttext
texttexttexttexttexttexttexttexttexttexttexttexttexttext
texttexttexttexttexttexttexttexttexttexttexttexttexttext
texttexttexttexttexttexttexttexttexttexttexttexttexttext
texttexttexttexttexttexttexttexttexttexttexttexttexttext
texttexttexttexttexttexttexttexttexttexttexttexttexttext
texttexttexttexttexttexttexttexttexttexttexttexttexttext
texttexttexttexttexttexttexttexttexttexttexttexttexttext
texttexttexttexttexttexttexttexttexttexttexttexttexttext
texttexttexttexttexttexttexttexttexttexttexttexttexttext
texttexttexttexttexttexttexttexttexttexttexttexttexttext'''),
Divider(
color: Colors.grey,
thickness: .5,
),
_buildItem(
'''texttexttexttexttexttexttexttexttexttexttexttexttexttext'''),
],
));
}
Widget _buildItem(String text) {
return IntrinsicHeight(
child: Row(
crossAxisAlignment: CrossAxisAlignment.center,
mainAxisAlignment: MainAxisAlignment.spaceAround,
children: [
Column(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [Text('01:59 AM'), Text('07:30 PM')]),
Column(
mainAxisSize: MainAxisSize.min,
children: [
Container(
width: 7,
height: 7,
decoration: BoxDecoration(
color: Colors.green,
shape: BoxShape.circle,
),
),
Expanded(
child: Container(width: 2, color: Colors.grey),
),
Container(
width: 7,
height: 7,
decoration: BoxDecoration(
color: Colors.red,
shape: BoxShape.circle,
),
),
],
),
Text(text)
],
),
);
}
}