2023-10-02 12:44:40 +05:30
|
|
|
import 'package:appflowy/generated/locale_keys.g.dart';
|
2023-02-26 16:27:17 +08:00
|
|
|
import 'package:appflowy/startup/startup.dart';
|
2023-10-02 12:44:40 +05:30
|
|
|
import 'package:easy_localization/easy_localization.dart';
|
2022-11-19 17:53:30 +08:00
|
|
|
import 'package:flowy_infra/size.dart';
|
2022-06-01 15:28:54 +08:00
|
|
|
import 'package:flowy_infra_ui/style_widget/text.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:fluttertoast/fluttertoast.dart';
|
|
|
|
|
|
|
|
class FlowyMessageToast extends StatelessWidget {
|
|
|
|
final String message;
|
2023-12-08 20:01:54 +07:00
|
|
|
const FlowyMessageToast({required this.message, super.key});
|
2022-06-01 15:28:54 +08:00
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
2023-10-02 09:12:24 +02:00
|
|
|
return DecoratedBox(
|
2023-04-10 21:18:36 -05:00
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: const BorderRadius.all(Radius.circular(4)),
|
|
|
|
color: Theme.of(context).colorScheme.surface,
|
2022-06-01 15:28:54 +08:00
|
|
|
),
|
2022-08-31 09:19:31 +08:00
|
|
|
child: Padding(
|
|
|
|
padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
|
2022-11-19 17:53:30 +08:00
|
|
|
child: FlowyText.medium(
|
|
|
|
message,
|
|
|
|
fontSize: FontSizes.s16,
|
2023-11-07 15:24:32 +08:00
|
|
|
maxLines: 3,
|
2022-11-19 17:53:30 +08:00
|
|
|
),
|
2022-08-31 09:19:31 +08:00
|
|
|
),
|
2022-06-01 15:28:54 +08:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
void initToastWithContext(BuildContext context) {
|
|
|
|
getIt<FToast>().init(context);
|
|
|
|
}
|
|
|
|
|
2023-11-07 15:24:32 +08:00
|
|
|
void showMessageToast(
|
|
|
|
String message, {
|
|
|
|
BuildContext? context,
|
|
|
|
ToastGravity gravity = ToastGravity.BOTTOM,
|
|
|
|
}) {
|
2022-06-01 15:28:54 +08:00
|
|
|
final child = FlowyMessageToast(message: message);
|
2023-11-07 15:24:32 +08:00
|
|
|
final toast = context == null ? getIt<FToast>() : FToast()
|
|
|
|
..init(context!);
|
|
|
|
toast.showToast(
|
2022-06-01 15:28:54 +08:00
|
|
|
child: child,
|
2023-11-07 15:24:32 +08:00
|
|
|
gravity: gravity,
|
2022-06-01 15:28:54 +08:00
|
|
|
toastDuration: const Duration(seconds: 3),
|
|
|
|
);
|
|
|
|
}
|
2023-06-10 22:38:25 +08:00
|
|
|
|
2023-10-02 12:44:40 +05:30
|
|
|
void showSnackBarMessage(
|
|
|
|
BuildContext context,
|
|
|
|
String message, {
|
|
|
|
bool showCancel = false,
|
|
|
|
}) {
|
2023-06-10 22:38:25 +08:00
|
|
|
ScaffoldMessenger.of(context).showSnackBar(
|
|
|
|
SnackBar(
|
2023-11-13 12:00:03 +08:00
|
|
|
backgroundColor: Theme.of(context).colorScheme.onSecondary,
|
2023-10-02 12:44:40 +05:30
|
|
|
action: !showCancel
|
|
|
|
? null
|
|
|
|
: SnackBarAction(
|
2023-10-25 06:29:50 -07:00
|
|
|
label: LocaleKeys.button_cancel.tr(),
|
2023-12-05 10:46:17 +08:00
|
|
|
textColor: Colors.white,
|
2023-10-02 12:44:40 +05:30
|
|
|
onPressed: () {
|
|
|
|
ScaffoldMessenger.of(context).hideCurrentSnackBar();
|
|
|
|
},
|
|
|
|
),
|
2023-06-10 22:38:25 +08:00
|
|
|
content: FlowyText(
|
|
|
|
message,
|
2023-12-05 10:46:17 +08:00
|
|
|
color: Colors.white,
|
2023-06-10 22:38:25 +08:00
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|