2
0
mirror of https://github.com/inventree/inventree-app.git synced 2025-04-27 21:16:48 +00:00

Display part thumbnail in part list

This commit is contained in:
Oliver Walters 2020-04-05 00:27:54 +11:00
parent 44a0c3e18d
commit 528215455d
7 changed files with 119 additions and 19 deletions

View File

@ -27,6 +27,10 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
android {
compileSdkVersion 28
packagingOptions {
exclude 'META-INF/proguard/androidx-annotations.pro'
}
lintOptions {
disable 'InvalidPackage'
}

View File

@ -211,7 +211,7 @@ class InvenTreeAPI {
Future<http.Response> patch(String url, {Map<String, String> body}) async {
var _url = makeApiUrl(url);
var _headers = _defaultHeaders();
var _headers = defaultHeaders();
var _body = Map<String, String>();
// Copy across provided data
@ -231,7 +231,7 @@ class InvenTreeAPI {
Future<http.Response> post(String url, {Map<String, String> body}) async {
var _url = makeApiUrl(url);
var _headers = _defaultHeaders();
var _headers = defaultHeaders();
var _body = Map<String, String>();
// Copy across provided data
@ -249,7 +249,7 @@ class InvenTreeAPI {
Future<http.Response> get(String url, {Map<String, String> params}) async {
var _url = makeApiUrl(url);
var _headers = _defaultHeaders();
var _headers = defaultHeaders();
// If query parameters are supplied, form a query string
if (params != null && params.isNotEmpty) {
@ -270,18 +270,21 @@ class InvenTreeAPI {
return http.get(_url, headers: _headers);
}
Map<String, String> _defaultHeaders() {
Map<String, String> defaultHeaders() {
var headers = Map<String, String>();
// Preference authentication token if available
if (_token.isNotEmpty) {
headers[HttpHeaders.authorizationHeader] = "Token " + _token;
} else {
headers[HttpHeaders.authorizationHeader] = 'Basic ' + base64Encode(utf8.encode('$_username:$_password'));
}
headers[HttpHeaders.authorizationHeader] = _authorizationHeader();
//headers['Authorization'] = _authorizationHeader();
return headers;
}
String _authorizationHeader () {
if (_token.isNotEmpty) {
return "Token $_token";
} else {
return "Basic " + base64Encode(utf8.encode('$_username:$_password'));
}
}
}

View File

View File

@ -1,7 +1,7 @@
import 'package:InvenTree/api.dart';
import 'model.dart';
import 'dart:convert';
import 'dart:io';
import 'package:path/path.dart' as path;
import 'package:http/http.dart' as http;
@ -38,6 +38,31 @@ class InvenTreePart extends InvenTreeModel {
String get categoryName => jsondata['category__name'] ?? '';
String get _image => jsondata['image'] ?? '';
String get _thumbnail => jsondata['thumbnail'] ?? '';
// Return a fully-qualified path to the image for this Part
String get image {
String img = _image.isNotEmpty ? _image : _thumbnail;
if (img.isEmpty) {
return InvenTreeAPI().makeUrl('/static/img/blank_image.png');
} else {
return InvenTreeAPI().makeUrl(img);
}
}
String get thumbnail {
String img = _thumbnail.isNotEmpty ? _thumbnail : _image;
if (img.isEmpty) {
return InvenTreeAPI().makeUrl('/static/img/blank_image.thumbnail.png');
} else {
return InvenTreeAPI().makeUrl(img);
}
}
InvenTreePart() : super();
InvenTreePart.fromJson(Map<String, dynamic> json) : super.fromJson(json) {
@ -50,6 +75,5 @@ class InvenTreePart extends InvenTreeModel {
var part = InvenTreePart.fromJson(json);
return part;
}
}

View File

@ -1,4 +1,5 @@
import 'package:InvenTree/api.dart';
import 'package:InvenTree/inventree/part.dart';
import 'package:InvenTree/widget/part_display.dart';
@ -8,6 +9,8 @@ import 'package:flutter/cupertino.dart';
import 'package:flutter/foundation.dart';
import 'package:flutter/material.dart';
import 'package:flutter_advanced_networkimage/provider.dart';
class CategoryDisplayWidget extends StatefulWidget {
CategoryDisplayWidget(this.category, {Key key}) : super(key: key);
@ -176,14 +179,15 @@ class PartList extends StatelessWidget {
return ListTile(
title: Text("${part.name}"),
subtitle: Text("${part.description}"),
/*
leading: CachedNetworkImage(
imageUrl: part.imageurl,
placeholder: (context, url) => CircularProgressIndicator(),
errorWidget: (context, url, error) => Icon(Icons.error),
leading: Image(
image: AdvancedNetworkImage(
part.thumbnail,
header: InvenTreeAPI().defaultHeaders(),
useDiskCache: true,
cacheRule: CacheRule(maxAge: const Duration(days: 1)),
),
width: 48,
),
*/
onTap: () {
_openPart(context, part.pk);
},

View File

@ -69,6 +69,13 @@ packages:
description: flutter
source: sdk
version: "0.0.0"
flutter_advanced_networkimage:
dependency: "direct main"
description:
name: flutter_advanced_networkimage
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.0"
flutter_launcher_icons:
dependency: "direct dev"
description:
@ -76,6 +83,13 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "0.7.4"
flutter_svg:
dependency: transitive
description:
name: flutter_svg
url: "https://pub.dartlang.org"
source: hosted
version: "0.17.3+1"
flutter_test:
dependency: "direct dev"
description: flutter
@ -135,6 +149,41 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.4"
path_drawing:
dependency: transitive
description:
name: path_drawing
url: "https://pub.dartlang.org"
source: hosted
version: "0.4.1"
path_parsing:
dependency: transitive
description:
name: path_parsing
url: "https://pub.dartlang.org"
source: hosted
version: "0.1.4"
path_provider:
dependency: transitive
description:
name: path_provider
url: "https://pub.dartlang.org"
source: hosted
version: "1.6.5"
path_provider_macos:
dependency: transitive
description:
name: path_provider_macos
url: "https://pub.dartlang.org"
source: hosted
version: "0.0.4"
path_provider_platform_interface:
dependency: transitive
description:
name: path_provider_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.1"
pedantic:
dependency: transitive
description:
@ -149,6 +198,20 @@ packages:
url: "https://pub.dartlang.org"
source: hosted
version: "2.4.0"
platform:
dependency: transitive
description:
name: platform
url: "https://pub.dartlang.org"
source: hosted
version: "2.2.1"
plugin_platform_interface:
dependency: transitive
description:
name: plugin_platform_interface
url: "https://pub.dartlang.org"
source: hosted
version: "1.0.2"
preferences:
dependency: "direct main"
description:

View File

@ -26,6 +26,8 @@ dependencies:
http: ^0.12.0+2
shared_preferences: ^0.5.3+1
flutter_advanced_networkimage: any
preferences: ^5.1.0
qr_utils: ^0.1.4