直播app源码,跳转站外链接或平台内部跳转页面
直播app源码,跳转站外链接或平台内部跳转页面实现的相关代码
});
} else {
await Future.delayed(Duration(milliseconds: 10));
showLoading();
}
}
@override
void dispose() {
super.dispose();
setIsDispose(true);
viewModel.showLoadingFun = null;
viewModel.dismissLoadingFun = null;
}
}
abstract class BaseViewModel extends ChangeNotifier
with
BaseViewModelInterface,
NavigatorMixin,
ToastMixin,
SharePreferenceMixin,
EventBusMixin,
DataBaseMixin {
int _loadNum = 0;
int _minLoadNum = 1;
late BuildContext context;
late M model;
bool _isDispose = false;
bool get isDispose => _isDispose;
int needLoadingRequestCount = 0;
bool isLoading = false;
Function()? showLoadingFun;
Function? dismissLoadingFun;
static bool isNeedCatchError = false;
set minLoadNum(int value) {
_minLoadNum = value;
}
set loadNum(int value) {
_loadNum = value;
}
int get loadNum {
return _loadNum;
}
void notifyPage() {
if (!_isDispose) {
loadNum++;
print(">loadNum:$loadNum");
if (_loadNum >= _minLoadNum) {
print(">notifyListeners");
notifyListeners();
}
}
}
@override
void init() {
model = getIt.get();
setContext(context);
setIsDispose(false);
}
void showLoading(bool isNeedLoading) {
if (isNeedLoading) {
needLoadingRequestCount++;
if (!isLoading) {
isLoading = true;
if (showLoadingFun != null) {
showLoadingFun!.call();
}
showLoadingFun?.call();
}
}
}
void dismissLoading(bool isNeedLoading) {
if (isNeedLoading) {
needLoadingRequestCount–;
if (needLoadingRequestCount == 0) {
isLoading = false;
if (dismissLoadingFun != null) {
dismissLoadingFun!.call();
}
dismissLoadingFun?.call();
}
}
}
/// 发起网络请求,同时处理异常,loading
void sendRequest(Future future, FutureOr onValue(T value),
{Function(Exception e)? error, bool isNeedLoading = false}) {
showLoading(isNeedLoading);
future.then((t) {
dismissLoading(isNeedLoading);
onValue(t);
});
if (isNeedCatchError) {
future.catchError((e) {
dismissLoading(isNeedLoading);
print("====>error:$e");
if (error != null) {
error(e);
}
});
}
}
@override
void dispose() {
super.dispose();
_isDispose = true;
setIsDispose(_isDispose);
}
}
@injectable
class LoginViewModel extends BaseViewModel {
@factoryMethod
LoginViewModel();
String loginName = “”;
String psw = “”;
///登录
void login() {
if (loginName.isEmpty) {
showToast(“登录账号不可为空”);
} else if (psw.isEmpty) {
showToast(“登录密码不可为空”);
} else {
sendRequest(model.login(loginName, psw), (value) {
if (value.errorCode == 0) {
value.data?.let((it) {
UserInfoSp.getInstance().uid = it.id ?? 0;
UserInfoSp.getInstance().token = it.token ?? “”;
UserInfoSp.getInstance().userName = it.username ?? “”;
});
pop();
push(MainPage());
} else {
showToast(value.errorMsg!);
}
}, isNeedLoading: true);
}
}
}
以上就是 直播app源码,跳转站外链接或平台内部跳转页面实现的相关代码,更多内容欢迎关注之后的文章