Skip to content

Commit

Permalink
actionable 토스트 구현 (#2730)
Browse files Browse the repository at this point in the history
  • Loading branch information
devunt committed Jul 10, 2024
1 parent 4ef8f0a commit ed78945
Showing 1 changed file with 29 additions and 2 deletions.
31 changes: 29 additions & 2 deletions apps/mobile/lib/context/toast.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'package:flutter/widgets.dart';
import 'package:flutter_riverpod/flutter_riverpod.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:gap/gap.dart';
import 'package:glyph/components/pressable.dart';
import 'package:glyph/icons/tabler.dart';
import 'package:glyph/themes/colors.dart';

Expand All @@ -16,10 +17,14 @@ class _TextToastWidget extends ConsumerWidget {
const _TextToastWidget({
required this.type,
required this.message,
this.actionText,
this.onAction,
});

final ToastType type;
final String message;
final String? actionText;
final Function()? onAction;

@override
Widget build(BuildContext context, WidgetRef ref) {
Expand Down Expand Up @@ -60,6 +65,20 @@ class _TextToastWidget extends ConsumerWidget {
),
),
),
if (actionText != null) ...[
const Gap(16),
Pressable(
onPressed: onAction,
child: Text(
actionText!,
style: const TextStyle(
fontSize: 14,
fontWeight: FontWeight.w700,
color: BrandColors.gray_0,
),
),
),
],
],
),
);
Expand Down Expand Up @@ -101,9 +120,17 @@ class ToastController {
final BuildContext context;
FToast get _ftoast => ToastScope.of(context)!.ftoast;

void show(String message, {ToastType type = ToastType.success}) {
void show(String message, {ToastType type = ToastType.success, String? actionText, Function()? onAction}) {
_ftoast.showToast(
child: _TextToastWidget(type: type, message: message),
child: _TextToastWidget(
type: type,
message: message,
actionText: actionText,
onAction: () {
_ftoast.removeCustomToast();
onAction?.call();
},
),
positionedToastBuilder: (context, child) {
final height = MediaQuery.of(context).padding.bottom;
final inset = MediaQuery.of(context).viewInsets.bottom;
Expand Down

0 comments on commit ed78945

Please sign in to comment.