Flutter Imageウェジェットを使ってListTileの左側に画像を表示する

環境
Windows11 pro 64bit
Flutter 3.3.7

構文
ListTile(
leading: Image(),
title: Text('test12’),
);
引数「leading」とImageウェジェットを使って、ListTileの左側に画像を表示します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
@override
Widget build(BuildContext context) {
return Scaffold(
body: Center(
child: ListView.builder(
shrinkWrap: true,
itemBuilder: (context, index) {
return ListTile(
leading: Image.asset(
'asset/images/xxx.png',
height: 65,
width: 65,
fit: BoxFit.fitHeight,
),
title: Text('Test ${index + 1}'),
);
},
itemCount: 3,
),
),
);
}
@override Widget build(BuildContext context) { return Scaffold( body: Center( child: ListView.builder( shrinkWrap: true, itemBuilder: (context, index) { return ListTile( leading: Image.asset( 'asset/images/xxx.png', height: 65, width: 65, fit: BoxFit.fitHeight, ), title: Text('Test ${index + 1}'), ); }, itemCount: 3, ), ), ); }
@override
 Widget build(BuildContext context) {
   return Scaffold(
     body: Center(
       child: ListView.builder(
         shrinkWrap: true,
         itemBuilder: (context, index) {
           return ListTile(
             leading: Image.asset(
               'asset/images/xxx.png',
               height: 65,
               width: 65,
               fit: BoxFit.fitHeight,
             ),
             title: Text('Test ${index + 1}'),
           );
         },
         itemCount: 3,
       ),
     ),
   );
 }

 

Flutter

Posted by arkgame