build method
Build a widget.
Implementation
@override
Widget build(final BuildContext context) {
final page = widget.tabs[_pageIndex];
final numbers = <GameShortcutsShortcut>[
GameShortcutsShortcut.digit1,
GameShortcutsShortcut.digit2,
GameShortcutsShortcut.digit3,
GameShortcutsShortcut.digit4,
GameShortcutsShortcut.digit5,
GameShortcutsShortcut.digit6,
GameShortcutsShortcut.digit7,
GameShortcutsShortcut.digit8,
GameShortcutsShortcut.digit9,
GameShortcutsShortcut.digit0,
];
final shortcuts = <GameShortcut>[
GameShortcut(
title: 'Switch to the next page',
shortcut: GameShortcutsShortcut.tab,
controlKey: useControlKey,
metaKey: useMetaKey,
onStart: (final innerContext) => switchPages(1),
),
GameShortcut(
title: 'Switch to the previous page',
shortcut: GameShortcutsShortcut.tab,
controlKey: useControlKey,
metaKey: useMetaKey,
shiftKey: true,
onStart: (final innerContext) => switchPages(-1),
),
for (var i = 0; i < min(widget.tabs.length, numbers.length); i++)
GameShortcut(
title: 'Switch to page ${i + 1}',
shortcut: numbers[i],
controlKey: useControlKey,
metaKey: useMetaKey,
onStart: (final innerContext) {
widget.onPageChange?.call(i);
setState(() => _pageIndex = i);
},
),
];
shortcuts.add(
GameShortcut(
title: 'Show help',
shortcut: GameShortcutsShortcut.slash,
shiftKey: true,
onStart: (final innerContext) => innerContext.pushWidgetBuilder(
(final _) => GameShortcutsHelpScreen(shortcuts: shortcuts),
),
),
);
return GameShortcuts(
shortcuts: shortcuts,
autofocus: false,
canRequestFocus: false,
child: SimpleScaffold(
title: page.title,
leading: page.leading,
actions: page.actions ?? [],
body: page.child,
floatingActionButton: page.floatingActionButton,
bottomNavigationBar: NavigationBar(
destinations: widget.tabs
.map(
(final e) => NavigationDestination(
icon: e.icon,
label: e.title,
tooltip: e.tooltip,
enabled: e.enabled,
),
)
.toList(),
onDestinationSelected: (final value) {
widget.onPageChange?.call(value);
setState(() => _pageIndex = value);
},
selectedIndex: _pageIndex,
),
),
);
}