helper.dart 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849
  1. import 'package:flutter/material.dart';
  2. import 'package:webviewx/webviewx.dart';
  3. /// This dialog will basically show up right on top of the webview.
  4. ///
  5. /// AlertDialog is a widget, so it needs to be wrapped in `WebViewAware`, in order
  6. /// to be able to interact (on web) with it.
  7. ///
  8. /// Read the `Readme.md` for more info.
  9. void showAlertDialog(String content, BuildContext context) {
  10. showDialog(
  11. context: context,
  12. builder: (_) => WebViewAware(
  13. child: AlertDialog(
  14. content: Text(content),
  15. actions: [
  16. TextButton(
  17. onPressed: Navigator.of(context).pop,
  18. child: const Text('Close'),
  19. ),
  20. ],
  21. ),
  22. ),
  23. );
  24. }
  25. void showSnackBar(String content, BuildContext context) {
  26. ScaffoldMessenger.of(context)
  27. ..hideCurrentSnackBar()
  28. ..showSnackBar(
  29. SnackBar(
  30. content: Text(content),
  31. duration: const Duration(seconds: 1),
  32. ),
  33. );
  34. }
  35. Widget createButton({
  36. VoidCallback? onTap,
  37. required String text,
  38. }) {
  39. return ElevatedButton(
  40. onPressed: onTap,
  41. style: ElevatedButton.styleFrom(
  42. padding: const EdgeInsets.symmetric(horizontal: 16.0, vertical: 16.0),
  43. ),
  44. child: Text(text),
  45. );
  46. }