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

@ -13,7 +13,7 @@ void main() async {
await setupInitialWindow(); await setupInitialWindow();
} else { } else {
var win = getInitialSize(); var win = getInitialSize();
await setupWindow(sz: win.$0, off: win.$1); await setupWindow(sz: win.$1, off: win.$2);
} }
runApp( runApp(
ProviderScope( ProviderScope(

View File

@ -132,17 +132,17 @@ class CollectionStateNotifier extends StateNotifier<List<RequestModel>?> {
var responseRec = var responseRec =
await request(requestModel, defaultUriScheme: defaultUriScheme); await request(requestModel, defaultUriScheme: defaultUriScheme);
late final RequestModel newRequestModel; late final RequestModel newRequestModel;
if (responseRec.$0 == null) { if (responseRec.$1 == null) {
newRequestModel = requestModel.copyWith( newRequestModel = requestModel.copyWith(
responseStatus: -1, responseStatus: -1,
message: responseRec.$2, message: responseRec.$3,
); );
} else { } else {
final responseModel = baseResponseModel.fromResponse( final responseModel = baseResponseModel.fromResponse(
response: responseRec.$0!, response: responseRec.$1!,
time: responseRec.$1!, time: responseRec.$2!,
); );
int statusCode = responseRec.$0!.statusCode; int statusCode = responseRec.$1!.statusCode;
newRequestModel = requestModel.copyWith( newRequestModel = requestModel.copyWith(
responseStatus: statusCode, responseStatus: statusCode,
message: kResponseCodeReasons[statusCode], message: kResponseCodeReasons[statusCode],

View File

@ -25,11 +25,11 @@ class _EditRequestBodyState extends ConsumerState<EditRequestBody> {
margin: kPt5o10, margin: kPt5o10,
child: Column( child: Column(
children: [ children: [
SizedBox( const SizedBox(
height: kHeaderHeight, height: kHeaderHeight,
child: Row( child: Row(
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
children: const [ children: [
Text( Text(
"Select Content Type:", "Select Content Type:",
), ),

View File

@ -28,8 +28,8 @@ class _RequestEditorPaneState extends ConsumerState<RequestEditorPane> {
} else { } else {
return Padding( return Padding(
padding: kIsMacOS ? kPt24o8 : kP8, padding: kIsMacOS ? kPt24o8 : kP8,
child: Column( child: const Column(
children: const [ children: [
EditorPaneRequestURLCard(), EditorPaneRequestURLCard(),
kVSpacer10, kVSpacer10,
Expanded( Expanded(

View File

@ -28,13 +28,13 @@ class _EditorPaneRequestURLCardState extends State<EditorPaneRequestURLCard> {
), ),
borderRadius: kBorderRadius12, borderRadius: kBorderRadius12,
), ),
child: Padding( child: const Padding(
padding: const EdgeInsets.symmetric( padding: EdgeInsets.symmetric(
vertical: 5, vertical: 5,
horizontal: 20, horizontal: 20,
), ),
child: Row( child: Row(
children: const [ children: [
DropdownButtonHTTPMethod(), DropdownButtonHTTPMethod(),
kHSpacer20, kHSpacer20,
Expanded( Expanded(

View File

@ -13,8 +13,8 @@ class HomePage extends StatefulWidget {
class HomePageState extends State<HomePage> { class HomePageState extends State<HomePage> {
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
return Column( return const Column(
children: const [ children: [
Expanded( Expanded(
child: DashboardSplitView( child: DashboardSplitView(
sidebarWidget: CollectionPane(), sidebarWidget: CollectionPane(),

View File

@ -7,66 +7,59 @@ import 'package:apidash/models/models.dart';
import 'package:apidash/consts.dart'; import 'package:apidash/consts.dart';
Future<(http.Response?, Duration?, String?)> request( Future<(http.Response?, Duration?, String?)> request(
RequestModel requestModel, RequestModel requestModel, {
{String defaultUriScheme = kDefaultUriScheme} String defaultUriScheme = kDefaultUriScheme,
) async { }) async {
(Uri?, String?) uriRec = getValidRequestUri(requestModel.url, (Uri?, String?) uriRec = getValidRequestUri(
requestModel.url,
requestModel.requestParams, requestModel.requestParams,
defaultUriScheme: defaultUriScheme); defaultUriScheme: defaultUriScheme,
if(uriRec.$0 != null){ );
Uri requestUrl = uriRec.$0!; if (uriRec.$1 != null) {
Uri requestUrl = uriRec.$1!;
Map<String, String> headers = rowsToMap(requestModel.requestHeaders) ?? {}; Map<String, String> headers = rowsToMap(requestModel.requestHeaders) ?? {};
http.Response response; http.Response response;
String? body; String? body;
try { try {
var requestBody = requestModel.requestBody; var requestBody = requestModel.requestBody;
if(kMethodsWithBody.contains(requestModel.method) && requestBody != null){ if (kMethodsWithBody.contains(requestModel.method) &&
requestBody != null) {
var contentLength = utf8.encode(requestBody).length; var contentLength = utf8.encode(requestBody).length;
if (contentLength > 0){ if (contentLength > 0) {
body = requestBody; body = requestBody;
headers[HttpHeaders.contentLengthHeader] = contentLength.toString(); headers[HttpHeaders.contentLengthHeader] = contentLength.toString();
headers[HttpHeaders.contentTypeHeader] = kContentTypeMap[requestModel.requestBodyContentType] ?? ""; headers[HttpHeaders.contentTypeHeader] =
kContentTypeMap[requestModel.requestBodyContentType] ?? "";
} }
} }
Stopwatch stopwatch = Stopwatch()..start(); Stopwatch stopwatch = Stopwatch()..start();
switch(requestModel.method){ switch (requestModel.method) {
case HTTPVerb.get: case HTTPVerb.get:
response = await http.get(requestUrl, response = await http.get(requestUrl, headers: headers);
headers: headers);
break; break;
case HTTPVerb.head: case HTTPVerb.head:
response = await http.head(requestUrl, response = await http.head(requestUrl, headers: headers);
headers: headers);
break; break;
case HTTPVerb.post: case HTTPVerb.post:
response = await http.post(requestUrl, response = await http.post(requestUrl, headers: headers, body: body);
headers: headers,
body: body);
break; break;
case HTTPVerb.put: case HTTPVerb.put:
response = await http.put(requestUrl, response = await http.put(requestUrl, headers: headers, body: body);
headers: headers,
body: body);
break; break;
case HTTPVerb.patch: case HTTPVerb.patch:
response = await http.patch(requestUrl, response = await http.patch(requestUrl, headers: headers, body: body);
headers: headers,
body: body);
break; break;
case HTTPVerb.delete: case HTTPVerb.delete:
response = await http.delete(requestUrl, response =
headers: headers, await http.delete(requestUrl, headers: headers, body: body);
body: body);
break; break;
} }
stopwatch.stop(); stopwatch.stop();
return (response, stopwatch.elapsed, null); return (response, stopwatch.elapsed, null);
} } catch (e) {
catch (e) {
return (null, null, e.toString()); return (null, null, e.toString());
} }
} } else {
else { return (null, null, uriRec.$2);
return (null, null, uriRec.$1);
} }
} }

View File

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

View File

@ -67,7 +67,12 @@ class _CodePreviewerState extends State<CodePreviewer> {
textStyle = textStyle.merge(widget.textStyle); textStyle = textStyle.merge(widget.textStyle);
} }
processed = sanitize(widget.code); processed = sanitize(widget.code);
spans = asyncGenerateSpans(processed.$0, widget.language, widget.theme, processed.$1); spans = asyncGenerateSpans(
processed.$1,
widget.language,
widget.theme,
processed.$2,
);
} }
@override @override
@ -131,12 +136,14 @@ class _CodePreviewerState extends State<CodePreviewer> {
} }
} }
Future<List<TextSpan>> asyncGenerateSpans( Future<List<TextSpan>> asyncGenerateSpans(String code, String? language,
String code, String? language, Map<String, TextStyle> theme, bool limitedLines) async { Map<String, TextStyle> theme, bool limitedLines) async {
var parsed = highlight.parse(code, language: language); var parsed = highlight.parse(code, language: language);
var spans = convert(parsed.nodes!, theme); var spans = convert(parsed.nodes!, theme);
if(limitedLines) { if (limitedLines) {
spans.add(const TextSpan(text: "\n... more.\nPreview ends here ($kCodePreviewLinesLimit lines).\nYou can check Raw for full result.")); spans.add(const TextSpan(
text:
"\n... more.\nPreview ends here ($kCodePreviewLinesLimit lines).\nYou can check Raw for full result."));
} }
return spans; return spans;
} }

View File

@ -339,8 +339,8 @@ class _ResponseBodyState extends State<ResponseBody> {
} }
var responseBodyView = getResponseBodyViewOptions(mediaType); var responseBodyView = getResponseBodyViewOptions(mediaType);
var options = responseBodyView.$0; var options = responseBodyView.$1;
var highlightLanguage = responseBodyView.$1; var highlightLanguage = responseBodyView.$2;
if (formattedBody == null) { if (formattedBody == null) {
options = [...options]; options = [...options];

View File

@ -156,22 +156,20 @@ void main() {
path: 'guides/libraries/library-tour', path: 'guides/libraries/library-tour',
fragment: 'numbers'); fragment: 'numbers');
String uriScheme1Expected = 'https'; String uriScheme1Expected = 'https';
expect(getUriScheme(uri1), (uriScheme1Expected,true)); expect(getUriScheme(uri1), (uriScheme1Expected, true));
}); });
test('Testing getUriScheme for mailto scheme value', () { test('Testing getUriScheme for mailto scheme value', () {
Uri uri2 = Uri(scheme: 'mailto'); Uri uri2 = Uri(scheme: 'mailto');
String uriScheme2Expected = 'mailto'; String uriScheme2Expected = 'mailto';
expect(getUriScheme(uri2), (uriScheme2Expected,false)); expect(getUriScheme(uri2), (uriScheme2Expected, false));
}); });
test('Testing getUriScheme for empty scheme value', () { test('Testing getUriScheme for empty scheme value', () {
Uri uri3 = Uri( Uri uri3 = Uri(scheme: '');
scheme: ''); expect(getUriScheme(uri3), (null, false));
expect(getUriScheme(uri3), (null,false));
}); });
test('Testing getUriScheme for null scheme value', () { test('Testing getUriScheme for null scheme value', () {
Uri uri4 = Uri( Uri uri4 = Uri(scheme: null);
scheme: null); expect(getUriScheme(uri4), (null, false));
expect(getUriScheme(uri4), (null,false));
}); });
}); });
@ -183,7 +181,7 @@ void main() {
scheme: 'https', scheme: 'https',
host: 'api.foss42.com', host: 'api.foss42.com',
path: 'country/data', path: 'country/data',
queryParameters: {'code':'US'}); queryParameters: {'code': 'US'});
expect(getValidRequestUri(url1, [kvRow1]), (uri1Expected, null)); expect(getValidRequestUri(url1, [kvRow1]), (uri1Expected, null));
}); });
test('Testing getValidRequestUri for null url value', () { test('Testing getValidRequestUri for null url value', () {
@ -201,7 +199,7 @@ void main() {
scheme: 'https', scheme: 'https',
host: 'api.foss42.com', host: 'api.foss42.com',
path: 'country/data', path: 'country/data',
queryParameters: {'code':'US'}); queryParameters: {'code': 'US'});
expect(getValidRequestUri(url4, [kvRow4]), (uri4Expected, null)); expect(getValidRequestUri(url4, [kvRow4]), (uri4Expected, null));
}); });
test('Testing getValidRequestUri when url has fragment', () { test('Testing getValidRequestUri when url has fragment', () {
@ -214,16 +212,18 @@ void main() {
}); });
test('Testing getValidRequestUri when uri scheme is not supported', () { test('Testing getValidRequestUri when uri scheme is not supported', () {
String url5 = "mailto:someone@example.com"; String url5 = "mailto:someone@example.com";
expect(getValidRequestUri(url5, null), (null, "Unsupported URL Scheme (mailto)")); expect(getValidRequestUri(url5, null),
(null, "Unsupported URL Scheme (mailto)"));
}); });
test('Testing getValidRequestUri when query params in both url and kvrow', () { test('Testing getValidRequestUri when query params in both url and kvrow',
() {
String url6 = "api.foss42.com/country/data?code=IND"; String url6 = "api.foss42.com/country/data?code=IND";
KVRow kvRow6 = const KVRow("code", "US"); KVRow kvRow6 = const KVRow("code", "US");
Uri uri6Expected = Uri( Uri uri6Expected = Uri(
scheme: 'https', scheme: 'https',
host: 'api.foss42.com', host: 'api.foss42.com',
path: 'country/data', path: 'country/data',
queryParameters: {'code':'US'}); queryParameters: {'code': 'US'});
expect(getValidRequestUri(url6, [kvRow6]), (uri6Expected, null)); expect(getValidRequestUri(url6, [kvRow6]), (uri6Expected, null));
}); });
test('Testing getValidRequestUri when kvrow is null', () { test('Testing getValidRequestUri when kvrow is null', () {
@ -232,7 +232,7 @@ void main() {
scheme: 'https', scheme: 'https',
host: 'api.foss42.com', host: 'api.foss42.com',
path: 'country/data', path: 'country/data',
queryParameters: {'code':'US'}); queryParameters: {'code': 'US'});
expect(getValidRequestUri(url7, null), (uri7Expected, null)); expect(getValidRequestUri(url7, null), (uri7Expected, null));
}); });
}); });
@ -241,72 +241,78 @@ void main() {
test('Testing getResponseBodyViewOptions for application/json', () { test('Testing getResponseBodyViewOptions for application/json', () {
MediaType mediaType1 = MediaType("application", "json"); MediaType mediaType1 = MediaType("application", "json");
var result1 = getResponseBodyViewOptions(mediaType1); var result1 = getResponseBodyViewOptions(mediaType1);
expect(result1.$0,kCodeRawBodyViewOptions); expect(result1.$1, kCodeRawBodyViewOptions);
expect(result1.$1, "json"); expect(result1.$2, "json");
}); });
test('Testing getResponseBodyViewOptions for application/xml', () { test('Testing getResponseBodyViewOptions for application/xml', () {
MediaType mediaType2 = MediaType("application", "xml"); MediaType mediaType2 = MediaType("application", "xml");
var result2 = getResponseBodyViewOptions(mediaType2); var result2 = getResponseBodyViewOptions(mediaType2);
expect(result2.$0, kCodeRawBodyViewOptions); expect(result2.$1, kCodeRawBodyViewOptions);
expect(result2.$1,"xml"); expect(result2.$2, "xml");
}); });
test('Testing getResponseBodyViewOptions for message/news a format currently not supported', () { test(
'Testing getResponseBodyViewOptions for message/news a format currently not supported',
() {
MediaType mediaType3 = MediaType("message", "news"); MediaType mediaType3 = MediaType("message", "news");
var result3 = getResponseBodyViewOptions(mediaType3); var result3 = getResponseBodyViewOptions(mediaType3);
expect(result3.$0,kNoBodyViewOptions); expect(result3.$1, kNoBodyViewOptions);
expect(result3.$1,null); expect(result3.$2, null);
}); });
test('Testing getResponseBodyViewOptions for application/calendar+json', () { test('Testing getResponseBodyViewOptions for application/calendar+json',
() {
MediaType mediaType4 = MediaType("application", "calendar+json"); MediaType mediaType4 = MediaType("application", "calendar+json");
var result4 = getResponseBodyViewOptions(mediaType4); var result4 = getResponseBodyViewOptions(mediaType4);
expect(result4.$0,kCodeRawBodyViewOptions); expect(result4.$1, kCodeRawBodyViewOptions);
expect(result4.$1, "json"); expect(result4.$2, "json");
}); });
test('Testing getResponseBodyViewOptions for image/svg+xml', () { test('Testing getResponseBodyViewOptions for image/svg+xml', () {
MediaType mediaType5 = MediaType("image", "svg+xml"); MediaType mediaType5 = MediaType("image", "svg+xml");
var result5 = getResponseBodyViewOptions(mediaType5); var result5 = getResponseBodyViewOptions(mediaType5);
expect(result5.$0,kCodeRawBodyViewOptions); expect(result5.$1, kCodeRawBodyViewOptions);
expect(result5.$1, "xml"); expect(result5.$2, "xml");
}); });
test('Testing getResponseBodyViewOptions for application/xhtml+xml', () { test('Testing getResponseBodyViewOptions for application/xhtml+xml', () {
MediaType mediaType6 = MediaType("application", "xhtml+xml"); MediaType mediaType6 = MediaType("application", "xhtml+xml");
var result6 = getResponseBodyViewOptions(mediaType6); var result6 = getResponseBodyViewOptions(mediaType6);
expect(result6.$0,kCodeRawBodyViewOptions); expect(result6.$1, kCodeRawBodyViewOptions);
expect(result6.$1, "xml"); expect(result6.$2, "xml");
}); });
test('Testing getResponseBodyViewOptions for application/xml-external-parsed-entity', () { test(
MediaType mediaType7 = MediaType("application", "xml-external-parsed-entity"); 'Testing getResponseBodyViewOptions for application/xml-external-parsed-entity',
() {
MediaType mediaType7 =
MediaType("application", "xml-external-parsed-entity");
var result7 = getResponseBodyViewOptions(mediaType7); var result7 = getResponseBodyViewOptions(mediaType7);
expect(result7.$0,kCodeRawBodyViewOptions); expect(result7.$1, kCodeRawBodyViewOptions);
expect(result7.$1, "xml"); expect(result7.$2, "xml");
}); });
test('Testing getResponseBodyViewOptions for text/html', () { test('Testing getResponseBodyViewOptions for text/html', () {
MediaType mediaType8 = MediaType("text", "html"); MediaType mediaType8 = MediaType("text", "html");
var result8 = getResponseBodyViewOptions(mediaType8); var result8 = getResponseBodyViewOptions(mediaType8);
expect(result8.$0,kCodeRawBodyViewOptions); expect(result8.$1, kCodeRawBodyViewOptions);
expect(result8.$1, "xml"); expect(result8.$2, "xml");
}); });
test('Testing getResponseBodyViewOptions for application/pdf', () { test('Testing getResponseBodyViewOptions for application/pdf', () {
MediaType mediaType9 = MediaType("application", "pdf"); MediaType mediaType9 = MediaType("application", "pdf");
var result9 = getResponseBodyViewOptions(mediaType9); var result9 = getResponseBodyViewOptions(mediaType9);
expect(result9.$0,kNoBodyViewOptions); expect(result9.$1, kNoBodyViewOptions);
expect(result9.$1, "pdf"); expect(result9.$2, "pdf");
}); });
test('Testing getResponseBodyViewOptions for text/calendar', () { test('Testing getResponseBodyViewOptions for text/calendar', () {
MediaType mediaType10 = MediaType("text", "calendar"); MediaType mediaType10 = MediaType("text", "calendar");
var result10 = getResponseBodyViewOptions(mediaType10); var result10 = getResponseBodyViewOptions(mediaType10);
expect(result10.$0,kRawBodyViewOptions); expect(result10.$1, kRawBodyViewOptions);
expect(result10.$1, "calendar"); expect(result10.$2, "calendar");
}); });
}); });
group("Testing formatBody", () { group("Testing formatBody", () {
test('Testing formatBody for null values', () { test('Testing formatBody for null values', () {
expect(formatBody(null, null),null); expect(formatBody(null, null), null);
}); });
test('Testing formatBody for null body values', () { test('Testing formatBody for null body values', () {
MediaType mediaType1 = MediaType("application", "xml"); MediaType mediaType1 = MediaType("application", "xml");
expect(formatBody(null, mediaType1),null); expect(formatBody(null, mediaType1), null);
}); });
test('Testing formatBody for null MediaType values', () { test('Testing formatBody for null MediaType values', () {
String body1 = ''' String body1 = '''
@ -314,7 +320,7 @@ void main() {
"text":"The Chosen One"; "text":"The Chosen One";
} }
'''; ''';
expect(formatBody(body1, null),null); expect(formatBody(body1, null), null);
}); });
test('Testing formatBody for json subtype values', () { test('Testing formatBody for json subtype values', () {
String body2 = '''{"data":{"area":9831510.0,"population":331893745}}'''; String body2 = '''{"data":{"area":9831510.0,"population":331893745}}''';
@ -325,7 +331,7 @@ void main() {
"population": 331893745 "population": 331893745
} }
}'''; }''';
expect(formatBody(body2, mediaType2),result2Expected); expect(formatBody(body2, mediaType2), result2Expected);
}); });
test('Testing formatBody for xml subtype values', () { test('Testing formatBody for xml subtype values', () {
String body3 = ''' String body3 = '''
@ -347,7 +353,7 @@ void main() {
<calories>650</calories> <calories>650</calories>
</food> </food>
</breakfast_menu>'''; </breakfast_menu>''';
expect(formatBody(body3, mediaType3),result3Expected); expect(formatBody(body3, mediaType3), result3Expected);
}); });
group("Testing formatBody for html", () { group("Testing formatBody for html", () {
MediaType mediaTypeHtml = MediaType("text", "html"); MediaType mediaTypeHtml = MediaType("text", "html");
@ -358,16 +364,18 @@ void main() {
<p>My first paragraph.</p> <p>My first paragraph.</p>
</body> </body>
</html>'''; </html>''';
expect(formatBody(body4, mediaTypeHtml),body4); expect(formatBody(body4, mediaTypeHtml), body4);
}); });
test('Testing formatBody for html subtype values with random values', () { test('Testing formatBody for html subtype values with random values', () {
String body5 = '''<html>${getRandomStringLines(100, 10000)}</html>'''; String body5 = '''<html>${getRandomStringLines(100, 10000)}</html>''';
expect(formatBody(body5, mediaTypeHtml),null); expect(formatBody(body5, mediaTypeHtml), null);
}); });
test('Testing formatBody for html subtype values with random values within limit', () { test(
'Testing formatBody for html subtype values with random values within limit',
() {
String body6 = '''<html>${getRandomStringLines(100, 190)}</html>'''; String body6 = '''<html>${getRandomStringLines(100, 190)}</html>''';
expect(formatBody(body6, mediaTypeHtml),body6); expect(formatBody(body6, mediaTypeHtml), body6);
}); });
}); });
}); });

View File

@ -6,12 +6,12 @@ import 'package:multi_split_view/multi_split_view.dart';
void main() { void main() {
testWidgets('Testing for Dashboard Splitview', (tester) async { testWidgets('Testing for Dashboard Splitview', (tester) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( const MaterialApp(
title: 'Dashboard Splitview', title: 'Dashboard Splitview',
home: Scaffold( home: Scaffold(
body: DashboardSplitView( body: DashboardSplitView(
sidebarWidget: Column(children: const [Text("Hello")]), sidebarWidget: Column(children: [Text("Hello")]),
mainWidget: Column(children: const [Text("World")]), mainWidget: Column(children: [Text("World")]),
), ),
), ),
), ),
@ -23,12 +23,12 @@ void main() {
}); });
testWidgets('Testing for Equal SplitView', (tester) async { testWidgets('Testing for Equal SplitView', (tester) async {
await tester.pumpWidget( await tester.pumpWidget(
MaterialApp( const MaterialApp(
title: 'Equal SplitView', title: 'Equal SplitView',
home: Scaffold( home: Scaffold(
body: EqualSplitView( body: EqualSplitView(
leftWidget: Column(children: const [Text("Hello equal")]), leftWidget: Column(children: [Text("Hello equal")]),
rightWidget: Column(children: const [Text("World equal")]), rightWidget: Column(children: [Text("World equal")]),
), ),
), ),
), ),

View File

@ -10,8 +10,8 @@ void main() {
MaterialApp( MaterialApp(
title: 'URL Field', title: 'URL Field',
theme: kThemeDataDark, theme: kThemeDataDark,
home: Scaffold( home: const Scaffold(
body: Column(children: const [URLField(activeId: '2')]), body: Column(children: [URLField(activeId: '2')]),
), ),
), ),
); );
@ -30,9 +30,9 @@ void main() {
MaterialApp( MaterialApp(
title: 'CellField', title: 'CellField',
theme: kThemeDataLight, theme: kThemeDataLight,
home: Scaffold( home: const Scaffold(
body: Column( body: Column(
children: const [ children: [
CellField( CellField(
keyId: "4", keyId: "4",
hintText: "Passing some hint text", hintText: "Passing some hint text",