mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 13:36:50 +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:convert';
|
||||||
import 'dart:io';
|
import 'dart:io';
|
||||||
|
|
||||||
|
import 'package:flutter/material.dart';
|
||||||
|
import 'package:flutter_advanced_networkimage/provider.dart';
|
||||||
import 'package:image/image.dart';
|
import 'package:image/image.dart';
|
||||||
|
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
@ -287,4 +289,20 @@ class InvenTreeAPI {
|
|||||||
return "Basic " + base64Encode(utf8.encode('$_username:$_password'));
|
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'] ?? '';
|
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 {
|
String get image {
|
||||||
|
// Use thumbnail as a backup
|
||||||
String img = _image.isNotEmpty ? _image : _thumbnail;
|
String img = _image.isNotEmpty ? _image : _thumbnail;
|
||||||
|
|
||||||
if (img.isEmpty) {
|
return img.isNotEmpty ? img : InvenTreeAPI.staticImage;
|
||||||
return InvenTreeAPI().makeUrl('/static/img/blank_image.png');
|
|
||||||
} else {
|
|
||||||
return InvenTreeAPI().makeUrl(img);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Return a path to the thumbnail for this part
|
||||||
String get thumbnail {
|
String get thumbnail {
|
||||||
|
// Use image as a backup
|
||||||
String img = _thumbnail.isNotEmpty ? _thumbnail : _image;
|
String img = _thumbnail.isNotEmpty ? _thumbnail : _image;
|
||||||
|
|
||||||
if (img.isEmpty) {
|
return img.isNotEmpty ? img : InvenTreeAPI.staticThumb;
|
||||||
return InvenTreeAPI().makeUrl('/static/img/blank_image.thumbnail.png');
|
|
||||||
} else {
|
|
||||||
return InvenTreeAPI().makeUrl(img);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
InvenTreePart() : super();
|
InvenTreePart() : super();
|
||||||
|
@ -180,12 +180,7 @@ class PartList extends StatelessWidget {
|
|||||||
title: Text("${part.name}"),
|
title: Text("${part.name}"),
|
||||||
subtitle: Text("${part.description}"),
|
subtitle: Text("${part.description}"),
|
||||||
leading: Image(
|
leading: Image(
|
||||||
image: AdvancedNetworkImage(
|
image: InvenTreeAPI().getImage(part.thumbnail),
|
||||||
part.thumbnail,
|
|
||||||
header: InvenTreeAPI().defaultHeaders(),
|
|
||||||
useDiskCache: true,
|
|
||||||
cacheRule: CacheRule(maxAge: const Duration(days: 1)),
|
|
||||||
),
|
|
||||||
width: 48,
|
width: 48,
|
||||||
),
|
),
|
||||||
onTap: () {
|
onTap: () {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user