mirror of
https://github.com/AppFlowy-IO/AppFlowy.git
synced 2024-08-30 18:12:39 +00:00
Merge pull request #823 from ChiragKr04/feat/close-dialog-on-esc-press
fix: closing rename dialog on escape key press
This commit is contained in:
commit
f913e00856
@ -3,12 +3,26 @@ import 'package:flowy_infra/size.dart';
|
|||||||
import 'package:flowy_infra/theme.dart';
|
import 'package:flowy_infra/theme.dart';
|
||||||
import 'package:flowy_infra_ui/widget/dialog/dialog_size.dart';
|
import 'package:flowy_infra_ui/widget/dialog/dialog_size.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter/services.dart';
|
||||||
import 'package:provider/provider.dart';
|
import 'package:provider/provider.dart';
|
||||||
import 'dart:ui';
|
import 'dart:ui';
|
||||||
|
|
||||||
extension IntoDialog on Widget {
|
extension IntoDialog on Widget {
|
||||||
Future<dynamic> show(BuildContext context) async {
|
Future<dynamic> show(BuildContext context) async {
|
||||||
await Dialogs.show(this, context);
|
FocusNode dialogFocusNode = FocusNode();
|
||||||
|
await Dialogs.show(
|
||||||
|
RawKeyboardListener(
|
||||||
|
focusNode: dialogFocusNode,
|
||||||
|
onKey: (value) {
|
||||||
|
if (value.isKeyPressed(LogicalKeyboardKey.escape)) {
|
||||||
|
Navigator.of(context).pop();
|
||||||
|
}
|
||||||
|
},
|
||||||
|
child: this,
|
||||||
|
),
|
||||||
|
context,
|
||||||
|
);
|
||||||
|
dialogFocusNode.dispose();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -45,7 +59,8 @@ class StyledDialog extends StatelessWidget {
|
|||||||
);
|
);
|
||||||
|
|
||||||
if (shrinkWrap) {
|
if (shrinkWrap) {
|
||||||
innerContent = IntrinsicWidth(child: IntrinsicHeight(child: innerContent));
|
innerContent =
|
||||||
|
IntrinsicWidth(child: IntrinsicHeight(child: innerContent));
|
||||||
}
|
}
|
||||||
|
|
||||||
return FocusTraversalGroup(
|
return FocusTraversalGroup(
|
||||||
@ -80,7 +95,8 @@ class Dialogs {
|
|||||||
return await Navigator.of(context).push(
|
return await Navigator.of(context).push(
|
||||||
StyledDialogRoute(
|
StyledDialogRoute(
|
||||||
barrier: DialogBarrier(color: Colors.black.withOpacity(0.4)),
|
barrier: DialogBarrier(color: Colors.black.withOpacity(0.4)),
|
||||||
pageBuilder: (BuildContext buildContext, Animation<double> animation, Animation<double> secondaryAnimation) {
|
pageBuilder: (BuildContext buildContext, Animation<double> animation,
|
||||||
|
Animation<double> secondaryAnimation) {
|
||||||
return SafeArea(child: child);
|
return SafeArea(child: child);
|
||||||
},
|
},
|
||||||
),
|
),
|
||||||
@ -132,7 +148,8 @@ class StyledDialogRoute<T> extends PopupRoute<T> {
|
|||||||
final RouteTransitionsBuilder? _transitionBuilder;
|
final RouteTransitionsBuilder? _transitionBuilder;
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildPage(BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation) {
|
Widget buildPage(BuildContext context, Animation<double> animation,
|
||||||
|
Animation<double> secondaryAnimation) {
|
||||||
return Semantics(
|
return Semantics(
|
||||||
child: _pageBuilder(context, animation, secondaryAnimation),
|
child: _pageBuilder(context, animation, secondaryAnimation),
|
||||||
scopesRoute: true,
|
scopesRoute: true,
|
||||||
@ -141,10 +158,12 @@ class StyledDialogRoute<T> extends PopupRoute<T> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
Widget buildTransitions(
|
Widget buildTransitions(BuildContext context, Animation<double> animation,
|
||||||
BuildContext context, Animation<double> animation, Animation<double> secondaryAnimation, Widget child) {
|
Animation<double> secondaryAnimation, Widget child) {
|
||||||
if (_transitionBuilder == null) {
|
if (_transitionBuilder == null) {
|
||||||
return FadeTransition(opacity: CurvedAnimation(parent: animation, curve: Curves.easeInOut), child: child);
|
return FadeTransition(
|
||||||
|
opacity: CurvedAnimation(parent: animation, curve: Curves.easeInOut),
|
||||||
|
child: child);
|
||||||
} else {
|
} else {
|
||||||
return _transitionBuilder!(context, animation, secondaryAnimation, child);
|
return _transitionBuilder!(context, animation, secondaryAnimation, child);
|
||||||
} // Some default transition
|
} // Some default transition
|
||||||
|
Loading…
x
Reference in New Issue
Block a user