Skip to content

Commit

Permalink
feat: update semantics and versions (#20)
Browse files Browse the repository at this point in the history
  • Loading branch information
AnnaPS authored Feb 12, 2024
1 parent 13a666b commit f7ace43
Show file tree
Hide file tree
Showing 14 changed files with 183 additions and 115 deletions.
3 changes: 0 additions & 3 deletions lib/app/view/app.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,6 @@ class App extends StatelessWidget {
return MaterialApp(
theme: ThemeData(
appBarTheme: const AppBarTheme(color: Color(0xFF13B9FF)),
colorScheme: ColorScheme.fromSwatch(
accentColor: const Color(0xFF13B9FF),
),
),
localizationsDelegates: AppLocalizations.localizationsDelegates,
supportedLocales: AppLocalizations.supportedLocales,
Expand Down
14 changes: 11 additions & 3 deletions lib/favorites/view/favorites_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,10 @@ class FavoritesDogs extends StatelessWidget {
final favoriteDogs =
context.select((HomeBloc bloc) => bloc.state.favoriteDogs);

final textStyle = Theme.of(context).textTheme;
final subtitleSytle = textStyle.bodySmall;
final fontSize = subtitleSytle?.fontSize;

return ListView.builder(
padding: const EdgeInsets.symmetric(horizontal: 8, vertical: 16),
itemBuilder: (context, index) {
Expand All @@ -33,26 +37,30 @@ class FavoritesDogs extends StatelessWidget {
children: [
MergeSemantics(
child: ListTile(
isThreeLine: true,
leading: ItemCardImage(image: dog.image, label: dog.imageLabel),
title: Text(dog.title),
subtitle: Text(dog.description),
trailing: Semantics(
button: true,
label: 'Remove button',
label: 'Button to remove ${dog.title} from favorites page',
onTap: () => _updateFavorites(context, dog),
onTapHint: 'Remove ${dog.title} from favorites',
enabled: true,
focusable: true,
image: true,
textDirection: TextDirection.ltr,
child: IconButton(
icon: const Icon(Icons.delete),
icon: AppIcon(
icon: Icons.delete,
fontSize: fontSize!,
label: 'Delete icon',
),
onPressed: () => _updateFavorites(context, dog),
),
),
),
),
const ExcludeSemantics(child: Divider()),
],
);
},
Expand Down
16 changes: 14 additions & 2 deletions lib/home/view/home_page.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ class HomePage extends StatelessWidget {
@override
Widget build(BuildContext context) {
final l10n = context.l10n;

// By default, the font size for BottomNavigationBar labels is 14.0.
const bottomNavFontSize = 14.0;

final selectedIndex =
context.select((HomeBloc bloc) => bloc.state.selectedIndex);

Expand Down Expand Up @@ -41,12 +45,20 @@ class HomePage extends StatelessWidget {
currentIndex: selectedIndex,
items: const [
BottomNavigationBarItem(
icon: Icon(Icons.home),
icon: AppIcon(
icon: Icons.home,
fontSize: bottomNavFontSize,
label: 'Home tab icon',
),
label: 'Home',
tooltip: 'Home page',
),
BottomNavigationBarItem(
icon: Icon(Icons.favorite),
icon: AppIcon(
icon: Icons.favorite,
fontSize: bottomNavFontSize,
label: 'Favorites tab icon',
),
label: 'Favorites',
tooltip: 'Favorites page',
),
Expand Down
34 changes: 34 additions & 0 deletions lib/home/widgets/app_icon.dart
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
import 'package:flutter/material.dart';

/// {@template app_icon}
/// A reusable [Icon] that scales with the current font size.
/// {@endtemplate}
class AppIcon extends StatelessWidget {
/// {@macro app_icon}
const AppIcon({
required this.icon,
required this.fontSize,
required this.label,
super.key,
});

/// The icon to display.
final IconData icon;

/// The size of the current font.
final double fontSize;

/// final label
final String label;

@override
Widget build(BuildContext context) {
final textScaleFactor = MediaQuery.textScalerOf(context);

return Icon(
icon,
semanticLabel: label,
size: textScaleFactor.scale(fontSize) * 1.5,
);
}
}
6 changes: 3 additions & 3 deletions lib/home/widgets/item_card.dart
Original file line number Diff line number Diff line change
Expand Up @@ -33,21 +33,21 @@ class ItemCard extends StatelessWidget {
),
),
),
const SizedBox(height: 8),
const ExcludeSemantics(child: SizedBox(height: 8)),
Flexible(
child: IndexedSemantics(
index: 1,
child: ItemCardTitle(title: dog.title),
),
),
const SizedBox(height: 16),
const ExcludeSemantics(child: SizedBox(height: 16)),
Flexible(
child: IndexedSemantics(
index: 2,
child: ItemCardDescription(description: dog.description),
),
),
const SizedBox(height: 16),
const ExcludeSemantics(child: SizedBox(height: 16)),
Flexible(
child: IndexedSemantics(
index: 3,
Expand Down
5 changes: 3 additions & 2 deletions lib/home/widgets/item_card_description.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,14 @@ class ItemCardDescription extends StatelessWidget {

@override
Widget build(BuildContext context) {
final textScaleFactor = MediaQuery.of(context).textScaleFactor;
final theme = Theme.of(context);

return Padding(
padding: const EdgeInsets.all(8),
child: Text(
description,
style: theme.textTheme.bodyMedium,
semanticsLabel: description,
textScaleFactor: textScaleFactor * 1,
),
);
}
Expand Down
7 changes: 5 additions & 2 deletions lib/home/widgets/item_card_title.dart
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,16 @@ class ItemCardTitle extends StatelessWidget {

@override
Widget build(BuildContext context) {
final textScaleFactor = MediaQuery.of(context).textScaleFactor;
final theme = Theme.of(context);

return Padding(
padding: const EdgeInsets.all(8),
child: Text(
title,
style: theme.textTheme.bodyLarge?.copyWith(
fontWeight: FontWeight.w500,
),
semanticsLabel: title,
textScaleFactor: textScaleFactor * 1.5,
),
);
}
Expand Down
13 changes: 8 additions & 5 deletions lib/home/widgets/item_favorite_button.dart
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ class ItemFavoriteButton extends StatelessWidget {
? 'Remove ${dog.title} from favorites'
: 'Add ${dog.title} to favorites';

final label = isFavorite ? 'Remove button' : 'Add button';
const iconLabel = 'Heart button icon';
final label = isFavorite
? 'Button to remove ${dog.title} from favorites'
: 'Button to add ${dog.title} to favorites';
const iconLabel = 'Heart icon';

return Align(
alignment: Alignment.centerRight,
Expand All @@ -33,9 +35,10 @@ class ItemFavoriteButton extends StatelessWidget {
onTap: () => _updateFavorites(context),
onTapHint: onTapHint,
child: IconButton(
icon: Icon(
isFavorite ? Icons.favorite : Icons.favorite_border,
semanticLabel: iconLabel,
icon: AppIcon(
icon: isFavorite ? Icons.favorite : Icons.favorite_border,
fontSize: 14,
label: iconLabel,
),
onPressed: () => _updateFavorites(context),
),
Expand Down
1 change: 1 addition & 0 deletions lib/home/widgets/widgets.dart
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export 'app_icon.dart';
export 'item_card.dart';
export 'item_card_description.dart';
export 'item_card_image.dart';
Expand Down
Loading

0 comments on commit f7ace43

Please sign in to comment.