Guest User

Untitled

a guest
Jun 19th, 2018
98
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.05 KB | None | 0 0
  1. // Copyright 2018 The Chromium Authors. All rights reserved.
  2. // Use of this source code is governed by a BSD-style license that can be
  3. // found in the LICENSE file.
  4.  
  5. import 'package:flutter/rendering.dart';
  6.  
  7. import 'basic.dart';
  8. import 'framework.dart';
  9.  
  10. /// Spacer creates an adjustable, empty spacer that can be used to tune the
  11. /// spacing between widgets, like [Row] or [Column].
  12. ///
  13. /// Different implementations include:
  14. /// - An optional flex: parameter causes the Spacer to utilize
  15. /// an Expanded that defaults to 1 if all parameters are left null.
  16. ///
  17. /// - Setting a value for the flex: parameter will cause the Spacer to
  18. /// utilize that value for it's Expanded.
  19. ///
  20. /// - Setting a value for width: and/or height: will cause the Spacer to
  21. /// use only a SizedBox with the width: or height: specified. In this case,
  22. /// the Spacer will not utilize an expanded at all.
  23. ///
  24. /// By default, with no parameters set, the [Spacer] widget will take up any
  25. /// available space, so setting the [Flex.mainAxisAlignment] on a flex container
  26. /// that contains a [Spacer] to [MainAxisAlignment.spaceAround],
  27. /// [MainAxisAlignment.spaceBetween], or [MainAxisAlignment.spaceEvenly] will not
  28. /// have any visible effect: the [Spacer] has taken up all of the additional space,
  29. /// so there is none left to redistribute.
  30. ///
  31. ///
  32. ///
  33. /// ## Sample code examples
  34. ///
  35. /// ```dart
  36. /// new Row(
  37. /// children: <Widget>[
  38. /// new Text('Begin'),
  39. /// new Spacer(), // Defaults to a flex of one.
  40. /// new Text('Middle'),
  41. /// // Gives twice the space between Middle and End than Begin and Middle.
  42. /// new Spacer(flex: 2),
  43. /// new Text('End'),
  44. /// ],
  45. /// )
  46. /// ```
  47. ///
  48. /// /// ```dart
  49. ///// new Row(
  50. ///// children: <Widget>[
  51. ///// new Text('Begin'),
  52. ///// new Spacer(
  53. ///// height: 100,
  54. ///// ), // Utilizes a SizedBox with a height of 100.
  55. ///// new Text('End'),
  56. ///// ],
  57. ///// )
  58. ///// ```
  59. ///
  60. /// See also:
  61. ///
  62. /// * [Row] and [Column], which are the most common containers to use a Spacer
  63. /// in.
  64. /// * [SizedBox], to create a box with a specific size and an optional child.
  65. class Spacer extends StatelessWidget {
  66. /// Creates a flexible space to insert into a [Flexible] widget.
  67. ///
  68. /// The [flex] parameter may not be null or less than one.
  69. const Spacer({Key key, this.flex = 1})
  70. : assert(flex > 0),
  71. super(key: key);
  72.  
  73. const Spacer.fromSize({
  74. Key key,
  75. this.width,
  76. this.height,
  77. })
  78. /// The flex factor to use in determining how much space to take up.
  79. ///
  80. /// The amount of space the [Spacer] can occupy in the main axis is determined
  81. /// by dividing the free space proportionately, after placing the inflexible
  82. /// children, according to the flex factors of the flexible children.
  83. ///
  84. /// Defaults to one.
  85. final int flex;
  86. final double width;
  87. final double height;
  88.  
  89. @override
  90. Widget build(BuildContext context) {
  91. return
  92. width != null || height != null ? SizedBox(
  93. width: width,
  94. height: height)
  95. : Expanded(
  96. flex: flex,
  97. child: const SizedBox(
  98. height: 0.0,
  99. width: 0.0,
  100. ),
  101. );
  102. }
  103. }
Add Comment
Please, Sign In to add comment