confirm_dialog.dart 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. import 'package:easy_localization/easy_localization.dart';
  2. import 'package:flutter/material.dart';
  3. import 'package:hooks_riverpod/hooks_riverpod.dart';
  4. class ConfirmDialog extends ConsumerWidget {
  5. final Function onOk;
  6. final String title;
  7. final String content;
  8. final String cancel;
  9. final String ok;
  10. const ConfirmDialog({
  11. Key? key,
  12. required this.onOk,
  13. required this.title,
  14. required this.content,
  15. this.cancel = "delete_dialog_cancel",
  16. this.ok = "backup_controller_page_background_battery_info_ok",
  17. }) : super(key: key);
  18. @override
  19. Widget build(BuildContext context, WidgetRef ref) {
  20. return AlertDialog(
  21. shape: RoundedRectangleBorder(borderRadius: BorderRadius.circular(10)),
  22. title: Text(title).tr(),
  23. content: Text(content).tr(),
  24. actions: [
  25. TextButton(
  26. onPressed: () => Navigator.of(context).pop(),
  27. child: Text(
  28. cancel,
  29. style: TextStyle(
  30. color: Theme.of(context).primaryColor,
  31. fontWeight: FontWeight.bold,
  32. ),
  33. ).tr(),
  34. ),
  35. TextButton(
  36. onPressed: () {
  37. onOk();
  38. Navigator.of(context).pop();
  39. },
  40. child: Text(
  41. ok,
  42. style: TextStyle(
  43. color: Colors.red[400],
  44. fontWeight: FontWeight.bold,
  45. ),
  46. ).tr(),
  47. ),
  48. ],
  49. );
  50. }
  51. }