Skip to content

Commit

Permalink
feat: use typed assets instead of hard coded paths
Browse files Browse the repository at this point in the history
  • Loading branch information
KRTirtho committed Jan 31, 2023
1 parent c809d2d commit 59561ab
Show file tree
Hide file tree
Showing 17 changed files with 351 additions and 139 deletions.
2 changes: 1 addition & 1 deletion .fvm/fvm_config.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{
"flutterSdkVersion": "3.0.5",
"flutterSdkVersion": "3.3.8",
"flavors": {}
}
182 changes: 182 additions & 0 deletions lib/collections/assets.gen.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

4 changes: 2 additions & 2 deletions lib/components/player/player_track_details.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:platform_ui/platform_ui.dart';
import 'package:spotube/collections/assets.gen.dart';
import 'package:spotube/components/shared/image/universal_image.dart';
import 'package:spotube/hooks/use_breakpoints.dart';
import 'package:spotube/provider/playback_provider.dart';
Expand All @@ -27,8 +28,7 @@ class PlayerTrackDetails extends HookConsumerWidget {
height: 50,
width: 50,
placeholder: (context, url) {
return Image.asset(
"assets/album-placeholder.png",
return Assets.albumPlaceholder.image(
height: 50,
width: 50,
);
Expand Down
3 changes: 2 additions & 1 deletion lib/components/root/bottom_player.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:macos_ui/macos_ui.dart';
import 'package:fluent_ui/fluent_ui.dart' as fluent_ui;
import 'package:platform_ui/platform_ui.dart';
import 'package:spotube/collections/assets.gen.dart';
import 'package:spotube/components/player/player_actions.dart';
import 'package:spotube/components/player/player_overlay.dart';
import 'package:spotube/components/player/player_track_details.dart';
Expand Down Expand Up @@ -36,7 +37,7 @@ class BottomPlayer extends HookConsumerWidget {
index: (playback.track?.album?.images?.length ?? 1) - 1,
placeholder: ImagePlaceholder.albumArt,
)
: "assets/album-placeholder.png",
: Assets.albumPlaceholder.path,
[playback.track?.album?.images],
);

Expand Down
11 changes: 4 additions & 7 deletions lib/components/root/sidebar.dart
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,9 @@ import 'package:fl_query_hooks/fl_query_hooks.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:flutter/material.dart';
import 'package:flutter/material.dart' hide Badge;
import 'package:platform_ui/platform_ui.dart';
import 'package:spotube/collections/assets.gen.dart';
import 'package:spotube/collections/side_bar_tiles.dart';
import 'package:spotube/collections/spotube_icons.dart';
import 'package:spotube/components/shared/image/universal_image.dart';
Expand Down Expand Up @@ -37,10 +38,7 @@ class Sidebar extends HookConsumerWidget {
color: Colors.black,
borderRadius: BorderRadius.circular(50),
),
child: Image.asset(
"assets/spotube-logo.png",
height: 50,
),
child: Assets.spotubeLogoPng.image(height: 50),
);
}

