Skip to content

Commit d81f1dc

Browse files
committed
## 1.3.0
* Features: Support zoom with mouse wheel.
1 parent fc44c92 commit d81f1dc

10 files changed

Lines changed: 259 additions & 14 deletions

‎.gitignore‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,8 @@ pubspec.lock
1010

1111
example/pubspec.lock
1212

13+
example/.packages
14+
1315
.flutter-plugins
1416

1517
flutter_export_environment.sh

‎CHANGELOG.md‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
## 1.3.0
2+
3+
* Features:
4+
Support zoom with mouse wheel.
5+
16
## 1.2.0
27

38
* Features:

‎README-ZH.md‎

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -986,7 +986,3 @@ ExtendedImage
986986
| enableMemoryCache | 是否缓存到内存 | true |
987987
| clearMemoryCacheIfFailed | 如果图片加载失败,是否清掉内存缓存 | true |
988988
| clearMemoryCacheWhenDispose | 如果图片从 tree 中移除,是否清掉内存缓存 | false |
989-
990-
## ☕️Buy me a coffee
991-
992-
![img](http://zmtzawqlp.gitee.io/my_images/images/qrcode.png)

‎example/analysis_options.yaml‎

Lines changed: 207 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,207 @@
1+
# Specify analysis options.
2+
#
3+
# Until there are meta linter rules, each desired lint must be explicitly enabled.
4+
# See: https://github.com/dart-lang/linter/issues/288
5+
#
6+
# For a list of lints, see: http://dart-lang.github.io/linter/lints/
7+
# See the configuration guide for more
8+
# https://github.com/dart-lang/sdk/tree/master/pkg/analyzer#configuring-the-analyzer
9+
#
10+
# There are other similar analysis options files in the flutter repos,
11+
# which should be kept in sync with this file:
12+
#
13+
# - analysis_options.yaml (this file)
14+
# - packages/flutter/lib/analysis_options_user.yaml
15+
# - https://github.com/flutter/plugins/blob/master/analysis_options.yaml
16+
# - https://github.com/flutter/engine/blob/master/analysis_options.yaml
17+
#
18+
# This file contains the analysis options used by Flutter tools, such as IntelliJ,
19+
# Android Studio, and the `flutter analyze` command.
20+
21+
analyzer:
22+
strong-mode:
23+
implicit-casts: false
24+
implicit-dynamic: false
25+
errors:
26+
# treat missing required parameters as a warning (not a hint)
27+
missing_required_param: warning
28+
# treat missing returns as a warning (not a hint)
29+
missing_return: warning
30+
# allow having TODOs in the code
31+
todo: ignore
32+
# Ignore analyzer hints for updating pubspecs when using Future or
33+
# Stream and not importing dart:async
34+
# Please see https://github.com/flutter/flutter/pull/24528 for details.
35+
sdk_version_async_exported_from_core: ignore
36+
exclude:
37+
- "lib/common/data/mock_data.dart"
38+
# # the following two are relative to the stocks example and the flutter package respectively
39+
# # see https://github.com/dart-lang/sdk/issues/28463
40+
# - "lib/i18n/messages_*.dart"
41+
# - "lib/src/http/**"
42+
43+
linter:
44+
rules:
45+
# these rules are documented on and in the same order as
46+
# the Dart Lint rules page to make maintenance easier
47+
# https://github.com/dart-lang/linter/blob/master/example/all.yaml
48+
- always_declare_return_types
49+
- always_put_control_body_on_new_line
50+
# - always_put_required_named_parameters_first # we prefer having parameters in the same order as fields https://github.com/flutter/flutter/issues/10219
51+
- always_require_non_null_named_parameters
52+
- always_specify_types
53+
- annotate_overrides
54+
# - avoid_annotating_with_dynamic # conflicts with always_specify_types
55+
# - avoid_as # required for implicit-casts: true
56+
- avoid_bool_literals_in_conditional_expressions
57+
# - avoid_catches_without_on_clauses # we do this commonly
58+
# - avoid_catching_errors # we do this commonly
59+
- avoid_classes_with_only_static_members
60+
# - avoid_double_and_int_checks # only useful when targeting JS runtime
61+
- avoid_empty_else
62+
# - avoid_equals_and_hash_code_on_mutable_classes # not yet tested
63+
- avoid_field_initializers_in_const_classes
64+
- avoid_function_literals_in_foreach_calls
65+
# - avoid_implementing_value_types # not yet tested
66+
- avoid_init_to_null
67+
# - avoid_js_rounded_ints # only useful when targeting JS runtime
68+
- avoid_null_checks_in_equality_operators
69+
# - avoid_positional_boolean_parameters # not yet tested
70+
# - avoid_print # not yet tested
71+
# - avoid_private_typedef_functions # we prefer having typedef (discussion in https://github.com/flutter/flutter/pull/16356)
72+
# - avoid_redundant_argument_values # not yet tested
73+
- avoid_relative_lib_imports
74+
- avoid_renaming_method_parameters
75+
- avoid_return_types_on_setters
76+
# - avoid_returning_null # there are plenty of valid reasons to return null
77+
# - avoid_returning_null_for_future # not yet tested
78+
- avoid_returning_null_for_void
79+
# - avoid_returning_this # there are plenty of valid reasons to return this
80+
# - avoid_setters_without_getters # not yet tested
81+
# - avoid_shadowing_type_parameters # not yet tested
82+
- avoid_single_cascade_in_expression_statements
83+
- avoid_slow_async_io
84+
- avoid_types_as_parameter_names
85+
# - avoid_types_on_closure_parameters # conflicts with always_specify_types
86+
# - avoid_unnecessary_containers # not yet tested
87+
- avoid_unused_constructor_parameters
88+
- avoid_void_async
89+
# - avoid_web_libraries_in_flutter # not yet tested
90+
- await_only_futures
91+
- camel_case_extensions
92+
- camel_case_types
93+
- cancel_subscriptions
94+
# - cascade_invocations # not yet tested
95+
# - close_sinks # not reliable enough
96+
# - comment_references # blocked on https://github.com/flutter/flutter/issues/20765
97+
# - constant_identifier_names # needs an opt-out https://github.com/dart-lang/linter/issues/204
98+
- control_flow_in_finally
99+
# - curly_braces_in_flow_control_structures # not yet tested
100+
# - diagnostic_describe_all_properties # not yet tested
101+
- directives_ordering
102+
- empty_catches
103+
- empty_constructor_bodies
104+
- empty_statements
105+
# - file_names # not yet tested
106+
- flutter_style_todos
107+
- hash_and_equals
108+
- implementation_imports
109+
# - invariant_booleans # too many false positives: https://github.com/dart-lang/linter/issues/811
110+
- iterable_contains_unrelated_type
111+
# - join_return_with_assignment # not yet tested
112+
- library_names
113+
- library_prefixes
114+
# - lines_longer_than_80_chars # not yet tested
115+
- list_remove_unrelated_type
116+
# - literal_only_boolean_expressions # too many false positives: https://github.com/dart-lang/sdk/issues/34181
117+
# - missing_whitespace_between_adjacent_strings # not yet tested
118+
- no_adjacent_strings_in_list
119+
- no_duplicate_case_values
120+
# - no_logic_in_create_state # not yet tested
121+
# - no_runtimeType_toString # not yet tested
122+
- non_constant_identifier_names
123+
# - null_closures # not yet tested
124+
# - omit_local_variable_types # opposite of always_specify_types
125+
# - one_member_abstracts # too many false positives
126+
# - only_throw_errors # https://github.com/flutter/flutter/issues/5792
127+
- overridden_fields
128+
- package_api_docs
129+
- package_names
130+
- package_prefixed_library_names
131+
# - parameter_assignments # we do this commonly
132+
- prefer_adjacent_string_concatenation
133+
- prefer_asserts_in_initializer_lists
134+
# - prefer_asserts_with_message # not yet tested
135+
- prefer_collection_literals
136+
- prefer_conditional_assignment
137+
- prefer_const_constructors
138+
- prefer_const_constructors_in_immutables
139+
- prefer_const_declarations
140+
- prefer_const_literals_to_create_immutables
141+
# - prefer_constructors_over_static_methods # not yet tested
142+
- prefer_contains
143+
# - prefer_double_quotes # opposite of prefer_single_quotes
144+
- prefer_equal_for_default_values
145+
# - prefer_expression_function_bodies # conflicts with https://github.com/flutter/flutter/wiki/Style-guide-for-Flutter-repo#consider-using--for-short-functions-and-methods
146+
- prefer_final_fields
147+
- prefer_final_in_for_each
148+
- prefer_final_locals
149+
- prefer_for_elements_to_map_fromIterable
150+
- prefer_foreach
151+
# - prefer_function_declarations_over_variables # not yet tested
152+
- prefer_generic_function_type_aliases
153+
- prefer_if_elements_to_conditional_expressions
154+
- prefer_if_null_operators
155+
- prefer_initializing_formals
156+
- prefer_inlined_adds
157+
# - prefer_int_literals # not yet tested
158+
# - prefer_interpolation_to_compose_strings # not yet tested
159+
- prefer_is_empty
160+
- prefer_is_not_empty
161+
- prefer_is_not_operator
162+
- prefer_iterable_whereType
163+
# - prefer_mixin # https://github.com/dart-lang/language/issues/32
164+
# - prefer_null_aware_operators # disable until NNBD, see https://github.com/flutter/flutter/pull/32711#issuecomment-492930932
165+
# - prefer_relative_imports # not yet tested
166+
- prefer_single_quotes
167+
- prefer_spread_collections
168+
- prefer_typing_uninitialized_variables
169+
- prefer_void_to_null
170+
# - provide_deprecation_message # not yet tested
171+
# - public_member_api_docs # enabled on a case-by-case basis; see e.g. packages/analysis_options.yaml
172+
- recursive_getters
173+
- slash_for_doc_comments
174+
# - sort_child_properties_last # not yet tested
175+
- sort_constructors_first
176+
- sort_pub_dependencies
177+
- sort_unnamed_constructors_first
178+
- test_types_in_equals
179+
- throw_in_finally
180+
# - type_annotate_public_apis # subset of always_specify_types
181+
- type_init_formals
182+
# - unawaited_futures # too many false positives
183+
# - unnecessary_await_in_return # not yet tested
184+
- unnecessary_brace_in_string_interps
185+
- unnecessary_const
186+
# - unnecessary_final # conflicts with prefer_final_locals
187+
- unnecessary_getters_setters
188+
# - unnecessary_lambdas # has false positives: https://github.com/dart-lang/linter/issues/498
189+
- unnecessary_new
190+
- unnecessary_null_aware_assignments
191+
- unnecessary_null_in_if_null_operators
192+
- unnecessary_overrides
193+
- unnecessary_parenthesis
194+
- unnecessary_statements
195+
- unnecessary_string_interpolations
196+
- unnecessary_this
197+
- unrelated_type_equality_checks
198+
# - unsafe_html # not yet tested
199+
- use_full_hex_values_for_flutter_colors
200+
# - use_function_type_syntax_for_parameters # not yet tested
201+
# - use_key_in_widget_constructors # not yet tested
202+
- use_rethrow_when_possible
203+
# - use_setters_to_change_properties # not yet tested
204+
# - use_string_buffers # has false positives: https://github.com/dart-lang/sdk/issues/34182
205+
# - use_to_and_as_if_applicable # has false positives, so we prefer to catch this by code-review
206+
- valid_regexps
207+
- void_checks

‎example/lib/pages/simple/zoom_image_demo.dart‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ class ZoomImageDemo extends StatelessWidget {
5252
inPageView: false,
5353
initialAlignment: InitialAlignment.center,
5454
gestureDetailsIsChanged: (GestureDetails details) {
55-
print(details.totalScale);
55+
//print(details.totalScale);
5656
},
5757
);
5858
},

