mirror of
https://github.com/Mercantec-GHC/h4-projekt-gruppe-0-sm.git
synced 2025-04-28 00:34:06 +02:00
fix infinite loading for image painter
This commit is contained in:
parent
eafabc8afa
commit
e8c666412c
@ -1,5 +1,4 @@
|
|||||||
import 'dart:ui' as ui;
|
import 'dart:ui' as ui;
|
||||||
|
|
||||||
import 'package:flutter/material.dart';
|
import 'package:flutter/material.dart';
|
||||||
import 'package:mobile/repos/location_image.dart';
|
import 'package:mobile/repos/location_image.dart';
|
||||||
import 'package:mobile/repos/product.dart';
|
import 'package:mobile/repos/product.dart';
|
||||||
@ -21,7 +20,6 @@ class ProductLocationPage extends StatelessWidget {
|
|||||||
],
|
],
|
||||||
),
|
),
|
||||||
Consumer<LocationImageRepo>(builder: (context, locationImage, child) {
|
Consumer<LocationImageRepo>(builder: (context, locationImage, child) {
|
||||||
locationImage.load();
|
|
||||||
if (locationImage.image == null) {
|
if (locationImage.image == null) {
|
||||||
return const CircularProgressIndicator(
|
return const CircularProgressIndicator(
|
||||||
color: Colors.blue,
|
color: Colors.blue,
|
||||||
@ -35,7 +33,6 @@ class ProductLocationPage extends StatelessWidget {
|
|||||||
double parentWidth = constraints.maxWidth;
|
double parentWidth = constraints.maxWidth;
|
||||||
|
|
||||||
final image = locationImage.image!;
|
final image = locationImage.image!;
|
||||||
// Maintain aspect ratio
|
|
||||||
double imageWidth = image.width.toDouble();
|
double imageWidth = image.width.toDouble();
|
||||||
double imageHeight = image.height.toDouble();
|
double imageHeight = image.height.toDouble();
|
||||||
double scale = (parentWidth / imageWidth).clamp(0.0, 1.0);
|
double scale = (parentWidth / imageWidth).clamp(0.0, 1.0);
|
||||||
@ -71,10 +68,14 @@ class LocationImagePainter extends CustomPainter {
|
|||||||
|
|
||||||
canvas.drawImage(image, const Offset(0, 0), paint);
|
canvas.drawImage(image, const Offset(0, 0), paint);
|
||||||
|
|
||||||
Paint circlePaint = Paint()..color = Colors.red;
|
Paint circlePaint = Paint();
|
||||||
|
circlePaint.color = Colors.red;
|
||||||
|
|
||||||
canvas.drawCircle(Offset(location.x, location.y), 50, circlePaint);
|
canvas.drawCircle(Offset(location.x, location.y), 50, circlePaint);
|
||||||
}
|
}
|
||||||
|
|
||||||
@override
|
@override
|
||||||
bool shouldRepaint(covariant CustomPainter oldDelegate) => true;
|
bool shouldRepaint(covariant LocationImagePainter oldDelegate) {
|
||||||
|
return oldDelegate.image != image || oldDelegate.scale != scale;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -6,6 +6,10 @@ import 'package:flutter/services.dart';
|
|||||||
class LocationImageRepo extends ChangeNotifier {
|
class LocationImageRepo extends ChangeNotifier {
|
||||||
ui.Image? image;
|
ui.Image? image;
|
||||||
|
|
||||||
|
LocationImageRepo() {
|
||||||
|
load();
|
||||||
|
}
|
||||||
|
|
||||||
Future<void> load() async {
|
Future<void> load() async {
|
||||||
final ByteData data = await rootBundle.load('assets/floor_plan.png');
|
final ByteData data = await rootBundle.load('assets/floor_plan.png');
|
||||||
final Uint8List list = data.buffer.asUint8List();
|
final Uint8List list = data.buffer.asUint8List();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user