Bring projects, wikis, and teams together with AI. AppFlowy is the AI collaborative workspace where you achieve more without losing control of your data. The leading open source Notion alternative.
Dart blogconfluence-alternativecontent-managementcontent-servicesdocumentationflutternote-takingnotion-alternativeproject-managementtask-managementteam-collaborationwiki
feat(flutter_desktop): press enter to confirm a dialog (#6675)
Richard Shiue8bb8131dd436
diff --git a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/shared_widget.dart b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/shared_widget.dartindex a81f8c3e0d..11b9f1f18a 100644--- a/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/shared_widget.dart+++ b/frontend/appflowy_flutter/lib/workspace/presentation/home/menu/sidebar/space/shared_widget.dart@@ -320,6 +320,12 @@ class _ConfirmPopupState extends State<ConfirmPopup> {if (event is KeyDownEvent &&event.logicalKey == LogicalKeyboardKey.escape) {Navigator.of(context).pop();+ } else if (event is KeyUpEvent &&+ event.logicalKey == LogicalKeyboardKey.enter) {+ widget.onConfirm();+ if (widget.closeOnAction) {+ Navigator.of(context).pop();+ }}},child: Container(diff --git a/frontend/appflowy_flutter/test/widget_test/confirm_dialog_test.dart b/frontend/appflowy_flutter/test/widget_test/confirm_dialog_test.dartnew file mode 100644index 0000000000..4458d588cc--- /dev/null+++ b/frontend/appflowy_flutter/test/widget_test/confirm_dialog_test.dart@@ -0,0 +1,91 @@+import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/shared_widget.dart';+import 'package:easy_localization/easy_localization.dart';+import 'package:flutter/material.dart';+import 'package:flutter/services.dart';+import 'package:flutter_test/flutter_test.dart';+import 'package:mocktail/mocktail.dart';+import 'package:shared_preferences/shared_preferences.dart';++import '../../integration_test/shared/util.dart';+import 'test_material_app.dart';++class _ConfirmPopupMock extends Mock {+ void confirm();+}++void main() {+ setUpAll(() async {+ SharedPreferences.setMockInitialValues({});+ EasyLocalization.logger.enableLevels = [];+ await EasyLocalization.ensureInitialized();+ });++ Widget buildDialog(VoidCallback onConfirm) {+ return Builder(+ builder: (context) {+ return TextButton(+ child: const Text(""),+ onPressed: () {+ showDialog(+ context: context,+ builder: (_) {+ return Dialog(+ shape: RoundedRectangleBorder(+ borderRadius: BorderRadius.circular(12.0),+ ),+ child: ConfirmPopup(+ description: "desc",+ title: "title",+ onConfirm: onConfirm,+ ),+ );+ },+ );+ },+ );+ },+ );+ }++ testWidgets('confirm dialog shortcut events', (tester) async {+ final callback = _ConfirmPopupMock();++ // escape+ await tester.pumpWidget(+ WidgetTestApp(+ child: buildDialog(callback.confirm),+ ),+ );+ await tester.pumpAndSettle();++ await tester.tap(find.byType(TextButton));+ await tester.pumpAndSettle();++ expect(find.byType(ConfirmPopup), findsOneWidget);++ await tester.simulateKeyEvent(LogicalKeyboardKey.escape);+ verifyNever(() => callback.confirm());++ verifyNever(() => callback.confirm());+ expect(find.byType(ConfirmPopup), findsNothing);++ // enter+ await tester.pumpWidget(+ WidgetTestApp(+ child: buildDialog(callback.confirm),+ ),+ );+ await tester.pumpAndSettle();++ await tester.tap(find.byType(TextButton));+ await tester.pumpAndSettle();++ expect(find.byType(ConfirmPopup), findsOneWidget);++ await tester.simulateKeyEvent(LogicalKeyboardKey.enter);+ verify(() => callback.confirm()).called(1);++ verifyNever(() => callback.confirm());+ expect(find.byType(ConfirmPopup), findsNothing);+ });+}diff --git a/frontend/appflowy_flutter/test/widget_test/date_picker_test.dart b/frontend/appflowy_flutter/test/widget_test/date_picker_test.dartindex c834b3595f..3257cfefc1 100644--- a/frontend/appflowy_flutter/test/widget_test/date_picker_test.dart+++ b/frontend/appflowy_flutter/test/widget_test/date_picker_test.dart@@ -8,7 +8,6 @@ import 'package:appflowy/workspace/presentation/widgets/date_picker/widgets/end_import 'package:appflowy/workspace/presentation/widgets/toggle/toggle.dart';import 'package:appflowy_backend/protobuf/flowy-database2/protobuf.dart';import 'package:easy_localization/easy_localization.dart';-import 'package:flowy_infra/theme_extension.dart';import 'package:flutter/material.dart';import 'package:flutter_test/flutter_test.dart';import 'package:shared_preferences/shared_preferences.dart';@@ -16,7 +15,7 @@ import 'package:table_calendar/table_calendar.dart';import 'package:time/time.dart';import '../../integration_test/shared/util.dart';-import 'test_asset_bundle.dart';+import 'test_material_app.dart';const _mockDatePickerDelay = Duration(milliseconds: 200);@@ -737,72 +736,3 @@ void main() {});});}--class WidgetTestApp extends StatelessWidget {- const WidgetTestApp({- super.key,- required this.child,- });-- final Widget child;-- @override- Widget build(BuildContext context) {- return EasyLocalization(- supportedLocales: const [Locale('en')],- path: 'assets/translations',- fallbackLocale: const Locale('en'),- useFallbackTranslations: true,- saveLocale: false,- assetLoader: const TestBundleAssetLoader(),- child: Builder(- builder: (context) => MaterialApp(- supportedLocales: const [Locale('en')],- locale: const Locale('en'),- localizationsDelegates: context.localizationDelegates,- theme: ThemeData.light().copyWith(- extensions: const [- AFThemeExtension(- warning: Colors.transparent,- success: Colors.transparent,- tint1: Colors.transparent,- tint2: Colors.transparent,- tint3: Colors.transparent,- tint4: Colors.transparent,- tint5: Colors.transparent,- tint6: Colors.transparent,- tint7: Colors.transparent,- tint8: Colors.transparent,- tint9: Colors.transparent,- textColor: Colors.transparent,- secondaryTextColor: Colors.transparent,- strongText: Colors.transparent,- greyHover: Colors.transparent,- greySelect: Colors.transparent,- lightGreyHover: Colors.transparent,- toggleOffFill: Colors.transparent,- progressBarBGColor: Colors.transparent,- toggleButtonBGColor: Colors.transparent,- calendarWeekendBGColor: Colors.transparent,- gridRowCountColor: Colors.transparent,- code: TextStyle(),- callout: TextStyle(),- calloutBGColor: Colors.transparent,- tableCellBGColor: Colors.transparent,- caption: TextStyle(),- onBackground: Colors.transparent,- background: Colors.transparent,- borderColor: Colors.transparent,- scrollbarColor: Colors.transparent,- scrollbarHoverColor: Colors.transparent,- ),- ],- ),- home: Scaffold(- body: child,- ),- ),- ),- );- }-}diff --git a/frontend/appflowy_flutter/test/widget_test/test_material_app.dart b/frontend/appflowy_flutter/test/widget_test/test_material_app.dartnew file mode 100644index 0000000000..be7b2001f0--- /dev/null+++ b/frontend/appflowy_flutter/test/widget_test/test_material_app.dart@@ -0,0 +1,74 @@+import 'package:easy_localization/easy_localization.dart';+import 'package:flowy_infra/theme_extension.dart';+import 'package:flutter/material.dart';++import 'test_asset_bundle.dart';++class WidgetTestApp extends StatelessWidget {+ const WidgetTestApp({+ super.key,+ required this.child,+ });++ final Widget child;++ @override+ Widget build(BuildContext context) {+ return EasyLocalization(+ supportedLocales: const [Locale('en')],+ path: 'assets/translations',+ fallbackLocale: const Locale('en'),+ useFallbackTranslations: true,+ saveLocale: false,+ assetLoader: const TestBundleAssetLoader(),+ child: Builder(+ builder: (context) => MaterialApp(+ supportedLocales: const [Locale('en')],+ locale: const Locale('en'),+ localizationsDelegates: context.localizationDelegates,+ theme: ThemeData.light().copyWith(+ extensions: const [+ AFThemeExtension(+ warning: Colors.transparent,+ success: Colors.transparent,+ tint1: Colors.transparent,+ tint2: Colors.transparent,+ tint3: Colors.transparent,+ tint4: Colors.transparent,+ tint5: Colors.transparent,+ tint6: Colors.transparent,+ tint7: Colors.transparent,+ tint8: Colors.transparent,+ tint9: Colors.transparent,+ textColor: Colors.transparent,+ secondaryTextColor: Colors.transparent,+ strongText: Colors.transparent,+ greyHover: Colors.transparent,+ greySelect: Colors.transparent,+ lightGreyHover: Colors.transparent,+ toggleOffFill: Colors.transparent,+ progressBarBGColor: Colors.transparent,+ toggleButtonBGColor: Colors.transparent,+ calendarWeekendBGColor: Colors.transparent,+ gridRowCountColor: Colors.transparent,+ code: TextStyle(),+ callout: TextStyle(),+ calloutBGColor: Colors.transparent,+ tableCellBGColor: Colors.transparent,+ caption: TextStyle(),+ onBackground: Colors.transparent,+ background: Colors.transparent,+ borderColor: Colors.transparent,+ scrollbarColor: Colors.transparent,+ scrollbarHoverColor: Colors.transparent,+ ),+ ],+ ),+ home: Scaffold(+ body: child,+ ),+ ),+ ),+ );+ }+}