Skip to content

Commit

Permalink
fix: listtile theme
Browse files Browse the repository at this point in the history
  • Loading branch information
Feichtmeier committed Oct 27, 2024
1 parent 0a122e7 commit adbc04c
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 7 deletions.
17 changes: 11 additions & 6 deletions example/lib/src/containers/containers_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ import 'package:flutter/material.dart';
import '../build_context_x.dart';
import '../constants.dart';

final _icons = [
Icons.add_reaction_sharp,
Icons.yard,
Icons.baby_changing_station,
Icons.cabin,
];

class ContainersView extends StatefulWidget {
const ContainersView({super.key});

Expand All @@ -13,12 +20,8 @@ class ContainersView extends StatefulWidget {
class _ContainersViewState extends State<ContainersView> {
var _elevation = 2.0;
var _inDialog = true;
final _icons = [
Icons.add_reaction_sharp,
Icons.yard,
Icons.baby_changing_station,
Icons.cabin,
];

final _selected = List.generate(_icons.length, (index) => false);

@override
Widget build(BuildContext context) {
Expand Down Expand Up @@ -89,6 +92,8 @@ class _ContainersViewState extends State<ContainersView> {
containerWithBorder,
for (var i = 0; i < _icons.length; i++)
ListTile(
selected: _selected[i],
onTap: () => setState(() => _selected[i] = !_selected[i]),
leading: Icon(_icons[i]),
title: Text('ListTile title $i'),
subtitle: i.isEven ? null : const Text('Subtitle'),
Expand Down
2 changes: 1 addition & 1 deletion example/pubspec.lock
Original file line number Diff line number Diff line change
Expand Up @@ -209,4 +209,4 @@ packages:
version: "14.2.5"
sdks:
dart: ">=3.3.0 <4.0.0"
flutter: ">=3.24.0"
flutter: ">=3.24.3"
23 changes: 23 additions & 0 deletions lib/src/theme.dart
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,7 @@ ThemeData _phoenixTheme({
cardTheme: _cardTheme(colorScheme),
drawerTheme: _drawerTheme(colorScheme),
inputDecorationTheme: _inputDecorationTheme(colorScheme),
listTileTheme: _createListTileTheme(colorScheme),
);
}

Expand Down Expand Up @@ -548,3 +549,25 @@ SnackBarThemeData _snackBarThemeData(ColorScheme colorScheme) {
),
);
}

ListTileThemeData _createListTileTheme(ColorScheme colorScheme) {
final isHighContrast =
[Colors.black, Colors.white].contains(colorScheme.primary);

return ListTileThemeData(
selectedColor:
isHighContrast ? colorScheme.onInverseSurface : colorScheme.onSurface,
iconColor: colorScheme.onSurface.withOpacity(0.8),
selectedTileColor: isHighContrast
? colorScheme.inverseSurface
: colorScheme.onSurface.withOpacity(
colorScheme.brightness == Brightness.dark ? 0.035 : 0.04,
),
minVerticalPadding: 6,
visualDensity: const VisualDensity(horizontal: -4, vertical: -4),
shape: const RoundedRectangleBorder(
borderRadius: BorderRadius.all(Radius.circular(6)),
side: BorderSide.none,
),
);
}

0 comments on commit adbc04c

Please sign in to comment.