Skip to content

Commit

Permalink
refactor: make Hero part of ImageOrVideoWidget
Browse files Browse the repository at this point in the history
  • Loading branch information
Ascenio committed May 7, 2024
1 parent 67fdd34 commit 9748839
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 59 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,9 @@ class DetailsPage extends StatelessWidget {
body: CustomScrollView(
slivers: [
SliverToBoxAdapter(
child: Hero(
tag: picture.url,
child: ImageOrVideoWidget(
isVideo: picture.isVideo,
url: picture.url,
),
child: ImageOrVideoWidget(
isVideo: picture.isVideo,
url: picture.url,
),
),
const SliverPadding(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,55 +13,58 @@ class ImageOrVideoWidget extends StatelessWidget {
@override
Widget build(BuildContext context) {
final size = MediaQuery.sizeOf(context);
return SizedBox(
height: size.height / 3,
child: switch (isVideo) {
true => Container(
width: double.infinity,
color: Colors.black,
child: Image.asset('assets/youtube-logo.png'),
),
false => Image.network(
url.toString(),
width: double.infinity,
height: size.height / 3,
cacheHeight: size.height ~/ 3,
fit: BoxFit.cover,
frameBuilder: (context, child, frame, wasSynchronouslyLoaded) {
return AnimatedOpacity(
duration: const Duration(milliseconds: 400),
opacity: frame == null ? 0 : 1,
child: child,
);
},
loadingBuilder: (context, child, loadingProgress) {
var progress = 0.0;
if (loadingProgress != null &&
loadingProgress.expectedTotalBytes != 0) {
progress = loadingProgress.cumulativeBytesLoaded /
loadingProgress.expectedTotalBytes!;
}
return Hero(
tag: url,
child: SizedBox(
height: size.height / 3,
child: switch (isVideo) {
true => Container(
width: double.infinity,
color: Colors.black,
child: Image.asset('assets/youtube-logo.png'),
),
false => Image.network(
url.toString(),
width: double.infinity,
height: size.height / 3,
cacheHeight: size.height ~/ 3,
fit: BoxFit.cover,
frameBuilder: (context, child, frame, wasSynchronouslyLoaded) {
return AnimatedOpacity(
duration: const Duration(milliseconds: 400),
opacity: frame == null ? 0 : 1,
child: child,
);
},
loadingBuilder: (context, child, loadingProgress) {
var progress = 0.0;
if (loadingProgress != null &&
loadingProgress.expectedTotalBytes != 0) {
progress = loadingProgress.cumulativeBytesLoaded /
loadingProgress.expectedTotalBytes!;
}

return DecoratedBox(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: const [
Colors.grey,
Colors.white,
],
begin: Alignment.bottomLeft,
end: Alignment.topRight,
stops: [
0,
progress,
],
return DecoratedBox(
decoration: BoxDecoration(
gradient: LinearGradient(
colors: const [
Colors.grey,
Colors.white,
],
begin: Alignment.bottomLeft,
end: Alignment.topRight,
stops: [
0,
progress,
],
),
),
),
child: child,
);
},
),
},
child: child,
);
},
),
},
),
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,9 @@ class PictureWidget extends StatelessWidget {
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
Hero(
tag: picture.url,
child: ImageOrVideoWidget(
isVideo: picture.isVideo,
url: picture.url,
),
ImageOrVideoWidget(
isVideo: picture.isVideo,
url: picture.url,
),
const SizedBox(height: 8),
Padding(
Expand Down

0 comments on commit 9748839

Please sign in to comment.