Add escape key support to backBtn by default
This commit is contained in:
parent
66840b9300
commit
432becb17a
@ -1,5 +1,6 @@
|
|||||||
import 'package:wonders/common_libs.dart';
|
import 'package:wonders/common_libs.dart';
|
||||||
import 'package:wonders/ui/common/app_icons.dart';
|
import 'package:wonders/ui/common/app_icons.dart';
|
||||||
|
import 'package:wonders/ui/common/fullscreen_keyboard_listener.dart';
|
||||||
|
|
||||||
class CircleBtn extends StatelessWidget {
|
class CircleBtn extends StatelessWidget {
|
||||||
const CircleBtn({
|
const CircleBtn({
|
||||||
@ -109,18 +110,37 @@ class BackBtn extends StatelessWidget {
|
|||||||
bgColor: bgColor,
|
bgColor: bgColor,
|
||||||
iconColor: iconColor);
|
iconColor: iconColor);
|
||||||
|
|
||||||
|
bool _handleKeyDown(BuildContext context, KeyDownEvent event) {
|
||||||
|
if (event.logicalKey == LogicalKeyboardKey.escape) {
|
||||||
|
_handleOnPressed(context);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget build(BuildContext context) {
|
Widget build(BuildContext context) {
|
||||||
return CircleIconBtn(
|
return FullscreenKeyboardListener(
|
||||||
|
onKeyDown: (event) => _handleKeyDown(context, event),
|
||||||
|
child: CircleIconBtn(
|
||||||
icon: icon,
|
icon: icon,
|
||||||
bgColor: bgColor,
|
bgColor: bgColor,
|
||||||
color: iconColor,
|
color: iconColor,
|
||||||
onPressed: onPressed ?? () => Navigator.pop(context),
|
onPressed: () => _handleOnPressed(context),
|
||||||
semanticLabel: semanticLabel ?? $strings.circleButtonsSemanticBack,
|
semanticLabel: semanticLabel ?? $strings.circleButtonsSemanticBack,
|
||||||
|
),
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
Widget safe() => _SafeAreaWithPadding(child: this);
|
Widget safe() => _SafeAreaWithPadding(child: this);
|
||||||
|
|
||||||
|
void _handleOnPressed(BuildContext context) {
|
||||||
|
if (onPressed != null) {
|
||||||
|
onPressed?.call();
|
||||||
|
} else {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
class _SafeAreaWithPadding extends StatelessWidget {
|
class _SafeAreaWithPadding extends StatelessWidget {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user