Expand Down Expand Up @@ -242,8 +240,7 @@ class SidebarFooter extends HookConsumerWidget {
backgroundImage:
UniversalImage.imageProvider(avatarImg),
onBackgroundImageError: (exception, stackTrace) =>
Image.asset(
"assets/user-placeholder.png",
Assets.userPlaceholder.image(
height: 16,
width: 16,
),
Expand Down
3 changes: 2 additions & 1 deletion lib/components/shared/fallbacks/not_found.dart
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import 'package:flutter/material.dart';
import 'package:spotube/collections/assets.gen.dart';

class NotFound extends StatelessWidget {
final bool vertical;
Expand All @@ -10,7 +11,7 @@ class NotFound extends StatelessWidget {
SizedBox(
height: 150,
width: 150,
child: Image.asset("assets/empty_box.png"),
child: Assets.emptyBox.image(),
),
Column(
crossAxisAlignment: CrossAxisAlignment.start,
Expand Down
10 changes: 4 additions & 6 deletions lib/components/shared/image/universal_image.dart
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import 'dart:io';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:spotube/collections/assets.gen.dart';

class UniversalImage extends HookWidget {
final String path;
Expand Down Expand Up @@ -64,8 +65,7 @@ class UniversalImage extends HookWidget {
scale: scale,
errorBuilder: (context, error, stackTrace) {
return placeholder?.call(context, error.toString()) ??
Image.asset(
"assets/placeholder.png",
Assets.placeholder.image(
width: width,
height: height,
cacheHeight: height?.toInt(),
Expand All @@ -84,8 +84,7 @@ class UniversalImage extends HookWidget {
scale: scale,
errorBuilder: (context, error, stackTrace) {
return placeholder?.call(context, error.toString()) ??
Image.asset(
"assets/placeholder.png",
Assets.placeholder.image(
width: width,
height: height,
cacheHeight: height?.toInt(),
Expand All @@ -105,8 +104,7 @@ class UniversalImage extends HookWidget {
scale: scale,
errorBuilder: (context, error, stackTrace) {
return placeholder?.call(context, error.toString()) ??
Image.asset(
"assets/placeholder.png",
Assets.placeholder.image(
width: width,
height: height,
cacheHeight: height?.toInt(),
Expand Down
4 changes: 2 additions & 2 deletions lib/components/shared/playbutton_card.dart
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import 'package:flutter/material.dart';
import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:platform_ui/platform_ui.dart';
import 'package:spotube/collections/assets.gen.dart';
import 'package:spotube/collections/spotube_icons.dart';
import 'package:spotube/components/shared/hover_builder.dart';
import 'package:spotube/components/shared/spotube_marquee_text.dart';
Expand Down Expand Up @@ -114,8 +115,7 @@ class PlaybuttonCard extends HookWidget {
child: UniversalImage(
path: imageUrl,
width: isSquare ? 200 : 60,
placeholder: (context, url) =>
Image.asset("assets/placeholder.png"),
placeholder: (context, url) => Assets.placeholder.image(),
),
),
);
Expand Down
7 changes: 3 additions & 4 deletions lib/components/shared/track_table/track_collection_view.dart
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import 'package:fuzzywuzzy/fuzzywuzzy.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:platform_ui/platform_ui.dart';
import 'package:spotube/collections/assets.gen.dart';
import 'package:spotube/collections/spotube_icons.dart';
import 'package:spotube/components/shared/compact_search.dart';
import 'package:spotube/components/shared/shimmers/shimmer_track_tile.dart';
Expand Down Expand Up @@ -185,7 +186,7 @@ class TrackCollectionView<T> extends HookConsumerWidget {
child: searchbar,
);
});
Overlay.of(context)!.insert(entry!);
Overlay.of(context)?.insert(entry!);
}
});
return () => entry?.remove();
Expand Down Expand Up @@ -274,9 +275,7 @@ class TrackCollectionView<T> extends HookConsumerWidget {
child: UniversalImage(
path: titleImage,
placeholder: (context, url) {
return const UniversalImage(
path: "assets/album-placeholder.png",
);
return Assets.albumPlaceholder.image();
},
),
),
Expand Down
4 changes: 2 additions & 2 deletions lib/components/shared/track_table/track_tile.dart
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import 'package:flutter_hooks/flutter_hooks.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:platform_ui/platform_ui.dart';
import 'package:spotify/spotify.dart' hide Image;
import 'package:spotube/collections/assets.gen.dart';
import 'package:spotube/collections/spotube_icons.dart';
import 'package:spotube/components/shared/adaptive/adaptive_popup_menu_button.dart';
import 'package:spotube/components/shared/heart_button.dart';
Expand Down Expand Up @@ -227,8 +228,7 @@ class TrackTile extends HookConsumerWidget {
height: 40,
width: 40,
placeholder: (context, url) {
return Image.asset(
"assets/album-placeholder.png",
return Assets.albumPlaceholder.image(
height: 40,
width: 40,
);
Expand Down
4 changes: 2 additions & 2 deletions lib/pages/desktop_login/desktop_login.dart
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import 'package:flutter/material.dart';
import 'package:go_router/go_router.dart';
import 'package:hooks_riverpod/hooks_riverpod.dart';
import 'package:platform_ui/platform_ui.dart';
import 'package:spotube/collections/assets.gen.dart';
import 'package:spotube/components/desktop_login/login_form.dart';
import 'package:spotube/components/shared/page_window_title_bar.dart';
import 'package:spotube/hooks/use_breakpoints.dart';
Expand Down Expand Up @@ -30,8 +31,7 @@ class DesktopLoginPage extends HookConsumerWidget {
),
child: Column(
children: [
Image.asset(
"assets/spotube-logo.png",
Assets.spotubeLogoPng.image(
width: MediaQuery.of(context).size.width *
(breakpoint <= Breakpoints.md ? .5 : .3),
),
Expand Down
Loading

0 comments on commit 59561ab

Please sign in to comment.