toast.dart 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. import 'package:app_flowy/startup/startup.dart';
  2. import 'package:flowy_infra/size.dart';
  3. import 'package:flowy_infra_ui/style_widget/text.dart';
  4. import 'package:flutter/material.dart';
  5. import 'package:fluttertoast/fluttertoast.dart';
  6. class FlowyMessageToast extends StatelessWidget {
  7. final String message;
  8. const FlowyMessageToast({required this.message, Key? key}) : super(key: key);
  9. @override
  10. Widget build(BuildContext context) {
  11. return Container(
  12. decoration: const BoxDecoration(
  13. borderRadius: BorderRadius.all(Radius.circular(4)),
  14. color: Colors.black,
  15. ),
  16. child: Padding(
  17. padding: const EdgeInsets.symmetric(horizontal: 12, vertical: 6),
  18. child: FlowyText.medium(
  19. message,
  20. color: Colors.white,
  21. fontSize: FontSizes.s16,
  22. ),
  23. ),
  24. );
  25. }
  26. }
  27. void initToastWithContext(BuildContext context) {
  28. getIt<FToast>().init(context);
  29. }
  30. void showMessageToast(String message) {
  31. final child = FlowyMessageToast(message: message);
  32. getIt<FToast>().showToast(
  33. child: child,
  34. gravity: ToastGravity.BOTTOM,
  35. toastDuration: const Duration(seconds: 3),
  36. );
  37. }