Toggle navigation
Toggle navigation
This project
Loading...
Sign in
flutter_package
/
flutter_screenutil
Go to a project
Toggle navigation
Projects
Groups
Snippets
Help
Toggle navigation pinning
Project
Activity
Repository
Pipelines
Graphs
Issues
0
Merge Requests
0
Wiki
Network
Create a new issue
Builds
Commits
Authored by
hussam
2022-03-01 00:18:36 +0200
Browse Files
Options
Browse Files
Download
Email Patches
Plain Diff
Commit
ffc43f3025775367adf05ec2f263ae8d01fc3deb
ffc43f30
1 parent
562a1502
refactor: add RSizedBox widget
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
69 additions
and
1 deletions
lib/src/r_sizedbox.dart
lib/src/size_extension.dart
lib/src/r_sizedbox.dart
0 → 100644
View file @
ffc43f3
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
.
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
;
}
}
...
...
lib/src/size_extension.dart
View file @
ffc43f3
...
...
@@ -2,7 +2,7 @@ import 'dart:math';
import
'package:flutter/material.dart'
;
import
'
../flutter_screen
util.dart'
;
import
'
screen_
util.dart'
;
extension
SizeExtension
on
num
{
///[ScreenUtil.setWidth]
...
...
@@ -75,3 +75,21 @@ extension RaduisExtension on Radius {
..
x
.
r
..
y
.
r
;
}
extension
BoxConstraintsExtension
on
BoxConstraints
{
/// Creates adapt BoxConstraints using r [SizeExtension].
BoxConstraints
get
r
=>
this
.
copyWith
(
maxHeight:
maxHeight
.
r
,
maxWidth:
maxWidth
.
r
,
minHeight:
minHeight
.
r
,
minWidth:
minWidth
.
r
,
);
/// Creates adapt BoxConstraints using h-w [SizeExtension].
BoxConstraints
get
hw
=>
this
.
copyWith
(
maxHeight:
maxHeight
.
h
,
maxWidth:
maxWidth
.
w
,
minHeight:
minHeight
.
h
,
minWidth:
minWidth
.
w
,
);
}
...
...
Please
register
or
login
to post a comment