Created
December 19, 2020 18:46
-
-
Save venkatd/d026230c8abac5883d48c13ead0f8724 to your computer and use it in GitHub Desktop.
If you want to add some space in your rows/columns, can give this a try.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import 'package:flutter/widgets.dart'; | |
class SeparatedRow extends StatelessWidget { | |
const SeparatedRow({ | |
@required this.separator, | |
@required this.children, | |
this.mainAxisAlignment = MainAxisAlignment.start, | |
this.mainAxisSize = MainAxisSize.max, | |
this.crossAxisAlignment = CrossAxisAlignment.center, | |
}) : assert(separator != null), | |
assert(children != null); | |
final List<Widget> children; | |
final Widget separator; | |
final MainAxisAlignment mainAxisAlignment; | |
final MainAxisSize mainAxisSize; | |
final CrossAxisAlignment crossAxisAlignment; | |
@override | |
Widget build(BuildContext context) { | |
return Row( | |
mainAxisAlignment: mainAxisAlignment, | |
mainAxisSize: mainAxisSize, | |
crossAxisAlignment: crossAxisAlignment, | |
children: [..._intersperse(children, separator)], | |
); | |
} | |
} | |
class SeparatedColumn extends StatelessWidget { | |
const SeparatedColumn({ | |
@required this.separator, | |
@required this.children, | |
this.mainAxisAlignment = MainAxisAlignment.start, | |
this.mainAxisSize = MainAxisSize.max, | |
this.crossAxisAlignment = CrossAxisAlignment.center, | |
}) : assert(separator != null), | |
assert(children != null); | |
final List<Widget> children; | |
final Widget separator; | |
final MainAxisAlignment mainAxisAlignment; | |
final MainAxisSize mainAxisSize; | |
final CrossAxisAlignment crossAxisAlignment; | |
@override | |
Widget build(BuildContext context) { | |
return Column( | |
mainAxisAlignment: mainAxisAlignment, | |
mainAxisSize: mainAxisSize, | |
crossAxisAlignment: crossAxisAlignment, | |
children: [..._intersperse(children, separator)], | |
); | |
} | |
} | |
Iterable<T> _intersperse<T>(Iterable<T> elements, T value) { | |
return elements.expand((el) sync* { | |
yield value; | |
yield el; | |
}).skip(1); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment