mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 05:26:47 +00:00
Driving the refactor tractor
- InvenTreeAPI() object now has a method to return a cache-backed image from the server
This commit is contained in:
parent
528215455d
commit
cd4731833d
18
lib/api.dart
18
lib/api.dart
@ -2,6 +2,8 @@ import 'dart:async';
|
||||
import 'dart:convert';
|
||||
import 'dart:io';
|
||||
|
||||
import 'package:flutter/material.dart';
|
||||
import 'package:flutter_advanced_networkimage/provider.dart';
|
||||
import 'package:image/image.dart';
|
||||
|
||||
import 'package:path/path.dart' as path;
|
||||
@ -287,4 +289,20 @@ class InvenTreeAPI {
|
||||
return "Basic " + base64Encode(utf8.encode('$_username:$_password'));
|
||||
}
|
||||
}
|
||||
|
||||
static String get staticImage => "/static/img/blank_image.png";
|
||||
|
||||
static String get staticThumb => "/static/img/blank_image.thumbnail.png";
|
||||
|
||||
/*
|
||||
* Get an image from the server (or, from cache)
|
||||
*/
|
||||
AdvancedNetworkImage getImage(String imageUrl) {
|
||||
|
||||
return new AdvancedNetworkImage(makeUrl(imageUrl),
|
||||
header: defaultHeaders(),
|
||||
useDiskCache: true,
|
||||
cacheRule: CacheRule(maxAge: const Duration(days: 5)),
|
||||
);
|
||||
}
|
||||
}
|
@ -42,25 +42,20 @@ class InvenTreePart extends InvenTreeModel {
|
||||
|
||||
String get _thumbnail => jsondata['thumbnail'] ?? '';
|
||||
|
||||
// Return a fully-qualified path to the image for this Part
|
||||
// Return a path to the image for this Part
|
||||
String get image {
|
||||
// Use thumbnail as a backup
|
||||
String img = _image.isNotEmpty ? _image : _thumbnail;
|
||||
|
||||
if (img.isEmpty) {
|
||||
return InvenTreeAPI().makeUrl('/static/img/blank_image.png');
|
||||
} else {
|
||||
return InvenTreeAPI().makeUrl(img);
|
||||
}
|
||||
return img.isNotEmpty ? img : InvenTreeAPI.staticImage;
|
||||
}
|
||||
|
||||
// Return a path to the thumbnail for this part
|
||||
String get thumbnail {
|
||||
// Use image as a backup
|
||||
String img = _thumbnail.isNotEmpty ? _thumbnail : _image;
|
||||
|
||||
if (img.isEmpty) {
|
||||
return InvenTreeAPI().makeUrl('/static/img/blank_image.thumbnail.png');
|
||||
} else {
|
||||
return InvenTreeAPI().makeUrl(img);
|
||||
}
|
||||
return img.isNotEmpty ? img : InvenTreeAPI.staticThumb;
|
||||
}
|
||||
|
||||
InvenTreePart() : super();
|
||||
|
@ -180,12 +180,7 @@ class PartList extends StatelessWidget {
|
||||
title: Text("${part.name}"),
|
||||
subtitle: Text("${part.description}"),
|
||||
leading: Image(
|
||||
image: AdvancedNetworkImage(
|
||||
part.thumbnail,
|
||||
header: InvenTreeAPI().defaultHeaders(),
|
||||
useDiskCache: true,
|
||||
cacheRule: CacheRule(maxAge: const Duration(days: 1)),
|
||||
),
|
||||
image: InvenTreeAPI().getImage(part.thumbnail),
|
||||
width: 48,
|
||||
),
|
||||
onTap: () {
|
||||
|
Loading…
x
Reference in New Issue
Block a user