Skip to content
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

Add touch number change callback #13

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions example/ios/Flutter/Debug.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.debug.xcconfig"
#include "Generated.xcconfig"
1 change: 1 addition & 0 deletions example/ios/Flutter/Release.xcconfig
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
#include? "Pods/Target Support Files/Pods-Runner/Pods-Runner.release.xcconfig"
#include "Generated.xcconfig"
41 changes: 41 additions & 0 deletions example/ios/Podfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
# Uncomment this line to define a global platform for your project
# platform :ios, '11.0'

# CocoaPods analytics sends network stats synchronously affecting flutter build latency.
ENV['COCOAPODS_DISABLE_STATS'] = 'true'

project 'Runner', {
'Debug' => :debug,
'Profile' => :release,
'Release' => :release,
}

def flutter_root
generated_xcode_build_settings_path = File.expand_path(File.join('..', 'Flutter', 'Generated.xcconfig'), __FILE__)
unless File.exist?(generated_xcode_build_settings_path)
raise "#{generated_xcode_build_settings_path} must exist. If you're running pod install manually, make sure flutter pub get is executed first"
end

File.foreach(generated_xcode_build_settings_path) do |line|
matches = line.match(/FLUTTER_ROOT\=(.*)/)
return matches[1].strip if matches
end
raise "FLUTTER_ROOT not found in #{generated_xcode_build_settings_path}. Try deleting Generated.xcconfig, then run flutter pub get"
end

require File.expand_path(File.join('packages', 'flutter_tools', 'bin', 'podhelper'), flutter_root)

flutter_ios_podfile_setup

target 'Runner' do
use_frameworks!
use_modular_headers!

flutter_install_all_ios_pods File.dirname(File.realpath(__FILE__))
end

post_install do |installer|
installer.pods_project.targets.each do |target|
flutter_additional_ios_build_settings(target)
end
end
15 changes: 14 additions & 1 deletion example/lib/main.dart
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,12 @@ class MyHomePage extends StatefulWidget {
}

class _MyHomePageState extends State<MyHomePage> {

// this is used to enable and disable scroll of the listview
// we can disable the listview scroll if the number of touch is 2 or more
// this will trigger zoom if the image is touched with two finger.
bool isZooming = false;

Widget listRow(int profile, int image, int likes, String name, String text) {
return Column(
crossAxisAlignment: CrossAxisAlignment.start,
Expand All @@ -50,7 +56,7 @@ class _MyHomePageState extends State<MyHomePage> {
modalBarrierColor: Colors.black12, // optional
minScale: 0.5, // optional
maxScale: 3.0, // optional
twoTouchOnly: true,
twoTouchOnly: false,
animationDuration: Duration(milliseconds: 300),
animationCurve: Curves.fastOutSlowIn,
onScaleStart: () {
Expand All @@ -59,6 +65,11 @@ class _MyHomePageState extends State<MyHomePage> {
onScaleStop: () {
debugPrint('zooming ended!');
}, // optional
onTouchCountChanged: (count) {
setState(() {
isZooming = count > 1;
});
},
child: CachedNetworkImage(
imageUrl: 'https://picsum.photos/800?image=$image')),
Padding(
Expand Down Expand Up @@ -129,6 +140,8 @@ class _MyHomePageState extends State<MyHomePage> {
fontSize: 38)),
systemOverlayStyle: SystemUiOverlayStyle.dark),
body: ListView(
// this disables the scroll which makes it easier for image to zoom.
physics: isZooming ? NeverScrollableScrollPhysics() : ScrollPhysics(),
children: <Widget>[
listRow(1027, 1062, 36, 'mary.porter',
'Lucy doesnt want to get out of bed today, its far too cold for the little darling.'),
Expand Down
15 changes: 13 additions & 2 deletions lib/zoom_pinch_overlay.dart
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ class ZoomOverlay extends StatefulWidget {
this.modalBarrierColor,
this.onScaleStart,
this.onScaleStop,
this.onTouchCountChanged,
}) : super(key: key);

/// A widget to make zoomable.
Expand Down Expand Up @@ -83,6 +84,10 @@ class ZoomOverlay extends StatefulWidget {
final VoidCallback? onScaleStart;
final VoidCallback? onScaleStop;

/// callback when the touch pointer changes
/// the parameter gives the number of current touch
final Function(int)? onTouchCountChanged;

@override
_ZoomOverlayState createState() => _ZoomOverlayState();
}
Expand Down Expand Up @@ -254,7 +259,13 @@ class _ZoomOverlayState extends State<ZoomOverlay>
_overlayEntry = null;
}

void _incrementEnter(PointerEvent details) => _touchCount++;
void _incrementEnter(PointerEvent details) {
_touchCount++;
widget.onTouchCountChanged?.call(_touchCount);
}

void _incrementExit(PointerEvent details) => _touchCount--;
void _incrementExit(PointerEvent details) {
_touchCount--;
widget.onTouchCountChanged?.call(_touchCount);
}
}