Skip to content

Commit 5389286

Browse files
committed
Add Documentation
1 parent 541bfb4 commit 5389286

File tree

3 files changed

+84
-11
lines changed

3 files changed

+84
-11
lines changed

lib/responsive_row_column.dart

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,22 @@
11
import 'package:flutter/cupertino.dart';
22
import 'package:flutter/widgets.dart';
33

4+
/// A convenience wrapper for responsive [Row] and
5+
/// [Column] switching with padding and spacing.
6+
///
7+
/// ResponsiveRowColumn combines responsiveness
8+
/// behaviors for managing rows and columns into one
9+
/// convenience widget. This widget requires all [children]
10+
/// to be [ResponsiveRowColumnItem] widgets.
11+
/// Row vs column layout is controlled by [rowColumn].
12+
/// RowColumn is Row layout when true and Column
13+
/// layout when false.
14+
/// Add spacing between widgets with [rowSpacing] and
15+
/// [columnSpacing]. Add padding around widgets with
16+
/// [rowPadding] and [columnPadding].
17+
///
18+
/// See [ResponsiveRowColumnItem] for [Flex] and
19+
/// [FlexFit] options.
420
class ResponsiveRowColumn extends StatelessWidget {
521
final List<ResponsiveRowColumnItem> children;
622
final bool rowColumn;
@@ -20,7 +36,6 @@ class ResponsiveRowColumn extends StatelessWidget {
2036
final double columnSpacing;
2137
final EdgeInsets rowPadding;
2238
final EdgeInsets columnPadding;
23-
final bool fillRow;
2439
get isRow => rowColumn;
2540
get isColumn => !rowColumn;
2641

@@ -42,7 +57,6 @@ class ResponsiveRowColumn extends StatelessWidget {
4257
this.columnTextBaseline,
4358
this.rowSpacing,
4459
this.columnSpacing,
45-
this.fillRow = false,
4660
this.rowPadding = EdgeInsets.zero,
4761
this.columnPadding = EdgeInsets.zero})
4862
: super(key: key);
@@ -80,6 +94,7 @@ class ResponsiveRowColumn extends StatelessWidget {
8094
);
8195
}
8296

97+
/// Logic to construct widget [children].
8398
List<Widget> buildChildren(
8499
List<ResponsiveRowColumnItem> children, bool rowColumn, double spacing) {
85100
// Sort ResponsiveRowColumnItems by their order.
@@ -91,7 +106,7 @@ class ResponsiveRowColumn extends StatelessWidget {
91106
return a.columnOrder.compareTo(b.columnOrder);
92107
}
93108
});
94-
// Add padding between items.
109+
// Add padding between widgets..
95110
List<Widget> widgetList = [];
96111
for (int i = 0; i < childrenHolder.length; i++) {
97112
widgetList.add(childrenHolder[i].copyWith(rowColumn: rowColumn));
@@ -105,6 +120,16 @@ class ResponsiveRowColumn extends StatelessWidget {
105120
}
106121
}
107122

