当前位置:网站首页>Live app source code, jump to links outside the station or jump to pages inside the platform
Live app source code, jump to links outside the station or jump to pages inside the platform
2022-07-03 23:06:00 【Cloudleopard network technology】
live broadcast app Source code , Jump to the relevant code of the implementation of links outside the station or jump pages inside the platform
});
} 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();
}
}
}
/// Initiate network request , Handle exceptions at the same time ,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 = “”; /// Sign in void login() {
if (loginName.isEmpty) {
showToast(“ Login account cannot be empty ”);
} else if (psw.isEmpty) {
showToast(“ The login password cannot be empty ”);
} 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);
}
}
}
That's all live broadcast app Source code , Jump to the relevant code of the implementation of links outside the station or jump pages inside the platform , More content welcome to follow the article
边栏推荐
- Firefox set up proxy server
- Mongoose the table associated with the primary key, and automatically bring out the data of another table
- Go error collection | talk about the difference between the value type and pointer type of the method receiver
- Unsafe and CAS principle
- 2022.02.13
- Creation of the template of the password management software keepassdx
- C3p0 connection MySQL 8.0.11 configuration problem
- Data consistency between redis and database
- Unity shader visualizer shader graph
- Runtime. getRuntime(). totalMemory/maxMemory()
猜你喜欢

webAssembly

Unique in China! Alibaba cloud container service enters the Forrester leader quadrant

Leetcode week 4: maximum sum of arrays (shape pressing DP bit operation)

How can enterprises and developers take advantage of the explosion of cloud native landing?

Summary of basic knowledge of exception handling

This time, thoroughly understand bidirectional data binding 01

Wisdom tooth technology announced that it had completed the round D financing of US $100million and had not obtained a valid patent yet

Meta metauniverse female safety problems occur frequently, how to solve the relevant problems in the metauniverse?

QT creator source code learning note 05, how does the menu bar realize plug-in?

How to switch between dual graphics cards of notebook computer
随机推荐
Firefox set up proxy server
Leetcode: a single element in an ordered array
How can enterprises and developers take advantage of the explosion of cloud native landing?
Programming language (1)
Op amp related - link
How to quickly build high availability of service discovery
How to connect a laptop to a projector
Text replacement demo
Sort merge sort
IO flow review
Summary of basic knowledge of exception handling
Teach you to easily learn the type of data stored in the database (a must see for getting started with the database)
Take you to master the formatter of visual studio code
LeetCode 1647. Minimum deletion times of unique character frequency
ADB command to get XML
C3p0 connection MySQL 8.0.11 configuration problem
Overview of Yunxi database executor
Interesting 10 CMD commands
Yyds dry goods inventory Prometheus alarm Art
Unique in China! Alibaba cloud container service enters the Forrester leader quadrant