Hibok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

89 line
2.5 KiB

  1. import 'package:chat/data/constants.dart';
  2. import 'package:chat/generated/i18n.dart';
  3. import 'package:chat/utils/counter_overlay.dart';
  4. import 'package:flutter/material.dart';
  5. class RecordOverlay {
  6. static String msg;
  7. static OverlayEntry entry;
  8. static show(BuildContext context, {String msgs = ''}) {
  9. if (msgs == '') {
  10. msgs = I18n.of(context).up_cancle;
  11. }
  12. msg = msgs;
  13. var overlayState = Overlay.of(context);
  14. OverlayEntry overlayEntry;
  15. overlayEntry = new OverlayEntry(builder: (context) {
  16. return buildToastLayout();
  17. });
  18. overlayState.insert(overlayEntry);
  19. if (entry != null) {
  20. entry.remove();
  21. }
  22. entry = overlayEntry;
  23. return overlayEntry;
  24. }
  25. static updateMsg(String newMsg) {
  26. msg = newMsg;
  27. if (entry != null) {
  28. entry.markNeedsBuild();
  29. }
  30. }
  31. static hide() {
  32. print('删除overlay');
  33. entry?.remove();
  34. entry = null;
  35. }
  36. static LayoutBuilder buildToastLayout() {
  37. return LayoutBuilder(builder: (context, constraints) {
  38. if (msg == null) {
  39. msg = I18n.of(context).up_cancle;
  40. }
  41. return IgnorePointer(
  42. ignoring: true,
  43. child: Container(
  44. child: Material(
  45. color: Colors.white.withOpacity(0),
  46. child: Container(
  47. width: 200,
  48. height: 120,
  49. child: Column(
  50. mainAxisAlignment: MainAxisAlignment.spaceAround,
  51. children: <Widget>[
  52. CounterOverlay(),
  53. Container(
  54. child: Text(
  55. "$msg",
  56. textScaleFactor: 1.0,
  57. style: TextStyle(color: Colors.white, fontSize: 16),
  58. ),
  59. ),
  60. ],
  61. ),
  62. decoration: BoxDecoration(
  63. color: Constants.BlackTextColor.withOpacity(0.8),
  64. borderRadius: BorderRadius.all(
  65. Radius.circular(5),
  66. ),
  67. ),
  68. padding: EdgeInsets.symmetric(vertical: 10, horizontal: 10),
  69. ),
  70. // margin: EdgeInsets.only(
  71. // bottom: constraints.biggest.height * 0.15,
  72. // left: constraints.biggest.width * 0.2,
  73. // right: constraints.biggest.width * 0.2,
  74. // ),
  75. ),
  76. alignment: Alignment.center,
  77. ),
  78. );
  79. });
  80. }
  81. }