我试图将文本居中一行,但我也想将图像保持在左侧。我想把标题和描述放在右手边顶部中间的同一行。我已经尝试了几种解决方案,但要么没关系,要么图像会移动。所有内容都在ListView中实现。
import 'package:flutter/material.dart';
import 'package:cached_network_image/cached_network_image.dart';
import '../recyclerview/data.dart';
class ListViewExample extends StatefulWidget {
@override
State<StatefulWidget> createState() {
return new ListViewExampleState(
);
}
}
class ListViewExampleState extends State<ListViewExample>{
List<Container> _buildListItemsFromItems(){
int index = 0;
return item.map((item){
var container = Container(
decoration: index % 2 == 0?
new BoxDecoration(color: const Color(0xFFFFFFFF)):
new BoxDecoration(
color: const Color(0xFFFAFAF5)
),
child: new Row(
children: <Widget>[
new Container(
margin: new EdgeInsets.all(5.0),
child: new CachedNetworkImage(
imageUrl: item.imageURL,
width: 200.0,
height: 100.0,
fit: BoxFit.cover,
),
),
new Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
new Text(
item.title,
style: new TextStyle(),
),
new Text(
item.description,
),
]
)
],
)
);
index = index + 1;
return container;
}).toList();
}
@override
Widget build(BuildContext context) {
return new ListView(
children: _buildListItemsFromItems(),
);
}
}
提前感谢您的帮助!
更新:我已经添加了扩展小部件。
您可以用下面的类似扩展小部件的代码包装您的第二行:
Expanded(
child: Row(
mainAxisAlignment: MainAxisAlignment.center,
children: <Widget>[
Text(
item.title,
style: TextStyle(),
),
Text(
item.description,
style: TextStyle(),
),
]),
)