Skip to content

Commit

Permalink
Fix onKey handler return values (flutter#473)
Browse files Browse the repository at this point in the history
This fixes the return values for the onKey handlers used in the gallery code to use the newer KeyEventResult values, rather than bools. The use of the bools will soon be deprecated.
  • Loading branch information
gspencergoog authored Apr 12, 2021
1 parent 2bb63d1 commit 4655d32
Show file tree
Hide file tree
Showing 9 changed files with 106 additions and 112 deletions.
29 changes: 12 additions & 17 deletions lib/codeviewer/code_segments.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7003,64 +7003,61 @@ class CodeSegments {
TextSpan(style: codeStyle.punctuationStyle, text: '.'),
TextSpan(
style: codeStyle.baseStyle,
text: 'tappable\u000a '),
text: 'tappable\u000a '),
TextSpan(style: codeStyle.punctuationStyle, text: '?'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(
style: codeStyle.classStyle, text: 'TappableTravelDestinationItem'),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(
style: codeStyle.baseStyle,
text: '\u000a destination'),
TextSpan(style: codeStyle.baseStyle, text: 'destination'),
TextSpan(style: codeStyle.punctuationStyle, text: ':'),
TextSpan(style: codeStyle.baseStyle, text: ' destination'),
TextSpan(style: codeStyle.punctuationStyle, text: ')'),
TextSpan(
style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.punctuationStyle, text: ':'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(
style: codeStyle.classStyle, text: 'SelectableTravelDestinationItem'),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(
style: codeStyle.baseStyle,
text: '\u000a destination'),
text: '\u000a destination'),
TextSpan(style: codeStyle.punctuationStyle, text: ':'),
TextSpan(style: codeStyle.baseStyle, text: ' destination'),
TextSpan(style: codeStyle.punctuationStyle, text: ','),
TextSpan(
style: codeStyle.baseStyle,
text: '\u000a isSelected'),
text: '\u000a isSelected'),
TextSpan(style: codeStyle.punctuationStyle, text: ':'),
TextSpan(style: codeStyle.baseStyle, text: ' _isSelected'),
TextSpan(style: codeStyle.punctuationStyle, text: '.'),
TextSpan(style: codeStyle.baseStyle, text: 'value'),
TextSpan(style: codeStyle.punctuationStyle, text: ','),
TextSpan(
style: codeStyle.baseStyle,
text: '\u000a onSelected'),
text: '\u000a onSelected'),
TextSpan(style: codeStyle.punctuationStyle, text: ':'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.punctuationStyle, text: '()'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.punctuationStyle, text: '{'),
TextSpan(
style: codeStyle.baseStyle,
text: '\u000a print'),
text: '\u000a print'),
TextSpan(style: codeStyle.punctuationStyle, text: '('),
TextSpan(
style: codeStyle.stringStyle,
text: '\u0027Selectable card state changed\u0027'),
TextSpan(style: codeStyle.punctuationStyle, text: ');'),
TextSpan(
style: codeStyle.baseStyle,
text: '\u000a setState'),
text: '\u000a setState'),
TextSpan(style: codeStyle.punctuationStyle, text: '(()'),
TextSpan(style: codeStyle.baseStyle, text: ' '),
TextSpan(style: codeStyle.punctuationStyle, text: '{'),
TextSpan(
style: codeStyle.baseStyle,
text: '\u000a _isSelected'),
text: '\u000a _isSelected'),
TextSpan(style: codeStyle.punctuationStyle, text: '.'),
TextSpan(style: codeStyle.baseStyle, text: 'value '),
TextSpan(style: codeStyle.punctuationStyle, text: '='),
Expand All @@ -7071,15 +7068,13 @@ class CodeSegments {
TextSpan(style: codeStyle.baseStyle, text: 'value'),
TextSpan(style: codeStyle.punctuationStyle, text: ';'),
TextSpan(
style: codeStyle.baseStyle,
text: '\u000a '),
style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.punctuationStyle, text: '});'),
TextSpan(
style: codeStyle.baseStyle,
text: '\u000a '),
style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.punctuationStyle, text: '},'),
TextSpan(
style: codeStyle.baseStyle, text: '\u000a '),
style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.punctuationStyle, text: '),'),
TextSpan(style: codeStyle.baseStyle, text: '\u000a '),
TextSpan(style: codeStyle.punctuationStyle, text: '),'),
Expand Down
23 changes: 11 additions & 12 deletions lib/demos/material/cards_demo.dart
Original file line number Diff line number Diff line change
Expand Up @@ -409,18 +409,17 @@ class _CardsDemoState extends State<CardsDemo> with RestorationMixin {
child: (destination.cardType == CardType.standard)
? TravelDestinationItem(destination: destination)
: destination.cardType == CardType.tappable
? TappableTravelDestinationItem(
destination: destination)
: SelectableTravelDestinationItem(
destination: destination,
isSelected: _isSelected.value,
onSelected: () {
print('Selectable card state changed');
setState(() {
_isSelected.value = !_isSelected.value;
});
},
),
? TappableTravelDestinationItem(destination: destination)
: SelectableTravelDestinationItem(
destination: destination,
isSelected: _isSelected.value,
onSelected: () {
print('Selectable card state changed');
setState(() {
_isSelected.value = !_isSelected.value;
});
},
),
),
],
),
Expand Down
4 changes: 2 additions & 2 deletions lib/layout/highlight_focus.dart
Original file line number Diff line number Diff line change
Expand Up @@ -82,9 +82,9 @@ class _HighlightFocusState extends State<HighlightFocus> {
event.logicalKey == LogicalKeyboardKey.enter ||
event.logicalKey == LogicalKeyboardKey.numpadEnter)) {
widget.onPressed();
return true;
return KeyEventResult.handled;
} else {
return false;
return KeyEventResult.ignored;
}
},
child: Container(
Expand Down
4 changes: 2 additions & 2 deletions lib/studies/crane/backdrop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ class _FrontLayerState extends State<_FrontLayer> {
final crossAxisCount = isSmallDesktop
? 2
: isDesktop
? 4
: 1;
? 4
: 1;

return FocusTraversalGroup(
policy: ReadingOrderTraversalPolicy(),
Expand Down
4 changes: 2 additions & 2 deletions lib/studies/rally/login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -301,10 +301,10 @@ class _ThumbButtonState extends State<_ThumbButton> {
if (event.logicalKey == LogicalKeyboardKey.enter ||
event.logicalKey == LogicalKeyboardKey.space) {
widget.onTap();
return true;
return KeyEventResult.handled;
}
}
return false;
return KeyEventResult.ignored;
},
onFocusChange: (hasFocus) {
if (hasFocus) {
Expand Down
124 changes: 62 additions & 62 deletions lib/studies/reply/adaptive_nav.dart
Original file line number Diff line number Diff line change
Expand Up @@ -851,72 +851,72 @@ class _BottomAppBarActionItems extends StatelessWidget {
),
)
: onMailView
? Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: [
IconButton(
key: const ValueKey('star_email_button'),
icon: ImageIcon(
const AssetImage(
'$_iconAssetLocation/twotone_star.png',
package: _assetsPackage,
),
color: starIconColor,
),
onPressed: () {
final currentEmail = model.currentEmail;
if (model.isCurrentEmailStarred) {
model.unstarEmail(currentEmail.id);
} else {
model.starEmail(currentEmail.id);
}
if (model.selectedMailboxPage ==
MailboxPageType.starred) {
mobileMailNavKey.currentState.pop();
model.selectedEmailId = -1;
}
},
color: ReplyColors.white50,
),
IconButton(
icon: const ImageIcon(
AssetImage(
'$_iconAssetLocation/twotone_delete.png',
package: _assetsPackage,
),
),
onPressed: () {
model.deleteEmail(
model.selectedEmailId,
);

mobileMailNavKey.currentState.pop();
model.selectedEmailId = -1;
},
color: ReplyColors.white50,
? Row(
mainAxisSize: MainAxisSize.max,
mainAxisAlignment: MainAxisAlignment.end,
children: [
IconButton(
key: const ValueKey('star_email_button'),
icon: ImageIcon(
const AssetImage(
'$_iconAssetLocation/twotone_star.png',
package: _assetsPackage,
),
IconButton(
icon: const Icon(Icons.more_vert),
onPressed: () {},
color: ReplyColors.white50,
color: starIconColor,
),
onPressed: () {
final currentEmail = model.currentEmail;
if (model.isCurrentEmailStarred) {
model.unstarEmail(currentEmail.id);
} else {
model.starEmail(currentEmail.id);
}
if (model.selectedMailboxPage ==
MailboxPageType.starred) {
mobileMailNavKey.currentState.pop();
model.selectedEmailId = -1;
}
},
color: ReplyColors.white50,
),
IconButton(
icon: const ImageIcon(
AssetImage(
'$_iconAssetLocation/twotone_delete.png',
package: _assetsPackage,
),
],
)
: Align(
alignment: Alignment.centerRight,
child: IconButton(
key: const ValueKey('ReplySearch'),
icon: const Icon(Icons.search),
color: ReplyColors.white50,
onPressed: () {
Provider.of<EmailStore>(
context,
listen: false,
).onSearchPage = true;
},
),
onPressed: () {
model.deleteEmail(
model.selectedEmailId,
);

mobileMailNavKey.currentState.pop();
model.selectedEmailId = -1;
},
color: ReplyColors.white50,
),
IconButton(
icon: const Icon(Icons.more_vert),
onPressed: () {},
color: ReplyColors.white50,
),
],
)
: Align(
alignment: Alignment.centerRight,
child: IconButton(
key: const ValueKey('ReplySearch'),
icon: const Icon(Icons.search),
color: ReplyColors.white50,
onPressed: () {
Provider.of<EmailStore>(
context,
listen: false,
).onSearchPage = true;
},
),
),
);
},
);
Expand Down
8 changes: 4 additions & 4 deletions lib/studies/reply/mailbox_body.dart
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,13 @@ class MailboxBody extends StatelessWidget {
final startPadding = isTablet
? 60.0
: isDesktop
? 120.0
: 4.0;
? 120.0
: 4.0;
final endPadding = isTablet
? 30.0
: isDesktop
? 60.0
: 4.0;
? 60.0
: 4.0;

return Consumer<EmailStore>(
builder: (context, model, child) {
Expand Down
4 changes: 2 additions & 2 deletions lib/studies/shrine/backdrop.dart
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ class _BackdropTitle extends AnimatedWidget {
final menuButtonTooltip = animation.isCompleted
? GalleryLocalizations.of(context).shrineTooltipOpenMenu
: animation.isDismissed
? GalleryLocalizations.of(context).shrineTooltipCloseMenu
: null;
? GalleryLocalizations.of(context).shrineTooltipCloseMenu
: null;

return DefaultTextStyle(
style: Theme.of(context).primaryTextTheme.headline6,
Expand Down
Loading

0 comments on commit 4655d32

Please sign in to comment.