首页 > 应用开发 > Java > app直播源码,收到消息时出现弹窗
app直播源码,收到消息时出现弹窗实现的相关代码
Flutter toast库配置,可参考fluttertoast配置引用
1.在pubspec.yaml中配置fluttertoast库,通过Pub get 获取fluttertoast的版本,通过Pub upgrade更新,eg:
|
1
2
3
4
5 |
# The following adds the Cupertino Icons font to your application.
# Use with the CupertinoIcons
class
for
iOS style icons.
cupertino_icons: ^1.0.2
provider: ^5.0.0
fluttertoast: ^8.0.8 |
2.在需要显示toast的dart文件中,import fluttertoast.dart,eg:
|
1 |
import
'package:fluttertoast/fluttertoast.dart'
; |
3.fluttertoast.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
55
56
57
58
59 |
/// Summons the platform's showToast which will display the message
///
/// Wraps the platform's native Toast for android.
/// Wraps the Plugin
/// Wraps the
///
/// Parameter [msg] is required and all remaining are optional
static
Future<bool?> showToast({
required String msg,
Toast? toastLength,
int timeInSecForIosWeb = 1,
double? fontSize,
ToastGravity? gravity,
Color? backgroundColor,
Color? textColor,
bool webShowClose = false,
webBgColor:
"linear-gradient(to right, #00b09b, #96c93d)"
,
webPosition:
"right"
,
}) async {
String toast =
"short"
;
if
(toastLength == Toast.LENGTH_LONG) {
toast =
"long"
;
}
String gravityToast =
"bottom"
;
if
(gravity == ToastGravity.TOP) {
gravityToast =
"top"
;
}
else
if
(gravity == ToastGravity.CENTER) {
gravityToast =
"center"
;
}
else
{
gravityToast =
"bottom"
;
} //lines from 78 to 97 have been changed in order to solve issue #328
if
(backgroundColor == null) {
backgroundColor = Colors.black;
}
if
(textColor == null) {
textColor = Colors.white;
}
final
Map<String, dynamic> params = <String, dynamic>{
'msg'
: msg,
'length'
: toast,
'time'
: timeInSecForIosWeb,
'gravity'
: gravityToast,
'bgcolor'
: backgroundColor != null ? backgroundColor.value : null,
'iosBgcolor'
: backgroundColor != null ? backgroundColor.value : null,
'textcolor'
: textColor != null ? textColor.value : null,
'iosTextcolor'
: textColor != null ? textColor.value : null,
'fontSize'
: fontSize,
'webShowClose'
: webShowClose,
'webBgColor'
: webBgColor,
'webPosition'
: webPosition
};
bool? res = await _channel.invokeMethod(
'showToast'
, params);
return
res;
}} |
以上就是 app直播源码,收到消息时出现弹窗实现的相关代码,更多内容欢迎关注之后的文章
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/69978258/viewspace-2850304/
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/70012648/viewspace-2851778/ ,如需转载,请注明出处,否则将追究法律责任。