diff --git a/mobile/lib/pages/product_location_page.dart b/mobile/lib/pages/product_location_page.dart index b838c1c..777071c 100644 --- a/mobile/lib/pages/product_location_page.dart +++ b/mobile/lib/pages/product_location_page.dart @@ -1,5 +1,4 @@ import 'dart:ui' as ui; - import 'package:flutter/material.dart'; import 'package:mobile/repos/location_image.dart'; import 'package:mobile/repos/product.dart'; @@ -21,7 +20,6 @@ class ProductLocationPage extends StatelessWidget { ], ), Consumer(builder: (context, locationImage, child) { - locationImage.load(); if (locationImage.image == null) { return const CircularProgressIndicator( color: Colors.blue, @@ -35,7 +33,6 @@ class ProductLocationPage extends StatelessWidget { double parentWidth = constraints.maxWidth; final image = locationImage.image!; - // Maintain aspect ratio double imageWidth = image.width.toDouble(); double imageHeight = image.height.toDouble(); 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); - Paint circlePaint = Paint()..color = Colors.red; + Paint circlePaint = Paint(); + circlePaint.color = Colors.red; + canvas.drawCircle(Offset(location.x, location.y), 50, circlePaint); } @override - bool shouldRepaint(covariant CustomPainter oldDelegate) => true; + bool shouldRepaint(covariant LocationImagePainter oldDelegate) { + return oldDelegate.image != image || oldDelegate.scale != scale; + } } diff --git a/mobile/lib/repos/location_image.dart b/mobile/lib/repos/location_image.dart index 9a1113b..19bc1d1 100644 --- a/mobile/lib/repos/location_image.dart +++ b/mobile/lib/repos/location_image.dart @@ -6,6 +6,10 @@ import 'package:flutter/services.dart'; class LocationImageRepo extends ChangeNotifier { ui.Image? image; + LocationImageRepo() { + load(); + } + Future load() async { final ByteData data = await rootBundle.load('assets/floor_plan.png'); final Uint8List list = data.buffer.asUint8List();