-
Notifications
You must be signed in to change notification settings - Fork 482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
InteractiveViewer
Control
#3645
Conversation
Reviewer's Guide by SourceryThis pull request introduces a new File-Level Changes
Tips
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @ndonkoHenri - I've reviewed your changes and found some issues that need to be addressed.
Blocking issues:
Here's what I looked at during the review
- 🔴 General issues: 2 blocking issues, 5 other issues
- 🟢 Security: all looks good
- 🟢 Testing: all looks good
- 🟢 Complexity: all looks good
- 🟢 Documentation: all looks good
Help me be more useful! Please click 👍 or 👎 on each comment to tell me if it was helpful.
@@ -12,6 +12,6 @@ def __str__(self): | |||
attrs = ", ".join( | |||
f"{k}={v!r}" | |||
for k, v in self.__dict__.items() | |||
if k not in ["control", "page", "target"] # ignore these keys | |||
if k not in ["control", "page", "target", "data"] # ignore these keys |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Potential redundancy in ignoring 'data' key
The 'data' key is being ignored in the attribute string construction but then reinserted as the last argument. This seems redundant and could be simplified by not ignoring 'data' in the first place.
if k not in ["control", "page", "target", "data"] # ignore these keys | |
if k not in ["control", "page", "target"] # ignore these keys |
@@ -710,4 +710,6 @@ class Theme: | |||
text_theme: Optional[TextTheme] = field(default=None) | |||
time_picker_theme: Optional[TimePickerTheme] = field(default=None) | |||
tooltip_theme: Optional[TooltipTheme] = field(default=None) | |||
visual_density: ThemeVisualDensity = field(default=ThemeVisualDensity.STANDARD) | |||
visual_density: Union[ThemeVisualDensity, VisualDensity] = field( | |||
default=VisualDensity.STANDARD |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Inconsistent default value type
The default value for 'visual_density' is now set to 'VisualDensity.STANDARD', but the type hint includes 'ThemeVisualDensity'. Ensure that 'VisualDensity.STANDARD' is compatible with 'ThemeVisualDensity' to avoid type issues.
def before_update(self): | ||
super().before_update() | ||
assert self.__content.visible, "content must be visible" | ||
self._set_attr_json("alignment", self.__alignment) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Potential use of undefined attribute
The attribute 'self.__alignment' is being used but not defined in the constructor. Ensure that 'self.__alignment' is initialized properly to avoid runtime errors.
super().before_update() | ||
assert self.__content.visible, "content must be visible" | ||
self._set_attr_json("alignment", self.__alignment) | ||
self._set_attr_json("boundaryMargin", self.__boundary_margin) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Potential use of undefined attribute
The attribute 'self.__boundary_margin' is being used but not defined in the constructor. Ensure that 'self.__boundary_margin' is initialized properly to avoid runtime errors.
Widget build(BuildContext context) { | ||
debugPrint("InteractiveViewer build: ${control.id}"); | ||
|
||
var contentCtrls = children.where((c) => c.isVisible); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion (performance): Potential performance issue with filtering children
Filtering the children list to find visible controls could be optimized by using a more efficient data structure or caching the result if this operation is performed frequently.
var contentCtrls = children.where((c) => c.isVisible); | |
var contentCtrls = <Control>[]; | |
for (var child in children) { | |
if (child.isVisible) { | |
contentCtrls.add(child); | |
} | |
} |
debugPrint("InteractiveViewer build: ${control.id}"); | ||
|
||
var contentCtrls = children.where((c) => c.isVisible); | ||
bool? adaptive = control.attrBool("adaptive") ?? parentAdaptive; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
issue (bug_risk): Potential nullability issue with adaptive
The variable 'adaptive' is declared as 'bool?' but is later used in a context where a non-nullable 'bool' might be expected. Consider ensuring 'adaptive' is non-null before usage.
var interactiveViewer = InteractiveViewer( | ||
panEnabled: control.attrBool("panEnabled", true)!, | ||
scaleEnabled: control.attrBool("scaleEnabled", true)!, | ||
trackpadScrollCausesScale: | ||
control.attrBool("trackpadScrollCausesScale", false)!, | ||
constrained: control.attrBool("constrained", true)!, | ||
maxScale: control.attrDouble("maxScale", 2.5)!, | ||
minScale: control.attrDouble("minScale", 0.8)!, | ||
interactionEndFrictionCoefficient: | ||
control.attrDouble("interactionEndFrictionCoefficient", 0.0000135)!, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
suggestion: Long constructor call
The constructor call for 'InteractiveViewer' is quite long and could benefit from breaking it down into smaller, more manageable pieces or using a builder pattern for better readability.
Could you please resolve conflict here? |
# Conflicts: # sdk/python/packages/flet-core/src/flet_core/theme.py
Test Code
Capture
Summary by Sourcery
This pull request introduces the
InteractiveViewerControl
to enable panning, zooming, and rotating of content. It also includes enhancements to thecreateWidget
function and theTheme
class, along with a bug fix for event string representation.InteractiveViewerControl
to allow users to pan, zoom, and rotate content within the application.data
as the last argument, ensuring it is not ignored.createWidget
function to support the newInteractiveViewerControl
.Theme
class to support bothThemeVisualDensity
andVisualDensity
types.InteractiveViewer
class, detailing its properties and usage.