Skip to content
This repository was archived by the owner on Dec 11, 2022. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 6 additions & 6 deletions .idea/libraries/Dart_Packages.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

22 changes: 22 additions & 0 deletions lib/network/Github.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import 'dart:convert';
import 'dart:io';

import 'package:LoginUI/ui/AppConstants.dart';
import 'package:LoginUI/utils/SharedPrefs.dart';
import 'package:http/http.dart' as http;
import 'package:url_launcher/url_launcher.dart';

Expand Down Expand Up @@ -173,4 +174,25 @@ class Github {
return http.post(authorizeBasicUrl,
headers: {'Authorization': authrorization}, body: json.encode(map));
}

static void _defaultUnAuthFunc(){}

/**
* this method will check if response is valid or not on basis of Response code.
* Optional param [onUnAuthorize] onUnauthorize will be called when response is unAuthorized.
* returns boolean as final response.
*/
static bool isValidResponse(http.Response response,{Function() onUnAuthorize:_defaultUnAuthFunc,bool clearAccessToken : false} ){
switch(response.statusCode){
case 200 : return true;
case 401 : onUnAuthorize();
if(clearAccessToken)SharedPrefs().saveToken("");
return false;//UnAuthorized
case 404: return false;
}

return true;
}


}