123+
/// A wrapper for [ResponsiveRowColumn] children with
124+
/// responsiveness.
125+
///
126+
/// Control the order of widgets within [ResponsiveRowColumn]
127+
/// by assigning a [rowOrder] or [columnOrder] value.
128+
/// Widgets without an order value are ranked behind
129+
/// those with order values.
130+
/// Set a widget's [Flex] value through [rowFlex] and
131+
/// [columnFlex]. Set a widget's [FlexFit] through
132+
/// [rowFit] and [columnFit].
108133
class ResponsiveRowColumnItem extends StatelessWidget {
109134
final Widget child;
110135
final int rowOrder;
@@ -129,9 +154,9 @@ class ResponsiveRowColumnItem extends StatelessWidget {
129154

130155
@override
131156
Widget build(BuildContext context) {
132-
if (rowColumn && rowFlex != null) {
157+
if (rowColumn && (rowFlex != null || rowFit != null)) {
133158
return Flexible(flex: rowFlex, fit: rowFit, child: child);
134-
} else if (!rowColumn && columnFlex != null) {
159+
} else if (!rowColumn && (columnFlex != null || columnFit != null)) {
135160
return Flexible(flex: columnFlex, fit: columnFit, child: child);
136161
}
137162

lib/responsive_value.dart

Lines changed: 21 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,16 @@ import 'package:flutter/widgets.dart';
22

33
import 'responsive_framework.dart';
44

5-
typedef T Value<T>();
6-
typedef StartListening<T> = VoidCallback Function(Value<T> element, T value);
7-
5+
/// Conditional values based on the active breakpoint.
6+
///
7+
/// Get a [value] that corresponds to active breakpoint
8+
/// determined by [Condition]s set in [valueWhen].
9+
/// Set a [defaultValue] for when no condition is
10+
/// active. Requires a parent [context] that contains
11+
/// a [ResponsiveWrapper].
12+
///
13+
/// No validation is performed on [Condition]s so
14+
/// valid conditions must be passed.
815
class ResponsiveValue<T> {
916
T value;
1017
final T defaultValue;
@@ -119,12 +126,18 @@ class ResponsiveValue<T> {
119126
}
120127
}
121128

129+
/// Internal equality comparators.
122130
enum Conditional {
123131
LARGER_THAN,
124132
EQUALS,
125133
SMALLER_THAN,
126134
}
127135

136+
/// A conditional value provider.
137+
///
138+
/// Provides the [value] when the [condition] is active.
139+
/// Compare conditions by setting either [breakpoint] or
140+
/// [name] values.
128141
class Condition<T> {
129142
final int breakpoint;
130143
final String name;
@@ -186,6 +199,11 @@ class Condition<T> {
186199
}
187200
}
188201

202+
/// A convenience wrapper for responsive [Visibility].
203+
///
204+
/// ResponsiveVisibility accepts [Condition]s in
205+
/// [visibleWhen] and [hiddenWhen] convenience
206+
/// fields. The [child] widget is [visible] by default.
189207
class ResponsiveVisibility extends StatelessWidget {
190208
final Widget child;
191209
final bool visible;

lib/responsive_wrapper.dart

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -398,6 +398,8 @@ class _ResponsiveWrapperState extends State<ResponsiveWrapper>
398398
devicePixelRatio: devicePixelRatio * activeScaleFactor);
399399
}
400400

401+
/// Calculate breakpoint segments algorithm. Performs
402+
/// a single pass
401403
List<ResponsiveBreakpointSegment> getBreakpointSegments(
402404
List<ResponsiveBreakpoint> breakpoints,
403405
ResponsiveBreakpoint defaultBreakpoint) {
@@ -414,10 +416,14 @@ class _ResponsiveWrapperState extends State<ResponsiveWrapper>
414416
// Perform ordering operation to allow breakpoints
415417
// to be accepted in any order.
416418
breakpoints.sort((a, b) {
417-
// If breakpoints are equal, return autoScaleDown
418-
// breakpoints first.
419+
// If breakpoints are equal, return in the following order:
420+
// AutoScaleDown, Resize, AutoScale.
419421
if (a.breakpoint == b.breakpoint && a.isAutoScaleDown) {
420-
if (a.isAutoScaleDown) {
422+
if (a.isAutoScaleDown && !b.isAutoScaleDown) {
423+
return -1;
424+
}
425+
426+
if (a.isResize && !b.isAutoScaleDown) {
421427
return -1;
422428
}
423429

@@ -765,6 +771,20 @@ enum _ResponsiveBreakpointBehavior {
765771
TAG,
766772
}
767773

774+
/// Control the responsiveness of the app at a breakpoint.
775+
///
776+
/// Specify a responsive [behavior] at a [breakpoint]
777+
/// value. The following behaviors are supported:
778+
/// Resize - default behavior.
779+
/// AutoScale - scales UI from breakpoint up.
780+
/// AutoScaleDown - scales UI from breakpoint down and
781+
/// from breakpoint up. Has the same behavior as AutoScale
782+
/// but scales down as well.
783+
/// Tag - named breakpoint value. Inherits behavior.
784+
/// Add a [name] to a breakpoint for ease of reference.
785+
/// The [scaleFactor] enlarges or shrinks the UI by a
786+
/// multiple of x. This values can be applied to all
787+
/// breakpoints.
768788
@immutable
769789
class ResponsiveBreakpoint {
770790
final double breakpoint;
@@ -839,6 +859,16 @@ class ResponsiveBreakpoint {
839859
')';
840860
}
841861

862+
/// Computed breakpoint segments.
863+
///
864+
/// Breakpoint segments are computed from
865+
/// 0 to infinity. The [breakpoint] specifies the
866+
/// start position for the [responsiveBreakpointBehavior].
867+
/// The [responsiveBreakpointBehavior] specifies
868+
/// how the segment behavior is computed.
869+
/// The [responsiveBreakpoint] holds the active
870+
/// breakpoint and controls the segment behavior.
871+
@immutable
842872
class ResponsiveBreakpointSegment {
843873
final double breakpoint;
844874
final _ResponsiveBreakpointBehavior responsiveBreakpointBehavior;

0 commit comments

Comments
 (0)