Added asset wrapper.

FIXES: Image paths on web
This commit is contained in:
Jakob Meier 2023-03-24 17:47:47 +01:00
parent 0235ec6a83
commit 09f7e4fdd1
No known key found for this signature in database
GPG key ID: 66BDC7E6A01A6152
4 changed files with 48 additions and 19 deletions

View file

@ -1,5 +1,6 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:localstore/localstore.dart'; import 'package:localstore/localstore.dart';
import 'package:outbag_app/tools/assets.dart';
class RoomVisibility { class RoomVisibility {
final int type; final int type;
@ -154,35 +155,50 @@ class RoomIcon {
// return image name // return image name
String get img { String get img {
String path = "";
switch (type.toLowerCase()) { switch (type.toLowerCase()) {
case 'love': case 'love':
return 'undraw/undraw_couple.svg'; path = 'undraw/undraw_couple.svg';
break;
case 'sports': case 'sports':
return 'undraw/undraw_greek_freak.svg'; path = 'undraw/undraw_greek_freak.svg';
break;
case 'pets': case 'pets':
return 'undraw/undraw_dog.svg'; path = 'undraw/undraw_dog.svg';
break;
case 'vacation': case 'vacation':
return 'undraw/undraw_trip.svg'; path = 'undraw/undraw_trip.svg';
break;
case 'gifts': case 'gifts':
return 'undraw/undraw_gifts.svg'; path = 'undraw/undraw_gifts.svg';
break;
case 'groceries': case 'groceries':
return 'undraw/undraw_gone_shopping.svg'; path = 'undraw/undraw_gone_shopping.svg';
break;
case 'fashion': case 'fashion':
return 'undraw/undraw_jewelry.svg'; path = 'undraw/undraw_jewelry.svg';
break;
case 'art': case 'art':
return 'undraw/undraw_sculpting.svg'; path = 'undraw/undraw_sculpting.svg';
break;
case 'tech': case 'tech':
return 'undraw/undraw_progressive_app.svg'; path = 'undraw/undraw_progressive_app.svg';
break;
case 'home': case 'home':
return 'undraw/undraw_under_construction.svg'; path = 'undraw/undraw_under_construction.svg';
break;
case 'family': case 'family':
return 'undraw/undraw_family.svg'; path = 'undraw/undraw_family.svg';
break;
case 'social': case 'social':
return 'undraw/undraw_pizza_sharing.svg'; path = 'undraw/undraw_pizza_sharing.svg';
break;
case 'other': case 'other':
default: default:
return 'undraw/undraw_file_manager.svg'; path = 'undraw/undraw_file_manager.svg';
} }
return asset(path);
} }
} }

View file

@ -1,4 +1,5 @@
import 'package:flutter/material.dart'; import 'package:flutter/material.dart';
import 'package:outbag_app/tools/assets.dart';
import 'package:routemaster/routemaster.dart'; import 'package:routemaster/routemaster.dart';
import 'package:flutter_svg/flutter_svg.dart'; import 'package:flutter_svg/flutter_svg.dart';
import 'dart:math'; import 'dart:math';
@ -60,7 +61,7 @@ class _WelcomePageState extends State<WelcomePage> {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[ children: <Widget>[
SvgPicture.asset("undraw/undraw_shopping_app.svg", SvgPicture.asset(asset("undraw/undraw_shopping_app.svg"),
fit: BoxFit.contain, fit: BoxFit.contain,
width: smallest*0.5, width: smallest*0.5,
height: smallest*0.5 height: smallest*0.5
@ -76,7 +77,7 @@ class _WelcomePageState extends State<WelcomePage> {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[ children: <Widget>[
SvgPicture.asset("undraw/undraw_mobile_login.svg", SvgPicture.asset(asset("undraw/undraw_mobile_login.svg"),
fit: BoxFit.contain, fit: BoxFit.contain,
width: smallest*0.5, width: smallest*0.5,
height: smallest*0.5), height: smallest*0.5),
@ -92,7 +93,7 @@ class _WelcomePageState extends State<WelcomePage> {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[ children: <Widget>[
SvgPicture.asset("undraw/undraw_online_connection.svg", SvgPicture.asset(asset("undraw/undraw_online_connection.svg"),
fit: BoxFit.contain, fit: BoxFit.contain,
width: smallest*0.5, width: smallest*0.5,
height: smallest*0.5), height: smallest*0.5),
@ -108,7 +109,7 @@ class _WelcomePageState extends State<WelcomePage> {
mainAxisAlignment: MainAxisAlignment.center, mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[ children: <Widget>[
SvgPicture.asset("undraw/undraw_online_groceries.svg", SvgPicture.asset(asset("undraw/undraw_online_groceries.svg"),
fit: BoxFit.contain, fit: BoxFit.contain,
width: smallest*0.5, width: smallest*0.5,
height: smallest*0.5), height: smallest*0.5),

11
lib/tools/assets.dart Normal file
View file

@ -0,0 +1,11 @@
import 'package:flutter/foundation.dart';
String asset(String pathInAssets) {
String prefix = "";
if (!kIsWeb || kReleaseMode) {
prefix = "assets/";
}
return '$prefix$pathInAssets';
}

View file

@ -47,7 +47,7 @@ dev_dependencies:
# package. See that file for information about deactivating specific lint # package. See that file for information about deactivating specific lint
# rules and activating additional ones. # rules and activating additional ones.
flutter_lints: ^2.0.0 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 # For information on the generic Dart part of this file, see the
# following page: https://dart.dev/tools/pub/pubspec # following page: https://dart.dev/tools/pub/pubspec
@ -65,7 +65,8 @@ flutter:
# - images/a_dot_burr.jpeg # - images/a_dot_burr.jpeg
# - images/a_dot_ham.jpeg # - images/a_dot_ham.jpeg
assets: assets:
- assets/ - assets/undraw/
- assets/icon.png
# An image asset can refer to one or more resolution-specific "variants", see # An image asset can refer to one or more resolution-specific "variants", see
# https://flutter.dev/assets-and-images/#resolution-aware # https://flutter.dev/assets-and-images/#resolution-aware