From 882f7ddcb10888578f6436c0846aef8e0ac3c763 Mon Sep 17 00:00:00 2001 From: longer96 Date: Mon, 16 Aug 2021 17:13:21 +0800 Subject: [PATCH 1/2] Update color_sucker.dart [fix]:ColorSucker move off screen bug --- .../components/color_sucker/color_sucker.dart | 20 ++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/kits/flutter_ume_kit_ui/lib/components/color_sucker/color_sucker.dart b/kits/flutter_ume_kit_ui/lib/components/color_sucker/color_sucker.dart index fc720c8f..375e814a 100644 --- a/kits/flutter_ume_kit_ui/lib/components/color_sucker/color_sucker.dart +++ b/kits/flutter_ume_kit_ui/lib/components/color_sucker/color_sucker.dart @@ -75,21 +75,35 @@ class _ColorSuckerState extends State { } void _onPanUpdate(DragUpdateDetails dragDetails) { - _magnifierPosition = - dragDetails.globalPosition - _magnifierSize.center(Offset.zero); double newX = dragDetails.globalPosition.dx; double newY = dragDetails.globalPosition.dy; + if (newX + (_magnifierSize.width / 2) < 0) { + newX = 0; + } else if (newX >= _windowSize.width) { + newX = _windowSize.width - 1; + } + + if (newY + (_magnifierSize.height / 2) < 0) { + newY = 0; + } else if (newY + (_magnifierSize.height / 2) > _windowSize.height) { + newY = _windowSize.height - 1; + } + + _magnifierPosition = + Offset(newX, newY) - _magnifierSize.center(Offset.zero); + final Matrix4 newMatrix = Matrix4.identity() ..translate(newX, newY) ..scale(_scale, _scale) ..translate(-newX, -newY); _matrix = newMatrix; - _searchPixel(dragDetails.globalPosition); + _searchPixel(Offset(newX, newY)); setState(() {}); } void _toolBarPanUpdate(DragUpdateDetails dragDetails) { _toolBarY = dragDetails.globalPosition.dy - 40; + if (_toolBarY <= 0) _toolBarY = 0; setState(() {}); } From 2870cca2b22f52ee5f2d3e8dbaaea7d4fd0fd25f Mon Sep 17 00:00:00 2001 From: longer Date: Mon, 16 Aug 2021 22:54:15 +0800 Subject: [PATCH 2/2] [fix]:ColorSucker move off screen bug --- .../lib/components/color_sucker/color_sucker.dart | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/kits/flutter_ume_kit_ui/lib/components/color_sucker/color_sucker.dart b/kits/flutter_ume_kit_ui/lib/components/color_sucker/color_sucker.dart index 375e814a..1bced20a 100644 --- a/kits/flutter_ume_kit_ui/lib/components/color_sucker/color_sucker.dart +++ b/kits/flutter_ume_kit_ui/lib/components/color_sucker/color_sucker.dart @@ -1,4 +1,5 @@ import 'dart:convert'; +import 'dart:math'; import 'dart:typed_data'; import 'dart:ui' as ui; import 'package:flutter/material.dart'; @@ -85,7 +86,7 @@ class _ColorSuckerState extends State { if (newY + (_magnifierSize.height / 2) < 0) { newY = 0; - } else if (newY + (_magnifierSize.height / 2) > _windowSize.height) { + } else if (newY >= _windowSize.height) { newY = _windowSize.height - 1; } @@ -103,7 +104,7 @@ class _ColorSuckerState extends State { void _toolBarPanUpdate(DragUpdateDetails dragDetails) { _toolBarY = dragDetails.globalPosition.dy - 40; - if (_toolBarY <= 0) _toolBarY = 0; + _toolBarY = max(0, _toolBarY); setState(() {}); }