Skip to content

Commit 460fd54

Browse files
authored
chore: adjust toast component (#8060)
* chore: adjust toast component * test: fix tests
1 parent d4f9c71 commit 460fd54

File tree

3 files changed

+49
-29
lines changed

3 files changed

+49
-29
lines changed

frontend/appflowy_flutter/integration_test/shared/expectation.dart

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -98,10 +98,8 @@ extension Expectation on WidgetTester {
9898

9999
/// Expect to the markdown file export success dialog.
100100
void expectToExportSuccess() {
101-
final exportSuccess = find.byWidgetPredicate(
102-
(widget) =>
103-
widget is FlowyText &&
104-
widget.text == LocaleKeys.settings_files_exportFileSuccess.tr(),
101+
final exportSuccess = find.text(
102+
LocaleKeys.settings_files_exportFileSuccess.tr(),
105103
);
106104
expect(exportSuccess, findsOneWidget);
107105
}

frontend/appflowy_flutter/lib/features/share_tab/presentation/widgets/copy_link_widget.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import 'package:appflowy/features/share_tab/logic/share_tab_bloc.dart';
22
import 'package:appflowy/generated/flowy_svgs.g.dart';
33
import 'package:appflowy/generated/locale_keys.g.dart';
4+
import 'package:appflowy/startup/startup.dart';
45
import 'package:appflowy/workspace/presentation/widgets/dialogs.dart';
56
import 'package:appflowy_ui/appflowy_ui.dart';
67
import 'package:easy_localization/easy_localization.dart';
@@ -68,6 +69,10 @@ class CopyLinkWidget extends StatelessWidget {
6869
ShareTabEvent.copyShareLink(link: shareLink),
6970
);
7071

72+
if (FlowyRunner.currentMode.isUnitTest) {
73+
return;
74+
}
75+
7176
showToastNotification(
7277
message: LocaleKeys.shareTab_copiedLinkToClipboard.tr(),
7378
);

frontend/appflowy_flutter/lib/workspace/presentation/widgets/dialogs.dart

Lines changed: 42 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import 'package:appflowy/generated/flowy_svgs.g.dart';
22
import 'package:appflowy/generated/locale_keys.g.dart';
3-
import 'package:appflowy/util/theme_extension.dart';
43
import 'package:appflowy/workspace/presentation/home/menu/sidebar/space/shared_widget.dart';
4+
import 'package:appflowy_ui/appflowy_ui.dart';
55
import 'package:easy_localization/easy_localization.dart';
66
import 'package:flowy_infra/size.dart';
77
import 'package:flowy_infra_ui/style_widget/text.dart';
@@ -260,18 +260,21 @@ class OkCancelButton extends StatelessWidget {
260260
}
261261

262262
ToastificationItem showToastNotification({
263+
BuildContext? context,
263264
String? message,
264265
TextSpan? richMessage,
265266
String? description,
266267
ToastificationType type = ToastificationType.success,
267268
ToastificationCallbacks? callbacks,
269+
bool showCloseButton = false,
268270
double bottomPadding = 100,
269271
}) {
270272
assert(
271273
(message == null) != (richMessage == null),
272274
"Exactly one of message or richMessage must be non-null.",
273275
);
274276
return toastification.showCustom(
277+
context: context,
275278
alignment: Alignment.bottomCenter,
276279
autoCloseDuration: const Duration(milliseconds: 3000),
277280
callbacks: callbacks ?? const ToastificationCallbacks(),
@@ -288,6 +291,7 @@ ToastificationItem showToastNotification({
288291
richMessage: richMessage,
289292
type: type,
290293
onDismiss: () => toastification.dismiss(item),
294+
showCloseButton: showCloseButton,
291295
);
292296
},
293297
);
@@ -390,25 +394,31 @@ class DesktopToast extends StatelessWidget {
390394
this.richMessage,
391395
required this.type,
392396
this.onDismiss,
397+
this.showCloseButton = false,
393398
});
394399

395400
final String? message;
396401
final TextSpan? richMessage;
397402
final ToastificationType type;
398403
final void Function()? onDismiss;
404+
final bool showCloseButton;
399405

400406
@override
401407
Widget build(BuildContext context) {
408+
final theme = AppFlowyTheme.of(context);
409+
402410
return Center(
403411
child: Container(
404412
constraints: const BoxConstraints(maxWidth: 360.0),
405-
padding: const EdgeInsets.symmetric(horizontal: 12.0, vertical: 8.0),
413+
padding: EdgeInsets.symmetric(
414+
horizontal: theme.spacing.xl,
415+
vertical: theme.spacing.l,
416+
),
406417
margin: const EdgeInsets.only(bottom: 32.0),
407418
decoration: BoxDecoration(
408-
color: Theme.of(context).isLightMode
409-
? const Color(0xFF333333)
410-
: const Color(0xFF363D49),
411-
borderRadius: const BorderRadius.all(Radius.circular(8.0)),
419+
color: theme.surfaceColorScheme.inverse,
420+
borderRadius: BorderRadius.circular(theme.borderRadius.l),
421+
boxShadow: theme.shadow.small,
412422
),
413423
child: Row(
414424
mainAxisSize: MainAxisSize.min,
@@ -425,42 +435,49 @@ class DesktopToast extends StatelessWidget {
425435
size: const Size.square(20.0),
426436
blendMode: null,
427437
),
428-
const HSpace(8.0),
438+
HSpace(
439+
theme.spacing.m,
440+
),
429441
// text
430442
Flexible(
431443
child: message != null
432-
? FlowyText(
444+
? Text(
433445
message!,
434446
maxLines: 2,
435-
figmaLineHeight: 20.0,
436447
overflow: TextOverflow.ellipsis,
437-
color: const Color(0xFFFFFFFF),
448+
style: theme.textStyle.body.standard(
449+
color: theme.textColorScheme.onFill,
450+
),
438451
)
439452
: RichText(
440453
text: richMessage!,
441454
maxLines: 2,
442455
overflow: TextOverflow.ellipsis,
443456
),
444457
),
445-
const HSpace(16.0),
446-
// close
447-
MouseRegion(
448-
cursor: SystemMouseCursors.click,
449-
child: GestureDetector(
450-
behavior: HitTestBehavior.opaque,
451-
onTap: onDismiss,
452-
child: const SizedBox.square(
453-
dimension: 24.0,
454-
child: Center(
455-
child: FlowySvg(
456-
FlowySvgs.toast_close_s,
457-
size: Size.square(16.0),
458-
color: Color(0xFFBDBDBD),
458+
if (showCloseButton) ...[
459+
HSpace(
460+
theme.spacing.xl,
461+
),
462+
// close
463+
MouseRegion(
464+
cursor: SystemMouseCursors.click,
465+
child: GestureDetector(
466+
behavior: HitTestBehavior.opaque,
467+
onTap: onDismiss,
468+
child: const SizedBox.square(
469+
dimension: 24.0,
470+
child: Center(
471+
child: FlowySvg(
472+
FlowySvgs.toast_close_s,
473+
size: Size.square(20.0),
474+
color: Color(0xFFBDBDBD),
475+
),
459476
),
460477
),
461478
),
462479
),
463-
),
480+
],
464481
],
465482
),
466483
),

0 commit comments

Comments
 (0)