net_error_dialog.dart 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116
  1. import 'package:flutter/material.dart';
  2. import 'package:flutter_screenutil/flutter_screenutil.dart';
  3. import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
  4. import 'package:location/helper/internet_connection_helper.dart';
  5. import 'package:location/resource/assets.gen.dart';
  6. import 'package:location/resource/colors.gen.dart';
  7. import 'package:location/resource/string.gen.dart';
  8. import 'package:location/utils/common_expand.dart';
  9. import 'package:location/utils/toast_util.dart';
  10. class NetErrorDialog {
  11. static const String _tag = 'NetErrorDialog';
  12. static void show() {
  13. if (SmartDialog.checkExist(tag: _tag)) {
  14. return;
  15. }
  16. SmartDialog.show(builder: (_) => _NetErrorView(), tag: _tag);
  17. }
  18. static void dismiss() {
  19. SmartDialog.dismiss(tag: _tag);
  20. }
  21. }
  22. class _NetErrorView extends StatelessWidget {
  23. const _NetErrorView();
  24. @override
  25. Widget build(BuildContext context) {
  26. return Container(
  27. width: 274.w,
  28. decoration: BoxDecoration(
  29. borderRadius: BorderRadius.circular(16.r),
  30. border: Border.all(
  31. color: Colors.white,
  32. width: 2.w,
  33. ),
  34. gradient: LinearGradient(
  35. begin: Alignment.topCenter,
  36. end: Alignment.bottomCenter,
  37. colors: [
  38. '#E4E4FF'.color,
  39. '#FFFFFF'.color,
  40. ])),
  41. child: Stack(
  42. alignment: Alignment.center,
  43. children: [
  44. Positioned(
  45. top: 16.w,
  46. right: 16.w,
  47. child: GestureDetector(
  48. onTap: onNetErrorCloseClick,
  49. child: Assets.images.iconDialogClose2
  50. .image(width: 20.w, height: 20.w),
  51. )),
  52. buildNetErrorContent(),
  53. ],
  54. ),
  55. );
  56. }
  57. Widget buildNetErrorContent() {
  58. return IntrinsicHeight(
  59. child: Column(
  60. children: [
  61. SizedBox(height: 30.w),
  62. Assets.images.iconDialogNetError.image(height: 98.w),
  63. SizedBox(height: 10.w),
  64. Text(
  65. StringName.dialogNetErrorTitle,
  66. style: TextStyle(
  67. fontSize: 17.sp,
  68. color: '#333333'.color,
  69. fontWeight: FontWeight.bold),
  70. ),
  71. SizedBox(height: 8.w),
  72. Text(StringName.dialogNetErrorDesc,
  73. style: TextStyle(fontSize: 15.sp, color: '#999999'.color)),
  74. SizedBox(height: 22.w),
  75. GestureDetector(
  76. onTap: onNetErrorAgainClick,
  77. child: Container(
  78. width: 229.w,
  79. height: 43.w,
  80. decoration: BoxDecoration(
  81. color: ColorName.colorPrimary,
  82. borderRadius: BorderRadius.circular(100.r),
  83. ),
  84. child: Center(
  85. child: Text(StringName.dialogNetErrorAgain,
  86. style: TextStyle(
  87. fontSize: 14.sp,
  88. color: Colors.white,
  89. fontWeight: FontWeight.w500)),
  90. ),
  91. ),
  92. ),
  93. SizedBox(height: 20.w),
  94. ],
  95. ),
  96. );
  97. }
  98. void onNetErrorAgainClick() async {
  99. if (await InternetConnectionHelper.getInstance().isConnected()) {
  100. NetErrorDialog.dismiss();
  101. } else {
  102. ToastUtil.show(StringName.networkError);
  103. }
  104. }
  105. void onNetErrorCloseClick() {
  106. NetErrorDialog.dismiss();
  107. }
  108. }