Skip to content

Commit

Permalink
Merge pull request #132 from LeGoffMael/performances
Browse files Browse the repository at this point in the history
change: improve widgets performances
  • Loading branch information
LeGoffMael committed Jan 5, 2023
2 parents 4e08096 + da7a4db commit 20ab6e9
Show file tree
Hide file tree
Showing 8 changed files with 82 additions and 58 deletions.
16 changes: 9 additions & 7 deletions lib/ui/cover/cover_selection.dart
Original file line number Diff line number Diff line change
Expand Up @@ -207,13 +207,15 @@ class _CoverSelectionState extends State<CoverSelection>
.addPostFrameCallback((_) => _scaleRect());
}

return CustomPaint(
size: Size.infinite,
painter: CropGridPainter(
_rect.value,
radius: coverStyle.borderRadius / 2,
showGrid: false,
style: widget.controller.cropStyle,
return RepaintBoundary(
child: CustomPaint(
size: Size.infinite,
painter: CropGridPainter(
_rect.value,
radius: coverStyle.borderRadius / 2,
showGrid: false,
style: widget.controller.cropStyle,
),
),
);
}),
Expand Down
8 changes: 7 additions & 1 deletion lib/ui/crop/crop_grid_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,13 @@ class CropGridPainter extends CustomPainter {
}

@override
bool shouldRepaint(CropGridPainter oldDelegate) => true;
bool shouldRepaint(CropGridPainter oldDelegate) =>
oldDelegate.rect != rect ||
oldDelegate.style != style ||
oldDelegate.boundary != boundary ||
oldDelegate.radius != radius ||
oldDelegate.showCenterRects != showCenterRects ||
oldDelegate.showGrid != showGrid;

@override
bool shouldRebuildSemantics(CropGridPainter oldDelegate) => false;
Expand Down
18 changes: 10 additions & 8 deletions lib/ui/crop/crop_mixin.dart
Original file line number Diff line number Diff line change
Expand Up @@ -106,14 +106,16 @@ mixin CropPreviewMixin<T extends StatefulWidget> on State<T> {
valueListenable: rect,

/// Build a [Widget] that hides the cropped area and show the crop grid if widget.showGris is true
builder: (_, Rect value, __) => CustomPaint(
size: Size.infinite,
painter: CropGridPainter(
value,
style: controller.cropStyle,
boundary: boundary,
showGrid: showGrid,
showCenterRects: showCenterRects,
builder: (_, Rect value, __) => RepaintBoundary(
child: CustomPaint(
size: Size.infinite,
painter: CropGridPainter(
value,
style: controller.cropStyle,
boundary: boundary,
showGrid: showGrid,
showCenterRects: showCenterRects,
),
),
),
);
Expand Down
6 changes: 5 additions & 1 deletion lib/ui/image_viewer.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,11 @@ class ImageViewer extends StatelessWidget {
image: MemoryImage(bytes),
placeholder: MemoryImage(kTransparentImage),
)
: Image.memory(bytes),
: Image.memory(
bytes,
color: const Color.fromRGBO(255, 255, 255, 0.2),
colorBlendMode: BlendMode.modulate,
),
),
if (child != null)
AspectRatio(
Expand Down
40 changes: 22 additions & 18 deletions lib/ui/transform.dart
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,16 @@ class CropTransform extends StatelessWidget {

@override
Widget build(BuildContext context) {
return ClipRRect(
child: Transform.rotate(
angle: transform.rotation,
child: Transform.scale(
scale: transform.scale,
child: Transform.translate(
offset: transform.translate,
child: child,
return RepaintBoundary(
child: ClipRRect(
child: Transform.rotate(
angle: transform.rotation,
child: Transform.scale(
scale: transform.scale,
child: Transform.translate(
offset: transform.translate,
child: child,
),
),
),
),
Expand Down Expand Up @@ -48,16 +50,18 @@ class CropTransformWithAnimation extends StatelessWidget {
return CropTransform(transform: transform, child: child);
}

return AnimatedRotation(
// convert rad to turns
turns: transform.rotation * (57.29578 / 360),
curve: Curves.easeInOut,
duration: const Duration(milliseconds: 300),
child: Transform.scale(
scale: transform.scale,
child: Transform.translate(
offset: transform.translate,
child: child,
return RepaintBoundary(
child: AnimatedRotation(
// convert rad to turns
turns: transform.rotation * (57.29578 / 360),
curve: Curves.easeInOut,
duration: const Duration(milliseconds: 300),
child: Transform.scale(
scale: transform.scale,
child: Transform.translate(
offset: transform.translate,
child: child,
),
),
),
);
Expand Down
27 changes: 13 additions & 14 deletions lib/ui/trim/thumbnail_slider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -125,13 +125,10 @@ class _ThumbnailSliderState extends State<ThumbnailSlider> {

return Stack(
children: [
Opacity(
opacity: 0.2,
child: _buildSingleThumbnail(
data[0],
transform,
isPlaceholder: true,
),
_buildSingleThumbnail(
data[0],
transform,
isPlaceholder: true,
),
if (index < data.length)
_buildSingleThumbnail(
Expand Down Expand Up @@ -164,19 +161,21 @@ class _ThumbnailSliderState extends State<ThumbnailSlider> {
bytes: bytes,
fadeIn: !isPlaceholder,
child: LayoutBuilder(builder: (_, constraints) {
Size size = constraints.biggest;
final size = constraints.biggest;
if (!isPlaceholder && _layout != size) {
_layout = size;
// init the widget with controller values
WidgetsBinding.instance.addPostFrameCallback((_) => _scaleRect());
}

return CustomPaint(
size: Size.infinite,
painter: CropGridPainter(
_rect.value,
showGrid: false,
style: widget.controller.cropStyle,
return RepaintBoundary(
child: CustomPaint(
size: Size.infinite,
painter: CropGridPainter(
_rect.value,
showGrid: false,
style: widget.controller.cropStyle,
),
),
);
}),
Expand Down
18 changes: 10 additions & 8 deletions lib/ui/trim/trim_slider.dart
Original file line number Diff line number Diff line change
Expand Up @@ -585,14 +585,16 @@ class _TrimSliderState extends State<TrimSlider>
widget.controller.video,
]),
builder: (_, __) {
return CustomPaint(
size: Size.fromHeight(widget.height),
painter: TrimSliderPainter(
_rect,
_getVideoPosition(),
widget.controller.trimStyle,
isTrimming: widget.controller.isTrimming,
isTrimmed: widget.controller.isTrimmed,
return RepaintBoundary(
child: CustomPaint(
size: Size.fromHeight(widget.height),
painter: TrimSliderPainter(
_rect,
_getVideoPosition(),
widget.controller.trimStyle,
isTrimming: widget.controller.isTrimming,
isTrimmed: widget.controller.isTrimmed,
),
),
);
},
Expand Down
7 changes: 6 additions & 1 deletion lib/ui/trim/trim_slider_painter.dart
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,12 @@ class TrimSliderPainter extends CustomPainter {
}

@override
bool shouldRepaint(TrimSliderPainter oldDelegate) => true;
bool shouldRepaint(TrimSliderPainter oldDelegate) =>
oldDelegate.rect != rect ||
oldDelegate.position != position ||
oldDelegate.style != style ||
oldDelegate.isTrimming != isTrimming ||
oldDelegate.isTrimmed != isTrimmed;

@override
bool shouldRebuildSemantics(TrimSliderPainter oldDelegate) => false;
Expand Down

0 comments on commit 20ab6e9

Please sign in to comment.