Skip to content

Commit

Permalink
增加 AppStatusModel 与 net observer 的关联
Browse files Browse the repository at this point in the history
增加 注释说明
  • Loading branch information
bladeofgod committed Aug 28, 2020
1 parent 19287ef commit 3620b27
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 3 deletions.
15 changes: 12 additions & 3 deletions lib/base_framework/utils/isolate/app_private_ioslate.dart
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,14 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter_bedrock/base_framework/config/net/base_http.dart';
import 'package:flutter_bedrock/base_framework/config/net/bedrock_http.dart';
import 'package:flutter_bedrock/base_framework/observe/app_status/app_status_observe.dart';
import 'package:flutter_bedrock/base_framework/view_model/app_model/app_status_model.dart';
import 'package:oktoast/oktoast.dart';

class AppPrivateIsolate{

final AppStatusModel appStatusModel = AppStatusModel();

///
static AppPrivateIsolate _appPrivateIsolate;

factory AppPrivateIsolate()=>getInstance();
Expand Down Expand Up @@ -48,11 +52,14 @@ class AppPrivateIsolate{
///网络是否可用
debugPrint('${message[1]}');
String available = message[1];
///可以根据状态做对应的操作 具体看你的业务需求
if(available == kNetDisable){
showToast('网络不可用');
bedRock.cancelAllRequest();
//bedRock.cancelAllRequest();
appStatusModel.setNetStatus(NetStatus.Disable);
}else if(available == kNetEnable){
debugPrint('网络正常');
appStatusModel.setNetStatus(NetStatus.Enable);
}
}
});
Expand All @@ -62,9 +69,11 @@ class AppPrivateIsolate{
Connectivity().onConnectivityChanged.listen((netType) {
debugPrint('$netType');
if(netType == ConnectivityResult.wifi){

appStatusModel.setNetType(NetType.wifi);
}else if(netType == ConnectivityResult.mobile){

appStatusModel.setNetType(NetType.mobile);
}else if(netType == ConnectivityResult.none){
appStatusModel.setNetType(NetType.none);
}

});
Expand Down
20 changes: 20 additions & 0 deletions lib/base_framework/view_model/app_model/app_status_model.dart
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,19 @@ enum NetStatus{
Enable,Disable
}

enum NetType{
wifi,mobile,none
}

class AppStatusModel extends ChangeNotifier{
static AppStatusModel _singleton;
factory AppStatusModel() => _getInstance();
static AppStatusModel _getInstance(){
if(_singleton == null){
_singleton = AppStatusModel();
}
return _singleton;
}

///网络是否可用
NetStatus netStatus = NetStatus.Enable;
Expand All @@ -18,6 +30,14 @@ class AppStatusModel extends ChangeNotifier{
notifyListeners();
}

///网络连接方式
NetType netType ;
setNetType(NetType type){
netType = type;
notifyListeners();
}


}

Expand Down

0 comments on commit 3620b27

Please sign in to comment.