Skip to content

Commit ba33b1d

Browse files
committed
Debug Log Pretty Print Creation
*Pretty print a visual of segments for debugging.
1 parent 713cc5a commit ba33b1d

File tree

2 files changed

+40
-6
lines changed

2 files changed

+40
-6
lines changed

lib/responsive_wrapper.dart

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ class _ResponsiveWrapperState extends State<ResponsiveWrapper>
310310

311311
// Log breakpoints to console.
312312
if (widget.debugLog)
313-
ResponsiveUtils.debugLogBreakpoints(breakpointSegments);
313+
ResponsiveUtils.debugLogBreakpointSegments(breakpointSegments);
314314

315315
WidgetsBinding.instance.addObserver(this);
316316
WidgetsBinding.instance.addPostFrameCallback((_) {

lib/utils/responsive_utils.dart

Lines changed: 39 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
import 'package:flutter/foundation.dart';
2+
13
import '../responsive_wrapper.dart';
24

35
/// Util functions for the Responsive Framework.
@@ -38,11 +40,43 @@ class ResponsiveUtils {
3840

3941
/// Print a visual view of [breakpointSegments]
4042
/// for debugging purposes.
41-
static String debugLogBreakpoints(
43+
static String debugLogBreakpointSegments(
4244
List<ResponsiveBreakpointSegment> responsiveBreakpointSegments) {
43-
responsiveBreakpointSegments.forEach((element) {
44-
print(element);
45-
});
46-
return responsiveBreakpointSegments.toString();
45+
var stringBuffer = new StringBuffer();
46+
stringBuffer.write('|');
47+
for (int i = 0; i < responsiveBreakpointSegments.length; i++) {
48+
// Convenience variable.
49+
ResponsiveBreakpointSegment segment = responsiveBreakpointSegments[i];
50+
print(segment);
51+
stringBuffer.write(segment.breakpoint.round());
52+
List<dynamic> attributes = [];
53+
String name = segment.responsiveBreakpoint.name;
54+
if (name != null) attributes.add(name);
55+
double scaleFactor = segment.responsiveBreakpoint.scaleFactor;
56+
if (scaleFactor != 1) attributes.add(scaleFactor);
57+
if (attributes.isNotEmpty) {
58+
stringBuffer.write('(');
59+
for (int i = 0; i < attributes.length; i++) {
60+
stringBuffer.write(attributes[i]);
61+
if (i != attributes.length - 1) stringBuffer.write('|');
62+
}
63+
stringBuffer.write(')');
64+
}
65+
stringBuffer.write(' ----- ');
66+
if (segment.segmentType == ResponsiveBreakpointBehavior.AUTOSCALEDOWN &&
67+
segment.breakpoint < segment.responsiveBreakpoint.breakpoint) {
68+
stringBuffer.write(describeEnum(segment.segmentType) +
69+
' from ' +
70+
segment.responsiveBreakpoint.breakpoint.round().toString());
71+
} else {
72+
stringBuffer
73+
.write('${describeEnum(segment.responsiveBreakpoint.behavior)}');
74+
}
75+
if (i != responsiveBreakpointSegments.length - 1)
76+
stringBuffer.write(' ----- ');
77+
}
78+
stringBuffer.write(' ----- ∞ |');
79+
print(stringBuffer.toString());
80+
return stringBuffer.toString();
4781
}
4882
}

0 commit comments

Comments
 (0)