Skip to content

Instantly share code, notes, and snippets.

@sho-ito-1027
Created August 30, 2021 13:25
Show Gist options
  • Save sho-ito-1027/8ec1c47dada7004aeebafcf4ee6c0bf7 to your computer and use it in GitHub Desktop.
Save sho-ito-1027/8ec1c47dada7004aeebafcf4ee6c0bf7 to your computer and use it in GitHub Desktop.
ListTileのleading、titleを使う場合の高さ変更可能な模倣Widget
import 'package:flutter/material.dart';
void main() {
runApp(
const MaterialApp(
home: MyHomePage(),
),
);
}
class MyHomePage extends StatelessWidget {
const MyHomePage({Key? key}) : super(key: key);
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: const Text('leading & title'),
),
body: ListView(
children: [
ImitationListTile(
height: 64,
leading: const Icon(Icons.home),
title: const Text('タイトル'),
onTap: () {
// ImitationListTile処理
},
),
const Divider(height: 1),
ImitationListTile(
height: 100,
leading: const Icon(Icons.wb_sunny),
title: const Text('タイトル'),
onTap: () {
// ImitationListTile処理
}
),
const Divider(height: 1),
],
),
);
}
}
class ImitationListTile extends StatelessWidget {
const ImitationListTile({
Key? key,
required this.leading,
required this.title,
this.height,
this.onTap,
}) : super(key: key);
final Icon leading;
final Text title;
final double? height;
final VoidCallback? onTap;
@override
Widget build(BuildContext context) {
final _height = height ?? 54.0;
return InkWell(
child: ConstrainedBox(
constraints: BoxConstraints(minHeight: _height),
child: Padding(
padding: const EdgeInsets.all(16.0),
child: Row(
children: [
leading,
const SizedBox(width: 32.0),
title,
],
),
),
),
onTap: onTap,
);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment