1- import 'package:flutter/widgets.dart' ;
2-
3- /// A widget that positions its child to a fraction of the total available space.
4- class FractionallyAlignedSizedBox extends StatelessWidget {
5- /// Creates a widget that positions its child to a fraction of the total available space.
6- ///
7- /// Only two out of the three horizontal values ([leftFactor] , [rightFactor] ,
8- /// [widthFactor] ), and only two out of the three vertical values ([topFactor] ,
9- /// [bottomFactor] , [heightFactor] ), can be set. In each case, at least one of
10- /// the three must be null.
11- ///
12- /// If non-null, the [widthFactor] and [heightFactor] arguments must be
13- /// non-negative.
14- FractionallyAlignedSizedBox ({
15- Key key,
16- @required this .child,
17- this .leftFactor,
18- this .topFactor,
19- this .rightFactor,
20- this .bottomFactor,
21- this .widthFactor,
22- this .heightFactor,
23- }) : assert (
24- leftFactor == null || rightFactor == null || widthFactor == null ),
25- assert (
26- topFactor == null || bottomFactor == null || heightFactor == null ),
27- assert (widthFactor == null || widthFactor >= 0.0 ),
28- assert (heightFactor == null || heightFactor >= 0.0 ),
29- super (key: key);
30-
31- /// The relative distance that the child's left edge is inset from the left of the parent.
32- final double leftFactor;
33-
34- /// The relative distance that the child's top edge is inset from the top of the parent.
35- final double topFactor;
36-
37- /// The relative distance that the child's right edge is inset from the right of the parent.
38- final double rightFactor;
39-
40- /// The relative distance that the child's bottom edge is inset from the bottom of the parent.
41- final double bottomFactor;
42-
43- /// The child's width relative to its parent's width.
44- final double widthFactor;
45-
46- /// The child's height relative to its parent's height.
47- final double heightFactor;
48-
49- /// The widget below this widget in the tree.
50- final Widget child;
51-
52- @override
53- Widget build (BuildContext context) {
54- double dx = 0 ;
55- double dy = 0 ;
56- double width = widthFactor;
57- double height = heightFactor;
58-
59- if (widthFactor == null ) {
60- final left = leftFactor ?? 0 ;
61- final right = rightFactor ?? 0 ;
62- width = 1 - left - right;
63-
64- if (width != 1 ) {
65- dx = left / (1.0 - width);
66- }
67- }
68-
69- if (heightFactor == null ) {
70- final top = topFactor ?? 0 ;
71- final bottom = bottomFactor ?? 0 ;
72- height = 1 - top - bottom;
73- if (height != 1 ) {
74- dy = top / (1.0 - height);
75- }
76- }
77-
78- if (widthFactor != null && widthFactor != 1 ) {
79- if (leftFactor != null ) {
80- dx = leftFactor / (1 - widthFactor);
81- } else if (leftFactor == null && rightFactor != null ) {
82- dx = (1 - widthFactor - rightFactor) / (1 - widthFactor);
83- }
84- }
85-
86- if (heightFactor != null && heightFactor != 1 ) {
87- if (topFactor != null ) {
88- dy = topFactor / (1 - heightFactor);
89- } else if (topFactor == null && bottomFactor != null ) {
90- dy = (1 - heightFactor - bottomFactor) / (1 - heightFactor);
91- }
92- }
93-
94- return Align (
95- alignment: FractionalOffset (
96- dx,
97- dy,
98- ),
99- child: FractionallySizedBox (
100- widthFactor: width,
101- heightFactor: height,
102- child: child,
103- ),
104- );
105- }
106- }
1+ // import 'package:flutter/widgets.dart';
2+ //
3+ ///// A widget that positions its child to a fraction of the total available space.
4+ // class FractionallyAlignedSizedBox extends StatelessWidget {
5+ // /// Creates a widget that positions its child to a fraction of the total available space.
6+ // ///
7+ // /// Only two out of the three horizontal values ([leftFactor], [rightFactor],
8+ // /// [widthFactor]), and only two out of the three vertical values ([topFactor],
9+ // /// [bottomFactor], [heightFactor]), can be set. In each case, at least one of
10+ // /// the three must be null.
11+ // ///
12+ // /// If non-null, the [widthFactor] and [heightFactor] arguments must be
13+ // /// non-negative.
14+ // FractionallyAlignedSizedBox({
15+ // Key key,
16+ // @required this.child,
17+ // this.leftFactor,
18+ // this.topFactor,
19+ // this.rightFactor,
20+ // this.bottomFactor,
21+ // this.widthFactor,
22+ // this.heightFactor,
23+ // }) : assert(
24+ // leftFactor == null || rightFactor == null || widthFactor == null),
25+ // assert(
26+ // topFactor == null || bottomFactor == null || heightFactor == null),
27+ // assert(widthFactor == null || widthFactor >= 0.0),
28+ // assert(heightFactor == null || heightFactor >= 0.0),
29+ // super(key: key);
30+ //
31+ // /// The relative distance that the child's left edge is inset from the left of the parent.
32+ // final double leftFactor;
33+ //
34+ // /// The relative distance that the child's top edge is inset from the top of the parent.
35+ // final double topFactor;
36+ //
37+ // /// The relative distance that the child's right edge is inset from the right of the parent.
38+ // final double rightFactor;
39+ //
40+ // /// The relative distance that the child's bottom edge is inset from the bottom of the parent.
41+ // final double bottomFactor;
42+ //
43+ // /// The child's width relative to its parent's width.
44+ // final double widthFactor;
45+ //
46+ // /// The child's height relative to its parent's height.
47+ // final double heightFactor;
48+ //
49+ // /// The widget below this widget in the tree.
50+ // final Widget child;
51+ //
52+ // @override
53+ // Widget build(BuildContext context) {
54+ // double dx = 0;
55+ // double dy = 0;
56+ // double width = widthFactor;
57+ // double height = heightFactor;
58+ //
59+ // if (widthFactor == null) {
60+ // final left = leftFactor ?? 0;
61+ // final right = rightFactor ?? 0;
62+ // width = 1 - left - right;
63+ //
64+ // if (width != 1) {
65+ // dx = left / (1.0 - width);
66+ // }
67+ // }
68+ //
69+ // if (heightFactor == null) {
70+ // final top = topFactor ?? 0;
71+ // final bottom = bottomFactor ?? 0;
72+ // height = 1 - top - bottom;
73+ // if (height != 1) {
74+ // dy = top / (1.0 - height);
75+ // }
76+ // }
77+ //
78+ // if (widthFactor != null && widthFactor != 1) {
79+ // if (leftFactor != null) {
80+ // dx = leftFactor / (1 - widthFactor);
81+ // } else if (leftFactor == null && rightFactor != null) {
82+ // dx = (1 - widthFactor - rightFactor) / (1 - widthFactor);
83+ // }
84+ // }
85+ //
86+ // if (heightFactor != null && heightFactor != 1) {
87+ // if (topFactor != null) {
88+ // dy = topFactor / (1 - heightFactor);
89+ // } else if (topFactor == null && bottomFactor != null) {
90+ // dy = (1 - heightFactor - bottomFactor) / (1 - heightFactor);
91+ // }
92+ // }
93+ //
94+ // return Align(
95+ // alignment: FractionalOffset(
96+ // dx,
97+ // dy,
98+ // ),
99+ // child: FractionallySizedBox(
100+ // widthFactor: width,
101+ // heightFactor: height,
102+ // child: child,
103+ // ),
104+ // );
105+ // }
106+ // }
0 commit comments