tips_dialog.dart 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import 'package:flutter/material.dart';
  2. import 'package:fluttertoast/fluttertoast.dart';
  3. class TipsDialog {
  4. static Future<void> show(
  5. BuildContext context,
  6. String title,
  7. String tips,
  8. ) {
  9. return showDialog<void>(
  10. context: context,
  11. barrierDismissible: false,
  12. builder: (context) {
  13. return AlertDialog(
  14. title: Text(title),
  15. content: SingleChildScrollView(
  16. child: ListBody(children: [Text(tips)]),
  17. ),
  18. actions: [
  19. TextButton(
  20. child: const Text('确定'),
  21. onPressed: () => Navigator.of(context).pop(),
  22. ),
  23. ],
  24. );
  25. },
  26. );
  27. }
  28. static Future<bool?> showByChoose(
  29. BuildContext context,
  30. String title,
  31. String tips,
  32. String yes,
  33. String no,
  34. ) {
  35. return showDialog<bool>(
  36. context: context,
  37. barrierDismissible: false,
  38. builder: (context) {
  39. return AlertDialog(
  40. title: Text(title),
  41. content: SingleChildScrollView(
  42. child: ListBody(children: [Text(tips)]),
  43. ),
  44. actions: [
  45. TextButton(
  46. child: Text(no),
  47. onPressed: () => Navigator.of(context).pop(false),
  48. ),
  49. TextButton(
  50. child: Text(yes),
  51. onPressed: () => Navigator.of(context).pop(true),
  52. ),
  53. ],
  54. );
  55. },
  56. );
  57. }
  58. static void toast(String message) {
  59. Fluttertoast.showToast(msg: message, gravity: ToastGravity.CENTER);
  60. }
  61. }