r_sizedbox.dart
1.55 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'size_extension.dart';
class RSizedBox extends SizedBox {
const RSizedBox({
Key? key,
double? height,
double? width,
Widget? child,
}) : _square = false,
super(key: key, child: child, width: width, height: height);
const RSizedBox.vertical(
double? height, {
Key? key,
Widget? child,
}) : _square = false,
super(key: key, child: child, height: height);
const RSizedBox.horizontal(
double? width, {
Key? key,
Widget? child,
}) : _square = false,
super(key: key, child: child, width: width);
const RSizedBox.square({
Key? key,
double? height,
double? dimension,
Widget? child,
}) : _square = true,
super.square(key: key, child: child, dimension: dimension);
RSizedBox.fromSize({
Key? key,
Size? size,
Widget? child,
}) : _square = false,
super.fromSize(key: key, child: child, size: size);
@override
RenderConstrainedBox createRenderObject(BuildContext context) {
return RenderConstrainedBox(
additionalConstraints: _additionalConstraints,
);
}
final bool _square;
BoxConstraints get _additionalConstraints {
final boxConstraints =
BoxConstraints.tightFor(width: width, height: height);
return _square ? boxConstraints.r : boxConstraints.hw;
}
@override
void updateRenderObject(
BuildContext context, RenderConstrainedBox renderObject) {
renderObject.additionalConstraints = _additionalConstraints;
}
}