From 09f7e4fdd16878391bbba81733e05c391a1ba0f5 Mon Sep 17 00:00:00 2001 From: Jakob Meier Date: Fri, 24 Mar 2023 17:47:47 +0100 Subject: [PATCH] Added asset wrapper. FIXES: Image paths on web --- lib/backend/room.dart | 42 +++++++++++++++++++++++++++------------- lib/screens/welcome.dart | 9 +++++---- lib/tools/assets.dart | 11 +++++++++++ pubspec.yaml | 5 +++-- 4 files changed, 48 insertions(+), 19 deletions(-) create mode 100644 lib/tools/assets.dart diff --git a/lib/backend/room.dart b/lib/backend/room.dart index 9aa011a..5c1687f 100644 --- a/lib/backend/room.dart +++ b/lib/backend/room.dart @@ -1,5 +1,6 @@ import 'package:flutter/material.dart'; import 'package:localstore/localstore.dart'; +import 'package:outbag_app/tools/assets.dart'; class RoomVisibility { final int type; @@ -154,35 +155,50 @@ class RoomIcon { // return image name String get img { + String path = ""; switch (type.toLowerCase()) { case 'love': - return 'undraw/undraw_couple.svg'; + path = 'undraw/undraw_couple.svg'; + break; case 'sports': - return 'undraw/undraw_greek_freak.svg'; + path = 'undraw/undraw_greek_freak.svg'; + break; case 'pets': - return 'undraw/undraw_dog.svg'; + path = 'undraw/undraw_dog.svg'; + break; case 'vacation': - return 'undraw/undraw_trip.svg'; + path = 'undraw/undraw_trip.svg'; + break; case 'gifts': - return 'undraw/undraw_gifts.svg'; + path = 'undraw/undraw_gifts.svg'; + break; case 'groceries': - return 'undraw/undraw_gone_shopping.svg'; + path = 'undraw/undraw_gone_shopping.svg'; + break; case 'fashion': - return 'undraw/undraw_jewelry.svg'; + path = 'undraw/undraw_jewelry.svg'; + break; case 'art': - return 'undraw/undraw_sculpting.svg'; + path = 'undraw/undraw_sculpting.svg'; + break; case 'tech': - return 'undraw/undraw_progressive_app.svg'; + path = 'undraw/undraw_progressive_app.svg'; + break; case 'home': - return 'undraw/undraw_under_construction.svg'; + path = 'undraw/undraw_under_construction.svg'; + break; case 'family': - return 'undraw/undraw_family.svg'; + path = 'undraw/undraw_family.svg'; + break; case 'social': - return 'undraw/undraw_pizza_sharing.svg'; + path = 'undraw/undraw_pizza_sharing.svg'; + break; case 'other': default: - return 'undraw/undraw_file_manager.svg'; + path = 'undraw/undraw_file_manager.svg'; } + + return asset(path); } } diff --git a/lib/screens/welcome.dart b/lib/screens/welcome.dart index 9087b6c..344a6f1 100644 --- a/lib/screens/welcome.dart +++ b/lib/screens/welcome.dart @@ -1,4 +1,5 @@ import 'package:flutter/material.dart'; +import 'package:outbag_app/tools/assets.dart'; import 'package:routemaster/routemaster.dart'; import 'package:flutter_svg/flutter_svg.dart'; import 'dart:math'; @@ -60,7 +61,7 @@ class _WelcomePageState extends State { mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ - SvgPicture.asset("undraw/undraw_shopping_app.svg", + SvgPicture.asset(asset("undraw/undraw_shopping_app.svg"), fit: BoxFit.contain, width: smallest*0.5, height: smallest*0.5 @@ -76,7 +77,7 @@ class _WelcomePageState extends State { mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ - SvgPicture.asset("undraw/undraw_mobile_login.svg", + SvgPicture.asset(asset("undraw/undraw_mobile_login.svg"), fit: BoxFit.contain, width: smallest*0.5, height: smallest*0.5), @@ -92,7 +93,7 @@ class _WelcomePageState extends State { mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ - SvgPicture.asset("undraw/undraw_online_connection.svg", + SvgPicture.asset(asset("undraw/undraw_online_connection.svg"), fit: BoxFit.contain, width: smallest*0.5, height: smallest*0.5), @@ -108,7 +109,7 @@ class _WelcomePageState extends State { mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ - SvgPicture.asset("undraw/undraw_online_groceries.svg", + SvgPicture.asset(asset("undraw/undraw_online_groceries.svg"), fit: BoxFit.contain, width: smallest*0.5, height: smallest*0.5), diff --git a/lib/tools/assets.dart b/lib/tools/assets.dart new file mode 100644 index 0000000..adca775 --- /dev/null +++ b/lib/tools/assets.dart @@ -0,0 +1,11 @@ +import 'package:flutter/foundation.dart'; + +String asset(String pathInAssets) { + String prefix = ""; + + if (!kIsWeb || kReleaseMode) { + prefix = "assets/"; + } + + return '$prefix$pathInAssets'; +} diff --git a/pubspec.yaml b/pubspec.yaml index b7b4b04..3aaa468 100644 --- a/pubspec.yaml +++ b/pubspec.yaml @@ -47,7 +47,7 @@ dev_dependencies: # package. See that file for information about deactivating specific lint # rules and activating additional ones. flutter_lints: ^2.0.0 - flutter_launcher_icons: "^0.12.0" + flutter_launcher_icons: ^0.12.0 # For information on the generic Dart part of this file, see the # following page: https://dart.dev/tools/pub/pubspec @@ -65,7 +65,8 @@ flutter: # - images/a_dot_burr.jpeg # - images/a_dot_ham.jpeg assets: - - assets/ + - assets/undraw/ + - assets/icon.png # An image asset can refer to one or more resolution-specific "variants", see # https://flutter.dev/assets-and-images/#resolution-aware