‎lib/src/editor/extended_image_editor.dart‎

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import 'dart:ui' as ui;
44
import 'package:extended_image/src/extended_image_utils.dart';
55
import 'package:extended_image/src/image/extended_raw_image.dart';
66
import 'package:extended_image_library/extended_image_library.dart';
7+
import 'package:flutter/gestures.dart';
78
import 'package:flutter/material.dart';
89
import 'package:flutter/widgets.dart';
910
import '../extended_image.dart';
@@ -183,6 +184,7 @@ class ExtendedImageEditorState extends State<ExtendedImageEditor> {
183184
onPointerUp: (_) {
184185
_layerKey.currentState.pointerDown(false);
185186
},
187+
onPointerSignal: _handlePointerSignal,
186188
// onPointerCancel: (_) {
187189
// pointerDown(false);
188190
// },
@@ -217,8 +219,9 @@ class ExtendedImageEditorState extends State<ExtendedImageEditor> {
217219
if (_layerKey.currentState.isAnimating || _layerKey.currentState.isMoving) {
218220
return;
219221
}
220-
double totalScale = _startingScale * details.scale;
221-
final Offset delta = details.focalPoint - _startingOffset;
222+
double totalScale = _startingScale * details.scale * _editorConfig.speed;
223+
final Offset delta =
224+
details.focalPoint * _editorConfig.speed - _startingOffset;
222225
final double scaleDelta = details.scale / _detailsScale;
223226
final bool zoomOut = scaleDelta < 1;
224227
final bool zoomIn = scaleDelta > 1;
@@ -249,6 +252,18 @@ class ExtendedImageEditorState extends State<ExtendedImageEditor> {
249252
}
250253
}
251254

255+
void _handlePointerSignal(PointerSignalEvent event) {
256+
if (event is PointerScrollEvent && event.kind == PointerDeviceKind.mouse) {
257+
_handleScaleStart(ScaleStartDetails(focalPoint: event.position));
258+
final double dy = event.scrollDelta.dy;
259+
final double dx = event.scrollDelta.dx;
260+
_handleScaleUpdate(ScaleUpdateDetails(
261+
focalPoint: event.position,
262+
scale: 1.0 +
263+
(dy.abs() > dx.abs() ? dy : dx) * _editorConfig.speed / 1000.0));
264+
}
265+
}
266+
252267
Rect getCropRect() {
253268
if (widget.extendedImageState?.extendedImageInfo?.image == null) {
254269
return null;

‎lib/src/editor/extended_image_editor_utils.dart‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -364,7 +364,9 @@ class EditorConfig {
364364
this.cropAspectRatio = CropAspectRatios.custom,
365365
this.initCropRectType = InitCropRectType.imageRect,
366366
this.cornerPainter,
367+
double speed,
367368
}) : maxScale = maxScale ??= 5.0,
369+
speed = speed ?? 1.0,
368370
// initialScale = initialScale ??= 1.0,
369371
// assert(minScale <= maxScale),
370372
// assert(minScale <= initialScale && initialScale <= maxScale),
@@ -424,6 +426,9 @@ class EditorConfig {
424426
/// or extend class [ExtendedImageCropLayerCornerPainter]
425427
/// and create your own corner painter.
426428
final ExtendedImageCropLayerCornerPainter cornerPainter;
429+
430+
//speed for zoom/pan
431+
final double speed;
427432
}
428433

429434
class CropAspectRatios {

‎lib/src/extended_image.dart‎

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -823,9 +823,9 @@ class _ExtendedImageState extends State<ExtendedImage>
823823
setState(() {
824824
_loadState = LoadState.failed;
825825
});
826-
if (kDebugMode) {
827-
print(exception);
828-
}
826+
// if (kDebugMode) {
827+
// print(exception);
828+
// }
829829
if (!widget.enableMemoryCache || widget.clearMemoryCacheIfFailed) {
830830
widget.image.evict();
831831
}

‎lib/src/gesture/extended_image_gesture.dart‎

Lines changed: 18 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -215,9 +215,10 @@ class ExtendedImageGestureState extends State<ExtendedImageGesture>
215215
return;
216216
}
217217

218-
final Offset offset =
219-
(details.scale == 1.0 ? details.focalPoint : _startingOffset) -
220-
_normalizedOffset * scale;
218+
final Offset offset = (details.scale == 1.0
219+
? details.focalPoint * _gestureConfig.speed
220+
: _startingOffset) -
221+
_normalizedOffset * scale;
221222

222223
if (mounted &&
223224
(offset != _gestureDetails.offset ||
@@ -357,6 +358,7 @@ class ExtendedImageGestureState extends State<ExtendedImageGesture>
357358
image = Listener(
358359
child: image,
359360
onPointerDown: _handlePointerDown,
361+
onPointerSignal: _handlePointerSignal,
360362
);
361363

362364
return image;
@@ -407,6 +409,19 @@ class ExtendedImageGestureState extends State<ExtendedImageGesture>
407409
offset: Offset.zero,
408410
)..initialAlignment = _gestureConfig.initialAlignment;
409411
}
412+
413+
void _handlePointerSignal(PointerSignalEvent event) {
414+
if (event is PointerScrollEvent && event.kind == PointerDeviceKind.mouse) {
415+
_handleScaleStart(ScaleStartDetails(focalPoint: event.position));
416+
final double dy = event.scrollDelta.dy;
417+
final double dx = event.scrollDelta.dx;
418+
_handleScaleUpdate(ScaleUpdateDetails(
419+
focalPoint: event.position,
420+
scale: 1.0 +
421+
(dy.abs() > dx.abs() ? dy : dx) * _gestureConfig.speed / 1000.0));
422+
_handleScaleEnd(ScaleEndDetails());
423+
}
424+
}
410425
}
411426

412427
Map<Object, GestureDetails> _gestureDetailsCache = <Object, GestureDetails>{};

‎pubspec.yaml‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
name: extended_image
22
description: Official extension image, support placeholder(loading)/ failed state, cache network, zoom/pan, photo view, slide out page, editor(crop,rotate,flip), painting etc.
3-
version: 1.2.0
3+
version: 1.3.0
44
homepage: https://github.com/fluttercandies/extended_image
55

66
environment:

0 commit comments

Comments
 (0)