-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmessage_utils.dart
54 lines (49 loc) · 1.57 KB
/
message_utils.dart
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import 'package:flutter/material.dart';
// import 'package:fluttertoast/fluttertoast.dart' as FlToast;
// class MessageUtils {
// static void showToast(String message) {
// if (Platform.isIOS || Platform.isAndroid) {
// FlToast.Fluttertoast.showToast(
// msg: message,
// toastLength: FlToast.Toast.LENGTH_SHORT,
// gravity: FlToast.ToastGravity.CENTER,
// timeInSecForIosWeb: 5,
// backgroundColor: Colors.red,
// textColor: Colors.white,
// fontSize: 16.0);
// return;
// }
//
// return;
// }
// }
class Toast {
static void show(BuildContext context, String message,
{Duration duration = const Duration(seconds: 2)}) {
OverlayEntry overlayEntry = OverlayEntry(
builder: (context) => Positioned(
top: MediaQuery.of(context).size.height * 0.8,
left: MediaQuery.of(context).size.width * 0.1,
width: MediaQuery.of(context).size.width * 0.8,
child: Material(
color: Colors.transparent,
child: Container(
padding: const EdgeInsets.symmetric(horizontal: 24.0, vertical: 12.0),
decoration: BoxDecoration(
color: Colors.black.withOpacity(0.7),
borderRadius: BorderRadius.circular(8.0),
),
child: Text(
message,
style: const TextStyle(color: Colors.white),
),
),
),
),
);
Overlay.of(context).insert(overlayEntry);
Future.delayed(duration, () {
overlayEntry.remove();
});
}
}