11import 'package:flutter/cupertino.dart' ;
22import 'package:flutter/widgets.dart' ;
33
4+ enum ResponsiveRowColumnType {
5+ ROW ,
6+ COLUMN ,
7+ }
8+
49/// A convenience wrapper for responsive [Row] and
510/// [Column] switching with padding and spacing.
611///
712/// ResponsiveRowColumn combines responsiveness
813/// behaviors for managing rows and columns into one
914/// convenience widget. This widget requires all [children]
1015/// 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.
16+ /// Row vs column layout is controlled by passing a
17+ /// [ResponsiveRowColumnType] to [layout] .
1418/// Add spacing between widgets with [rowSpacing] and
1519/// [columnSpacing] . Add padding around widgets with
1620/// [rowPadding] and [columnPadding] .
@@ -19,7 +23,7 @@ import 'package:flutter/widgets.dart';
1923/// [FlexFit] options.
2024class ResponsiveRowColumn extends StatelessWidget {
2125 final List <ResponsiveRowColumnItem > children;
22- final bool rowColumn ;
26+ final ResponsiveRowColumnType layout ;
2327 final MainAxisAlignment rowMainAxisAlignment;
2428 final MainAxisSize rowMainAxisSize;
2529 final CrossAxisAlignment rowCrossAxisAlignment;
@@ -36,13 +40,13 @@ class ResponsiveRowColumn extends StatelessWidget {
3640 final double ? columnSpacing;
3741 final EdgeInsets rowPadding;
3842 final EdgeInsets columnPadding;
39- get isRow => rowColumn ;
40- get isColumn => ! rowColumn ;
43+ get isRow => layout == ResponsiveRowColumnType . ROW ;
44+ get isColumn => layout == ResponsiveRowColumnType . COLUMN ;
4145
4246 const ResponsiveRowColumn (
4347 {Key ? key,
4448 this .children = const [],
45- required this .rowColumn ,
49+ required this .layout ,
4650 this .rowMainAxisAlignment = MainAxisAlignment .start,
4751 this .rowMainAxisSize = MainAxisSize .max,
4852 this .rowCrossAxisAlignment = CrossAxisAlignment .center,
@@ -63,35 +67,36 @@ class ResponsiveRowColumn extends StatelessWidget {
6367
6468 @override
6569 Widget build (BuildContext context) {
66- return rowColumn
67- ? Padding (
68- padding: rowPadding,
69- child: Row (
70- mainAxisAlignment: rowMainAxisAlignment,
71- mainAxisSize: rowMainAxisSize,
72- crossAxisAlignment: rowCrossAxisAlignment,
73- textDirection: rowTextDirection,
74- verticalDirection: rowVerticalDirection,
75- textBaseline: rowTextBaseline,
76- children: [
77- ...buildChildren (children, rowColumn, rowSpacing),
78- ],
79- ),
80- )
81- : Padding (
82- padding: columnPadding,
83- child: Column (
84- mainAxisAlignment: columnMainAxisAlignment,
85- mainAxisSize: columnMainAxisSize,
86- crossAxisAlignment: columnCrossAxisAlignment,
87- textDirection: columnTextDirection,
88- verticalDirection: columnVerticalDirection,
89- textBaseline: columnTextBaseline,
90- children: [
91- ...buildChildren (children, rowColumn, columnSpacing),
92- ],
93- ),
94- );
70+ if (layout == ResponsiveRowColumnType .ROW )
71+ return Padding (
72+ padding: rowPadding,
73+ child: Row (
74+ mainAxisAlignment: rowMainAxisAlignment,
75+ mainAxisSize: rowMainAxisSize,
76+ crossAxisAlignment: rowCrossAxisAlignment,
77+ textDirection: rowTextDirection,
78+ verticalDirection: rowVerticalDirection,
79+ textBaseline: rowTextBaseline,
80+ children: [
81+ ...buildChildren (children, true , rowSpacing),
82+ ],
83+ ),
84+ );
85+
86+ return Padding (
87+ padding: columnPadding,
88+ child: Column (
89+ mainAxisAlignment: columnMainAxisAlignment,
90+ mainAxisSize: columnMainAxisSize,
91+ crossAxisAlignment: columnCrossAxisAlignment,
92+ textDirection: columnTextDirection,
93+ verticalDirection: columnVerticalDirection,
94+ textBaseline: columnTextBaseline,
95+ children: [
96+ ...buildChildren (children, false , columnSpacing),
97+ ],
98+ ),
99+ );
95100 }
96101
97102 /// Logic to construct widget [children] .
0 commit comments