76 lines
2.0 KiB
Dart
Raw Normal View History

import 'package:appflowy/generated/locale_keys.g.dart';
import 'package:appflowy/startup/startup.dart';
import 'package:easy_localization/easy_localization.dart';
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 {
const FlowyMessageToast({required this.message, super.key});
2022-06-01 15:28:54 +08:00
final String message;
2022-06-01 15:28:54 +08:00
@override
Widget build(BuildContext context) {
2023-10-02 09:12:24 +02:00
return DecoratedBox(
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),
child: FlowyText.medium(
message,
fontSize: FontSizes.s16,
maxLines: 3,
),
2022-08-31 09:19:31 +08:00
),
2022-06-01 15:28:54 +08:00
);
}
}
void initToastWithContext(BuildContext context) {
getIt<FToast>().init(context);
}
void showMessageToast(
String message, {
BuildContext? context,
ToastGravity gravity = ToastGravity.BOTTOM,
}) {
2022-06-01 15:28:54 +08:00
final child = FlowyMessageToast(message: message);
final toast = context == null ? getIt<FToast>() : FToast()
..init(context!);
toast.showToast(
2022-06-01 15:28:54 +08:00
child: child,
gravity: gravity,
2022-06-01 15:28:54 +08:00
toastDuration: const Duration(seconds: 3),
);
}
void showSnackBarMessage(
BuildContext context,
String message, {
bool showCancel = false,
}) {
ScaffoldMessenger.of(context).showSnackBar(
SnackBar(
backgroundColor: Theme.of(context).colorScheme.onSecondary,
action: !showCancel
? null
: SnackBarAction(
label: LocaleKeys.button_cancel.tr(),
textColor: Colors.white,
onPressed: () {
ScaffoldMessenger.of(context).hideCurrentSnackBar();
},
),
content: FlowyText(
message,
color: Colors.white,
),
),
);
}