toast.dart 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. //import 'package:oktoast/oktoast.dart';
  2. import 'package:fluttertoast/fluttertoast.dart';
  3. import 'package:flutter/material.dart';
  4. import 'package:liftmanager/utils/loading_dialog.dart';
  5. /// Toast工具类
  6. //class Toast {
  7. // static show(String msg, {duration = 2000}) {
  8. // if (msg == null){
  9. // return;
  10. // }
  11. // showToast(
  12. // msg,
  13. // duration: Duration(milliseconds: duration),
  14. // dismissOtherToast: true
  15. // );
  16. // }
  17. //
  18. // static cancelToast() {
  19. // dismissAllToast();
  20. // }
  21. //}
  22. toasts(String msg,{int timeInSecForIos}) {
  23. Fluttertoast.showToast(
  24. msg: msg,
  25. toastLength: Toast.LENGTH_SHORT,
  26. gravity: ToastGravity.BOTTOM,
  27. timeInSecForIos: timeInSecForIos);
  28. }
  29. showSnackBar(BuildContext context, String msg){
  30. Scaffold.of(context)
  31. .showSnackBar(SnackBar(content: Text('$msg')));
  32. }
  33. showLoading(BuildContext context, [String msg = '加载中...']) {
  34. showDialog<Null>(
  35. context: context, //BuildContext对象
  36. barrierDismissible: false,
  37. builder: (BuildContext context) {
  38. return LoadingDialog(
  39. //调用对话框
  40. text: msg,
  41. );
  42. });
  43. }
  44. showAlert(BuildContext context, String title, String content, String txt1,
  45. Function onPre1,
  46. {String txt2 = "", Function onPre2,String txt3 = "", Function onPre3,}) {
  47. showDialog(
  48. barrierDismissible: false,
  49. context: context,
  50. builder: (context) => new AlertDialog(
  51. title: new Text('${title}'),
  52. content: new Text('${content}'),
  53. actions: <Widget>[
  54. txt3.length > 0
  55. ? new FlatButton(
  56. onPressed: onPre3,
  57. child: new Text("${txt3}"),
  58. )
  59. : Container(),
  60. txt2.length > 0
  61. ? new FlatButton(
  62. onPressed: onPre2,
  63. child: new Text("${txt2}"),
  64. )
  65. : Container(),
  66. new FlatButton(
  67. onPressed: onPre1,
  68. child: new Text('${txt1}'),
  69. ),
  70. ],
  71. ),
  72. );
  73. }
  74. dismissLoading(BuildContext context) {
  75. Navigator.pop(context);
  76. }