Fix for logo CORS issue

This commit is contained in:
Hillel Coren 2023-09-12 12:55:54 +03:00
parent c36411668e
commit 516a7c1476
3 changed files with 15 additions and 2 deletions

View File

@ -87,7 +87,9 @@ class _MenuDrawerState extends State<MenuDrawer> {
company.settings.companyLogo.isNotEmpty company.settings.companyLogo.isNotEmpty
? CachedImage( ? CachedImage(
width: MenuDrawer.LOGO_WIDTH, width: MenuDrawer.LOGO_WIDTH,
//url: state.credentials.url + '/companies/' + company.id + '/logo',
url: company.settings.companyLogo, url: company.settings.companyLogo,
sendApiToken: true,
) )
: Image.asset('assets/images/icon.png', width: MenuDrawer.LOGO_WIDTH); : Image.asset('assets/images/icon.png', width: MenuDrawer.LOGO_WIDTH);

View File

@ -10,13 +10,19 @@ import 'package:flutter_redux/flutter_redux.dart';
import 'package:invoiceninja_flutter/redux/app/app_state.dart'; import 'package:invoiceninja_flutter/redux/app/app_state.dart';
class CachedImage extends StatelessWidget { class CachedImage extends StatelessWidget {
const CachedImage( const CachedImage({
{this.url, this.width, this.height, this.showNinjaOnError = true}); this.url,
this.width,
this.height,
this.showNinjaOnError = true,
this.sendApiToken = false,
});
final String url; final String url;
final bool showNinjaOnError; final bool showNinjaOnError;
final double width; final double width;
final double height; final double height;
final bool sendApiToken;
@override @override
Widget build(BuildContext context) { Widget build(BuildContext context) {
@ -39,6 +45,7 @@ class CachedImage extends StatelessWidget {
height: height, height: height,
key: ValueKey(url), key: ValueKey(url),
fit: BoxFit.contain, fit: BoxFit.contain,
headers: sendApiToken ? {'X-API-TOKEN': state.credentials.token} : null,
); );
} }
@ -50,6 +57,8 @@ class CachedImage extends StatelessWidget {
placeholder: (context, url) => Center(child: CircularProgressIndicator()), placeholder: (context, url) => Center(child: CircularProgressIndicator()),
errorWidget: (context, url, Object error) => errorWidget: (context, url, Object error) =>
Image.asset('assets/images/icon.png', width: 32, height: 30), Image.asset('assets/images/icon.png', width: 32, height: 30),
httpHeaders:
sendApiToken ? {'X-API-TOKEN': state.credentials.token} : null,
); );
} }
} }

View File

@ -574,7 +574,9 @@ class _CompanyDetailsState extends State<CompanyDetails>
padding: const EdgeInsets.symmetric(vertical: 20), padding: const EdgeInsets.symmetric(vertical: 20),
child: CachedImage( child: CachedImage(
width: double.infinity, width: double.infinity,
//url: state.credentials.url + '/companies/' + company.id + '/logo',
url: settings.companyLogo, url: settings.companyLogo,
sendApiToken: true,
)), )),
], ],
), ),