gpt4 book ai didi

flutter : Image on ListTile leading too small

转载 作者:行者123 更新时间:2023-12-04 01:23:47 24 4
gpt4 key购买 nike

当我在 ConstrainedBox 中放置 ListTile 的前导时,我遇到了图像大小问题,图像太小,无法填充到更大的尺寸,有什么想法可以使此图像大小可以跟随 Card 的高度吗?

谢谢你。

Listview with Card

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 来做您想做的事情;)

使用容器、列和行,你可以做这样的事情(我只是一个例子,不要使用这个快速的坏代码;)):

enter image description here

    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")),
],
),
)
],
),
),
),
]),
),
);
}),
);
}
}

关于 flutter : Image on ListTile leading too small,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62211250/

24 4 0