mirror of
https://github.com/inventree/inventree-app.git
synced 2025-04-28 05:26:47 +00:00
Display part thumbnail in part list
This commit is contained in:
parent
44a0c3e18d
commit
528215455d
@ -27,6 +27,10 @@ apply from: "$flutterRoot/packages/flutter_tools/gradle/flutter.gradle"
|
|||||||
android {
|
android {
|
||||||
compileSdkVersion 28
|
compileSdkVersion 28
|
||||||
|
|
||||||
|
packagingOptions {
|
||||||
|
exclude 'META-INF/proguard/androidx-annotations.pro'
|
||||||
|
}
|
||||||
|
|
||||||
lintOptions {
|
lintOptions {
|
||||||
disable 'InvalidPackage'
|
disable 'InvalidPackage'
|
||||||
}
|
}
|
||||||
|
23
lib/api.dart
23
lib/api.dart
@ -211,7 +211,7 @@ class InvenTreeAPI {
|
|||||||
Future<http.Response> patch(String url, {Map<String, String> body}) async {
|
Future<http.Response> patch(String url, {Map<String, String> body}) async {
|
||||||
|
|
||||||
var _url = makeApiUrl(url);
|
var _url = makeApiUrl(url);
|
||||||
var _headers = _defaultHeaders();
|
var _headers = defaultHeaders();
|
||||||
var _body = Map<String, String>();
|
var _body = Map<String, String>();
|
||||||
|
|
||||||
// Copy across provided data
|
// Copy across provided data
|
||||||
@ -231,7 +231,7 @@ class InvenTreeAPI {
|
|||||||
Future<http.Response> post(String url, {Map<String, String> body}) async {
|
Future<http.Response> post(String url, {Map<String, String> body}) async {
|
||||||
|
|
||||||
var _url = makeApiUrl(url);
|
var _url = makeApiUrl(url);
|
||||||
var _headers = _defaultHeaders();
|
var _headers = defaultHeaders();
|
||||||
var _body = Map<String, String>();
|
var _body = Map<String, String>();
|
||||||
|
|
||||||
// Copy across provided data
|
// Copy across provided data
|
||||||
@ -249,7 +249,7 @@ class InvenTreeAPI {
|
|||||||
Future<http.Response> get(String url, {Map<String, String> params}) async {
|
Future<http.Response> get(String url, {Map<String, String> params}) async {
|
||||||
|
|
||||||
var _url = makeApiUrl(url);
|
var _url = makeApiUrl(url);
|
||||||
var _headers = _defaultHeaders();
|
var _headers = defaultHeaders();
|
||||||
|
|
||||||
// If query parameters are supplied, form a query string
|
// If query parameters are supplied, form a query string
|
||||||
if (params != null && params.isNotEmpty) {
|
if (params != null && params.isNotEmpty) {
|
||||||
@ -270,18 +270,21 @@ class InvenTreeAPI {
|
|||||||
return http.get(_url, headers: _headers);
|
return http.get(_url, headers: _headers);
|
||||||
}
|
}
|
||||||
|
|
||||||
Map<String, String> _defaultHeaders() {
|
Map<String, String> defaultHeaders() {
|
||||||
|
|
||||||
var headers = Map<String, String>();
|
var headers = Map<String, String>();
|
||||||
|
|
||||||
// Preference authentication token if available
|
headers[HttpHeaders.authorizationHeader] = _authorizationHeader();
|
||||||
if (_token.isNotEmpty) {
|
//headers['Authorization'] = _authorizationHeader();
|
||||||
headers[HttpHeaders.authorizationHeader] = "Token " + _token;
|
|
||||||
} else {
|
|
||||||
headers[HttpHeaders.authorizationHeader] = 'Basic ' + base64Encode(utf8.encode('$_username:$_password'));
|
|
||||||
}
|
|
||||||
|
|
||||||
return headers;
|
return headers;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
String _authorizationHeader () {
|
||||||
|
if (_token.isNotEmpty) {
|
||||||
|
return "Token $_token";
|
||||||
|
} else {
|
||||||
|
return "Basic " + base64Encode(utf8.encode('$_username:$_password'));
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
@ -1,7 +1,7 @@
|
|||||||
import 'package:InvenTree/api.dart';
|
import 'package:InvenTree/api.dart';
|
||||||
|
|
||||||
import 'model.dart';
|
import 'model.dart';
|
||||||
import 'dart:convert';
|
import 'dart:io';
|
||||||
|
|
||||||
import 'package:path/path.dart' as path;
|
import 'package:path/path.dart' as path;
|
||||||
import 'package:http/http.dart' as http;
|
import 'package:http/http.dart' as http;
|
||||||
@ -38,6 +38,31 @@ class InvenTreePart extends InvenTreeModel {
|
|||||||
|
|
||||||
String get categoryName => jsondata['category__name'] ?? '';
|
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() : super();
|
||||||
|
|
||||||
InvenTreePart.fromJson(Map<String, dynamic> json) : super.fromJson(json) {
|
InvenTreePart.fromJson(Map<String, dynamic> json) : super.fromJson(json) {
|
||||||
@ -50,6 +75,5 @@ class InvenTreePart extends InvenTreeModel {
|
|||||||
var part = InvenTreePart.fromJson(json);
|
var part = InvenTreePart.fromJson(json);
|
||||||
|
|
||||||
return part;
|
return part;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -1,4 +1,5 @@
|
|||||||
|
|
||||||
|
import 'package:InvenTree/api.dart';
|
||||||
import 'package:InvenTree/inventree/part.dart';
|
import 'package:InvenTree/inventree/part.dart';
|
||||||
|
|
||||||
import 'package:InvenTree/widget/part_display.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/foundation.dart';
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
|
|
||||||
|
import 'package:flutter_advanced_networkimage/provider.dart';
|
||||||
|
|
||||||
class CategoryDisplayWidget extends StatefulWidget {
|
class CategoryDisplayWidget extends StatefulWidget {
|
||||||
|
|
||||||
CategoryDisplayWidget(this.category, {Key key}) : super(key: key);
|
CategoryDisplayWidget(this.category, {Key key}) : super(key: key);
|
||||||
@ -176,14 +179,15 @@ class PartList extends StatelessWidget {
|
|||||||
return ListTile(
|
return ListTile(
|
||||||
title: Text("${part.name}"),
|
title: Text("${part.name}"),
|
||||||
subtitle: Text("${part.description}"),
|
subtitle: Text("${part.description}"),
|
||||||
|
leading: Image(
|
||||||
/*
|
image: AdvancedNetworkImage(
|
||||||
leading: CachedNetworkImage(
|
part.thumbnail,
|
||||||
imageUrl: part.imageurl,
|
header: InvenTreeAPI().defaultHeaders(),
|
||||||
placeholder: (context, url) => CircularProgressIndicator(),
|
useDiskCache: true,
|
||||||
errorWidget: (context, url, error) => Icon(Icons.error),
|
cacheRule: CacheRule(maxAge: const Duration(days: 1)),
|
||||||
|
),
|
||||||
|
width: 48,
|
||||||
),
|
),
|
||||||
*/
|
|
||||||
onTap: () {
|
onTap: () {
|
||||||
_openPart(context, part.pk);
|
_openPart(context, part.pk);
|
||||||
},
|
},
|
||||||
|
63
pubspec.lock
63
pubspec.lock
@ -69,6 +69,13 @@ packages:
|
|||||||
description: flutter
|
description: flutter
|
||||||
source: sdk
|
source: sdk
|
||||||
version: "0.0.0"
|
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:
|
flutter_launcher_icons:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description:
|
description:
|
||||||
@ -76,6 +83,13 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "0.7.4"
|
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:
|
flutter_test:
|
||||||
dependency: "direct dev"
|
dependency: "direct dev"
|
||||||
description: flutter
|
description: flutter
|
||||||
@ -135,6 +149,41 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "1.6.4"
|
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:
|
pedantic:
|
||||||
dependency: transitive
|
dependency: transitive
|
||||||
description:
|
description:
|
||||||
@ -149,6 +198,20 @@ packages:
|
|||||||
url: "https://pub.dartlang.org"
|
url: "https://pub.dartlang.org"
|
||||||
source: hosted
|
source: hosted
|
||||||
version: "2.4.0"
|
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:
|
preferences:
|
||||||
dependency: "direct main"
|
dependency: "direct main"
|
||||||
description:
|
description:
|
||||||
|
@ -26,6 +26,8 @@ dependencies:
|
|||||||
http: ^0.12.0+2
|
http: ^0.12.0+2
|
||||||
shared_preferences: ^0.5.3+1
|
shared_preferences: ^0.5.3+1
|
||||||
|
|
||||||
|
flutter_advanced_networkimage: any
|
||||||
|
|
||||||
preferences: ^5.1.0
|
preferences: ^5.1.0
|
||||||
|
|
||||||
qr_utils: ^0.1.4
|
qr_utils: ^0.1.4
|
||||||
|
Loading…
x
Reference in New Issue
Block a user