Migrate to Dart 3

This commit is contained in:
Ankit Mahato
2023-08-27 20:23:41 +05:30
parent 8bb9cbcc91
commit cdba6476b0
13 changed files with 178 additions and 164 deletions

View File

@ -44,8 +44,8 @@ MediaType? getMediaTypeFromHeaders(Map? headers) {
}
(String?, bool) getUriScheme(Uri uri) {
if(uri.hasScheme){
if(kSupportedUriSchemes.contains(uri.scheme)){
if (uri.hasScheme) {
if (kSupportedUriSchemes.contains(uri.scheme)) {
return (uri.scheme, true);
}
return (uri.scheme, false);
@ -53,38 +53,34 @@ MediaType? getMediaTypeFromHeaders(Map? headers) {
return (null, false);
}
(Uri?, String?) getValidRequestUri(
String? url,
List<KVRow>? requestParams,
{String defaultUriScheme = kDefaultUriScheme}
) {
(Uri?, String?) getValidRequestUri(String? url, List<KVRow>? requestParams,
{String defaultUriScheme = kDefaultUriScheme}) {
url = url?.trim();
if(url == null || url == ""){
if (url == null || url == "") {
return (null, "URL is missing!");
}
Uri? uri = Uri.tryParse(url);
if(uri == null){
Uri? uri = Uri.tryParse(url);
if (uri == null) {
return (null, "Check URL (malformed)");
}
(String?, bool) urlScheme = getUriScheme(uri);
if(urlScheme.$0 != null){
if (!urlScheme.$1){
return (null, "Unsupported URL Scheme (${urlScheme.$0})");
if (urlScheme.$1 != null) {
if (!urlScheme.$2) {
return (null, "Unsupported URL Scheme (${urlScheme.$1})");
}
}
else {
} else {
url = "$defaultUriScheme://$url";
}
uri = Uri.parse(url);
if (uri.hasFragment){
uri = Uri.parse(url);
if (uri.hasFragment) {
uri = uri.removeFragment();
}
Map<String, String>? queryParams = rowsToMap(requestParams);
if(queryParams != null){
if(uri.hasQuery){
if (queryParams != null) {
if (uri.hasQuery) {
Map<String, String> urlQueryParams = uri.queryParameters;
queryParams = mergeMaps(urlQueryParams, queryParams);
}
@ -93,48 +89,58 @@ MediaType? getMediaTypeFromHeaders(Map? headers) {
return (uri, null);
}
(List<ResponseBodyView>, String?) getResponseBodyViewOptions(MediaType? mediaType){
if(mediaType != null){
(List<ResponseBodyView>, String?) getResponseBodyViewOptions(
MediaType? mediaType) {
if (mediaType != null) {
var type = mediaType.type;
var subtype = mediaType.subtype;
if(kResponseBodyViewOptions.containsKey(type)){
if (kResponseBodyViewOptions[type]!.containsKey(subtype)){
return (kResponseBodyViewOptions[type]![subtype]!, kCodeHighlighterMap[subtype] ?? subtype);
if (kResponseBodyViewOptions.containsKey(type)) {
if (kResponseBodyViewOptions[type]!.containsKey(subtype)) {
return (
kResponseBodyViewOptions[type]![subtype]!,
kCodeHighlighterMap[subtype] ?? subtype
);
}
if(subtype.contains(kSubTypeJson)){
if (subtype.contains(kSubTypeJson)) {
subtype = kSubTypeJson;
}
if(subtype.contains(kSubTypeXml)){
if (subtype.contains(kSubTypeXml)) {
subtype = kSubTypeXml;
}
if (kResponseBodyViewOptions[type]!.containsKey(subtype)){
return (kResponseBodyViewOptions[type]![subtype]!, kCodeHighlighterMap[subtype] ?? subtype);
if (kResponseBodyViewOptions[type]!.containsKey(subtype)) {
return (
kResponseBodyViewOptions[type]![subtype]!,
kCodeHighlighterMap[subtype] ?? subtype
);
}
return (kResponseBodyViewOptions[type]![kSubTypeDefaultViewOptions]!, subtype);
return (
kResponseBodyViewOptions[type]![kSubTypeDefaultViewOptions]!,
subtype
);
}
}
return (kNoBodyViewOptions, null);
}
String? formatBody(String? body, MediaType? mediaType){
if(mediaType != null && body != null){
String? formatBody(String? body, MediaType? mediaType) {
if (mediaType != null && body != null) {
var subtype = mediaType.subtype;
try {
if(subtype.contains(kSubTypeJson)){
if (subtype.contains(kSubTypeJson)) {
final tmp = jsonDecode(body);
String result = kEncoder.convert(tmp);
return result;
}
if(subtype.contains(kSubTypeXml)){
if (subtype.contains(kSubTypeXml)) {
final document = XmlDocument.parse(body);
String result = document.toXmlString(pretty: true, indent: ' ');
return result;
}
if(subtype == kSubTypeHtml){
if (subtype == kSubTypeHtml) {
var len = body.length;
var lines = kSplitter.convert(body);
var numOfLines = lines.length;
if(numOfLines !=0 && len/numOfLines <= kCodeCharsPerLineLimit){
if (numOfLines != 0 && len / numOfLines <= kCodeCharsPerLineLimit) {
return body;
}
}
@ -143,4 +149,4 @@ String? formatBody(String? body, MediaType? mediaType){
}
}
return null;
}
}