Skip to content

Commit b4a124b

Browse files
committed
Addressed Requested changes: update size units, refactor column definition, simplify code, and revert unnecessary changes
1 parent 6fb03f9 commit b4a124b

3 files changed

Lines changed: 21 additions & 19 deletions

File tree

packages/devtools_app/lib/src/screens/network/network_request_inspector_views.dart

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -680,16 +680,17 @@ class NetworkRequestOverviewView extends StatelessWidget {
680680

681681
// Output Formats:
682682
// - 512 → "512 B"
683-
// - 2048 → "2.0 KB"
684-
// - 1048576 → "1.0 MB"
685-
// Values are rounded to one decimal place for KB and MB.
683+
// - 2000 → "2.0 kB"
684+
// - 1000000 → "1.0 MB"
685+
// Values are rounded to one decimal place for kB and MB.
686+
// Uses decimal (base-10) units to match Chrome DevTools.
686687
String _formatBytes(int? bytes) {
687688
if (bytes == null) return '-';
688-
if (bytes < 1024) return '$bytes B';
689-
if (bytes < 1024 * 1024) {
690-
return '${(bytes / 1024).toStringAsFixed(1)} KB';
689+
if (bytes < 1000) return '$bytes B';
690+
if (bytes < 1000 * 1000) {
691+
return '${(bytes / 1000).toStringAsFixed(1)} kB';
691692
}
692-
return '${(bytes / (1024 * 1024)).toStringAsFixed(1)} MB';
693+
return '${(bytes / (1000 * 1000)).toStringAsFixed(1)} MB';
693694
}
694695

695696
List<Widget> _buildTimingOverview(BuildContext context) {

packages/devtools_app/lib/src/screens/network/network_screen.dart

Lines changed: 12 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -363,6 +363,7 @@ class NetworkRequestsTable extends StatelessWidget {
363363
static const statusColumn = StatusColumn();
364364
static const typeColumn = TypeColumn();
365365
static const durationColumn = DurationColumn();
366+
static const responseSizeColumn = ResponseSizeColumn();
366367
static final timestampColumn = TimestampColumn();
367368
static const actionsColumn = ActionsColumn();
368369
static final columns = <ColumnData<NetworkRequest>>[
@@ -371,7 +372,7 @@ class NetworkRequestsTable extends StatelessWidget {
371372
statusColumn,
372373
typeColumn,
373374
durationColumn,
374-
const ResponseSizeColumn(),
375+
responseSizeColumn,
375376
timestampColumn,
376377
actionsColumn,
377378
];
@@ -408,16 +409,17 @@ class NetworkRequestsTable extends StatelessWidget {
408409

409410
// Output Formats:
410411
// - 512 → "512 B"
411-
// - 2048 → "2.0 KB"
412-
// - 1048576 → "1.0 MB"
413-
// Values are rounded to one decimal place for KB and MB.
412+
// - 2000 → "2.0 kB"
413+
// - 1000000 → "1.0 MB"
414+
// Values are rounded to one decimal place for kB and MB.
415+
// Uses decimal (base-10) units to match Chrome DevTools.
414416
String _formatBytes(int? bytes) {
415417
if (bytes == null) return '-';
416-
if (bytes < 1024) return '$bytes B';
417-
if (bytes < 1024 * 1024) {
418-
return '${(bytes / 1024).toStringAsFixed(1)} KB';
418+
if (bytes < 1000) return '$bytes B';
419+
if (bytes < 1000 * 1000) {
420+
return '${(bytes / 1000).toStringAsFixed(1)} kB';
419421
}
420-
return '${(bytes / (1024 * 1024)).toStringAsFixed(1)} MB';
422+
return '${(bytes / (1000 * 1000)).toStringAsFixed(1)} MB';
421423
}
422424

423425
class ResponseSizeColumn extends ColumnData<NetworkRequest> {
@@ -444,8 +446,8 @@ class AddressColumn extends ColumnData<NetworkRequest>
444446
);
445447

446448
@override
447-
String getValue(NetworkRequest data) {
448-
return data.uri;
449+
String getValue(NetworkRequest dataObject) {
450+
return dataObject.uri;
449451
}
450452

451453
@override

packages/devtools_app/lib/src/shared/http/http_request_data.dart

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -229,8 +229,7 @@ class DartIOHttpRequestData extends NetworkRequest {
229229

230230
@override
231231
int? get responseBytes {
232-
final headers = responseHeaders;
233-
final contentLength = headers?['content-length'];
232+
final contentLength = responseHeaders?['content-length'];
234233

235234
if (contentLength is String) {
236235
return int.tryParse(contentLength);

0 commit comments

Comments
 (0)