flutter - Flutter:ListTile上的图像太小
问题描述
当我在 ConstrainedBox 中放置 ListTile 的前导时,我遇到了图像尺寸问题,图像太小,无法填充到更大的尺寸,有什么想法可以让这个图像尺寸跟随卡片的高度吗?
谢谢你。
ListTile(
leading: ConstrainedBox(
constraints:
BoxConstraints(minWidth: 100, minHeight: 100),
child: Image.network(
'http://www.malmalioboro.co.id/$gambar',
width: 100,
height: 100,
)),
title: Text(
nama,
style: TextStyle(
fontSize: 20.0, fontWeight: FontWeight.bold),
),
subtitle: Column(
children: <Widget>[
Row(
children: <Widget>[
Text(
'Barcode : ',
style: TextStyle(fontWeight: FontWeight.bold),
),
Text(
deskripsi,
style: TextStyle(fontSize: 15.0),
),
],
),
Row(
children: <Widget>[
Text(
'Harga : ',
style: TextStyle(
fontWeight: FontWeight.bold,
fontSize: 20),
),
Text(
harga,
style: TextStyle(fontSize: 20),
)
],
),
],
),
),
解决方案
使用自定义小部件而不是 ListTile。
创建了您自己的 ListTileCustom 来做您想做的事;)
使用容器、列和行,你可以做这样的事情(我只是一个例子,不要使用这个快速的坏代码;)):
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
// This widget is the root of your application.
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Flutter Demo',
theme: ThemeData(
primarySwatch: Colors.blue,
visualDensity: VisualDensity.adaptivePlatformDensity,
),
home: MyHomePage(title: 'Flutter Demo Home Page'),
);
}
}
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text(widget.title),
),
body: ListView.builder(
itemCount: 15,
itemBuilder: (context, index) {
return Card(
clipBehavior: Clip.antiAlias,
child: Container(
height: 120,
padding: const EdgeInsets.all(0),
child: Row(children: [
Expanded(
flex: 6,
child: Container(
decoration: BoxDecoration(
image: DecorationImage(
image: NetworkImage(
'https://live.staticflickr.com/3780/9134266649_3d2f1af95b_z.jpg'),
fit: BoxFit.fill)),
),
),
Spacer(
flex: 1,
),
Expanded(
flex: 14,
child: Container(
padding: const EdgeInsets.only(top: 5),
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
Text("Title",
style: TextStyle(
fontSize: 20.0, fontWeight: FontWeight.bold)),
Row(
children: <Widget>[
Text(
'Barcode : ',
style: TextStyle(fontWeight: FontWeight.bold),
),
Text(
"barcode",
style: TextStyle(fontSize: 15.0),
),
],
),
Row(
children: <Widget>[
Text(
'Harga : ',
style: TextStyle(
fontWeight: FontWeight.bold, fontSize: 20),
),
Text(
'harga',
style: TextStyle(fontSize: 20),
)
],
),
Align(
alignment: Alignment.bottomRight,
child: Row(
mainAxisAlignment: MainAxisAlignment.end,
children: <Widget>[
FlatButton(
onPressed: null,
child: Text("DETAIL ITEM")),
FlatButton(
onPressed: null, child: Text("BELI")),
],
),
)
],
),
),
),
]),
),
);
}),
);
}
}
推荐阅读
- python - 我们什么时候使用 return 来调用同一个类中的函数,什么时候我们只调用它们而不使用 return?
- python - 在 python pandas 中使用 tkinker 的不同错误消息
- stripe-payments - 如何在 Stripe 中更改 paymentintent 的目的地?
- flutter - 不推荐使用 Flutter FlatButton - 替代解决方案
- elasticsearch - 有没有办法在汇总后显示文档?
- reactjs - 如何使用 expo cli(React Native)发送 OTP SMS 并从收到的消息中自动填充 OTP 字段?
- c# - 枚举我的方法来处理任何超时问题
- python - 使代码更高效(python)-初学者
- swift - 在 MacOS 上的 Swift 中使用 CGEvent.tapCreate 捕获鼠标事件
- javascript - 数组推送用新数据替换旧数据