tips_dialog.dart 1.4 KB

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