-
Notifications
You must be signed in to change notification settings - Fork 143
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
网络请求封装不显示toast #191
Comments
给下简化, 能直接运行, 且能复现问题的demo, 给上面的代码没什么意义 |
show() async { |
dependencies:
flutter_smart_dialog: ^4.9.7+6 |
牛,现在能弹出来了,但是有个新问题,原来没这个报错,现在有了,是用在网络请求里的, |
给下复现这个异常的demo |
//b页面 A 页面跳转B页面 |
大佬还在吗 |
工作日没时间, 周末再看 |
我也会出现这个异常 也是网络请求封装弹loading弹窗 在WidgetsBinding.instance.addPostFrameCallback这个回调里面弹窗就正常 |
dependencies:
flutter_smart_dialog: ^4.9.7+7 |
管用 🐮 |
版本信息
描述bug/需求
网络请求封装loading和toast, 频繁出现loading关闭不了,toast显示不出来,如果在关闭loading之前显示toast就能显示出来
问题demo
Future<HttpResponseEntity?> request(
String url, {
String? method,
Map<String, dynamic>? params,
Object? data,
bool showLoading = true,
bool showToast = true,
CancelToken? cancelToken,
}) async {
try {
if (showLoading) YDToast.showLoading();
final response = await _dio.request(
url,
options: Options(method: method ?? 'GET'),
queryParameters: params,
data: data,
cancelToken: cancelToken,
);
if (showLoading) await YDToast.dismissLoading();
import 'package:flutter/material.dart';
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
import 'package:flutter_spinkit/flutter_spinkit.dart';
import 'package:zhaopin/base/base_build_value.dart';
import 'package:zhaopin/base/base_stateless_widget.dart';
class YDToast {
static Future<T?> showLoading() {
return SmartDialog.showLoading(
maskColor: Colors.transparent,
usePenetrate: false,
clickMaskDismiss: false,
animationTime: const Duration(milliseconds: 200),
);
}
static Future dismissLoading() async {
return await SmartDialog.dismiss(status: SmartStatus.loading);
}
static Future showToast(
String msg, {
bool clickMaskDismiss = false,
}) {
return SmartDialog.showToast(
msg,
usePenetrate: false,
maskColor: Colors.transparent,
clickMaskDismiss: clickMaskDismiss,
alignment: Alignment.center,
animationTime: const Duration(milliseconds: 200),
displayTime: msg.length > 10
? const Duration(milliseconds: 2000)
: const Duration(milliseconds: 1000),
);
}
}
class YDLoadingWidget extends BaseStatelessWidget {
const YDLoadingWidget({super.key});
@OverRide
Widget ydBuild(BuildContext context, BaseBuildValue value) {
return SpinKitRing(
color: value.theme.brand_color_6,
size: 40,
lineWidth: 5,
);
}
}
class YDToastWidget extends StatelessWidget {
final String msg;
const YDToastWidget(this.msg, {super.key});
@OverRide
Widget build(BuildContext context) {
return Align(
alignment: Alignment.center,
child: Container(
constraints:
BoxConstraints(maxWidth: MediaQuery.of(context).size.width - 100),
padding: const EdgeInsets.symmetric(horizontal: 15, vertical: 10),
decoration: BoxDecoration(
color: Colors.black87, borderRadius: BorderRadius.circular(5)),
child: Text(
msg,
style: const TextStyle(fontSize: 15, color: Colors.white),
),
),
);
}
}
The text was updated successfully, but these errors were encountered: