Skip to content

Commit becb63b

Browse files
author
ZhuGuojun
committed
splash 的网络禁止的处理
1 parent d0ef4aa commit becb63b

File tree

2 files changed

+23
-5
lines changed

2 files changed

+23
-5
lines changed

lib/tools/net_config.dart

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -139,7 +139,13 @@ class NetConfig{
139139
}
140140
} on TimeoutException{
141141
print('TimeoutException');
142-
return 504;
142+
return 408;
143+
} on Exception {
144+
Tools.showToast('check your network');
145+
if(errorCallback!=null){
146+
errorCallback();
147+
}
148+
return 600;
143149
}
144150

145151
// Fluttertoast.cancel();

lib/view/main_view/splash.dart

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -99,9 +99,10 @@ class _SplashState extends State<Splash> {
9999
_checkVersion() async {
100100

101101
// Invoke api.
102-
var data = await NetConfig.get(context,NetConfig.getNewestVersion,timeOut: 5);
102+
var data = await NetConfig.get(context,NetConfig.getNewestVersion,timeOut: 5,);
103103

104-
if(data!=null&&data==504){
104+
print(data);
105+
if(data!=null&&(data==408||data==600)){
105106
refreshOpacity = 1;
106107
setState(() {});
107108
return;
@@ -238,8 +239,19 @@ class _SplashState extends State<Splash> {
238239

239240
//
240241
void _getUserInfo(SharedPreferences share) {
241-
242-
Future data = NetConfig.get(context,NetConfig.getUserInfo);
242+
Future data = NetConfig.get(
243+
context, NetConfig.getUserInfo,
244+
errorCallback: () {
245+
share.clear();
246+
GlobalInfo.clear();
247+
print('==> user is not exist');
248+
// show welcome page
249+
Navigator.of(context).pushAndRemoveUntil(
250+
MaterialPageRoute(builder: (context) => WelcomePageOne()),
251+
(route) => route == null,
252+
);
253+
}
254+
);
243255
// Tools.loadingAnimation(context);
244256
data.then((data) {
245257
if (data != null) {

0 commit comments

Comments
 (0)