Skip to content

Commit adbc04c

Browse files
committed
fix: listtile theme
1 parent 0a122e7 commit adbc04c

File tree

3 files changed

+35
-7
lines changed

3 files changed

+35
-7
lines changed

example/lib/src/containers/containers_view.dart

+11-6
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,13 @@ import 'package:flutter/material.dart';
33
import '../build_context_x.dart';
44
import '../constants.dart';
55

6+
final _icons = [
7+
Icons.add_reaction_sharp,
8+
Icons.yard,
9+
Icons.baby_changing_station,
10+
Icons.cabin,
11+
];
12+
613
class ContainersView extends StatefulWidget {
714
const ContainersView({super.key});
815

@@ -13,12 +20,8 @@ class ContainersView extends StatefulWidget {
1320
class _ContainersViewState extends State<ContainersView> {
1421
var _elevation = 2.0;
1522
var _inDialog = true;
16-
final _icons = [
17-
Icons.add_reaction_sharp,
18-
Icons.yard,
19-
Icons.baby_changing_station,
20-
Icons.cabin,
21-
];
23+
24+
final _selected = List.generate(_icons.length, (index) => false);
2225

2326
@override
2427
Widget build(BuildContext context) {
@@ -89,6 +92,8 @@ class _ContainersViewState extends State<ContainersView> {
8992
containerWithBorder,
9093
for (var i = 0; i < _icons.length; i++)
9194
ListTile(
95+
selected: _selected[i],
96+
onTap: () => setState(() => _selected[i] = !_selected[i]),
9297
leading: Icon(_icons[i]),
9398
title: Text('ListTile title $i'),
9499
subtitle: i.isEven ? null : const Text('Subtitle'),

example/pubspec.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -209,4 +209,4 @@ packages:
209209
version: "14.2.5"
210210
sdks:
211211
dart: ">=3.3.0 <4.0.0"
212-
flutter: ">=3.24.0"
212+
flutter: ">=3.24.3"

lib/src/theme.dart

+23
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,7 @@ ThemeData _phoenixTheme({
118118
cardTheme: _cardTheme(colorScheme),
119119
drawerTheme: _drawerTheme(colorScheme),
120120
inputDecorationTheme: _inputDecorationTheme(colorScheme),
121+
listTileTheme: _createListTileTheme(colorScheme),
121122
);
122123
}
123124

@@ -548,3 +549,25 @@ SnackBarThemeData _snackBarThemeData(ColorScheme colorScheme) {
548549
),
549550
);
550551
}
552+
553+
ListTileThemeData _createListTileTheme(ColorScheme colorScheme) {
554+
final isHighContrast =
555+
[Colors.black, Colors.white].contains(colorScheme.primary);
556+
557+
return ListTileThemeData(
558+
selectedColor:
559+
isHighContrast ? colorScheme.onInverseSurface : colorScheme.onSurface,
560+
iconColor: colorScheme.onSurface.withOpacity(0.8),
561+
selectedTileColor: isHighContrast
562+
? colorScheme.inverseSurface
563+
: colorScheme.onSurface.withOpacity(
564+
colorScheme.brightness == Brightness.dark ? 0.035 : 0.04,
565+
),
566+
minVerticalPadding: 6,
567+
visualDensity: const VisualDensity(horizontal: -4, vertical: -4),
568+
shape: const RoundedRectangleBorder(
569+
borderRadius: BorderRadius.all(Radius.circular(6)),
570+
side: BorderSide.none,
571+
),
572+
);
573+
}

0 commit comments

Comments
 (0)