Skip to content

Commit

Permalink
new image viewer and bug fix
Browse files Browse the repository at this point in the history
  • Loading branch information
dasmikko committed Sep 10, 2020
1 parent ddb10a9 commit 8f92ddf
Show file tree
Hide file tree
Showing 14 changed files with 502 additions and 27 deletions.
12 changes: 6 additions & 6 deletions ios/Flutter/flutter_export_environment.sh
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@
# This is a generated file; do not edit or check into version control.
export "FLUTTER_ROOT=/Users/mikkeljensen/development/flutter"
export "FLUTTER_APPLICATION_PATH=/Users/mikkeljensen/development/repos/knocky"
export "FLUTTER_TARGET=/Users/mikkeljensen/development/repos/knocky/lib/main.dart"
export "FLUTTER_TARGET=lib/main.dart"
export "FLUTTER_BUILD_DIR=build"
export "SYMROOT=${SOURCE_ROOT}/../build/ios"
export "OTHER_LDFLAGS=$(inherited) -framework Flutter"
export "FLUTTER_FRAMEWORK_DIR=/Users/mikkeljensen/development/flutter/bin/cache/artifacts/engine/ios-profile"
export "FLUTTER_BUILD_NAME=1.6.0"
export "FLUTTER_BUILD_NUMBER=48"
export "FLUTTER_FRAMEWORK_DIR=/Users/mikkeljensen/development/flutter/bin/cache/artifacts/engine/ios-release"
export "FLUTTER_BUILD_NAME=1.6.1"
export "FLUTTER_BUILD_NUMBER=49"
export "DART_OBFUSCATION=false"
export "TRACK_WIDGET_CREATION=true"
export "TREE_SHAKE_ICONS=false"
export "TRACK_WIDGET_CREATION=false"
export "TREE_SHAKE_ICONS=true"
export "PACKAGE_CONFIG=.packages"
Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.
Binary file added ios/build/XCBuildData/build.db
Binary file not shown.
Binary file not shown.

Large diffs are not rendered by default.

Binary file not shown.

Large diffs are not rendered by default.

115 changes: 98 additions & 17 deletions lib/screens/imageViewer.dart
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import 'dart:async';

import 'package:flutter/material.dart';
import 'package:flutter_advanced_networkimage/zoomable.dart';
import 'package:flutter/services.dart';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:matrix4_transform/matrix4_transform.dart';
//import 'package:knocky_edge/helpers/Download.dart';

class ImageViewerScreen extends StatefulWidget {
Expand All @@ -15,15 +17,98 @@ class ImageViewerScreen extends StatefulWidget {
_ImageViewerScreenState createState() => _ImageViewerScreenState();
}

class _ImageViewerScreenState extends State<ImageViewerScreen> {
class _ImageViewerScreenState extends State<ImageViewerScreen>
with TickerProviderStateMixin {
final GlobalKey<ScaffoldState> _scaffoldKey = new GlobalKey<ScaffoldState>();
int _currentPage = 0;
bool _isZooming = false;
TransformationController transformationController;
Animation<Matrix4> _animationZoom;
AnimationController _animationController;

int _tapCount = 0;

@override
void initState() {
super.initState();
transformationController = new TransformationController();
_currentPage = this.widget.urls.indexOf(widget.url);

_animationController = AnimationController(
vsync: this,
duration: const Duration(milliseconds: 400),
);
}

void _onZoomAnimation() {
transformationController.value = _animationZoom.value;
if (!_animationController.isAnimating) {
_animationZoom?.removeListener(_onZoomAnimation);
_animationZoom = null;
_animationController.reset();
}
}

void _handleTapDown(TapDownDetails details) async {
print('tap tap tap');
final RenderBox referenceBox = context.findRenderObject();

print(details);

Timer onSingleTapTimer = Timer(Duration(milliseconds: 200), () {
print('is single tap');
setState(() {
_tapCount = 0;
});
});

if (_tapCount < 2) {
print(_tapCount);
setState(() {
_tapCount++;
});
}

if (_tapCount >= 2) {
print('is Double tap');

onSingleTapTimer.cancel();

if (_animationController.isAnimating) {
_animationController.reverse();
}

setState(() {
_tapCount = 0;
});

double currentScale = transformationController.value.getMaxScaleOnAxis();
Matrix4 endTransform;

if (currentScale == 1.0) {
setState(() {
_isZooming = true;
});
endTransform = Matrix4Transform.from(transformationController.value)
.scale(3, origin: details.globalPosition)
.matrix4;
} else {
setState(() {
_isZooming = false;
});
endTransform = Matrix4.identity();
}

_animationZoom = Matrix4Tween(
begin: transformationController.value,
end: endTransform,
).animate(CurvedAnimation(
parent: _animationController,
curve: Curves.ease,
));
_animationZoom.addListener(_onZoomAnimation);
_animationController.forward();
}
}

@override
Expand Down Expand Up @@ -72,30 +157,26 @@ class _ImageViewerScreenState extends State<ImageViewerScreen> {
return Container(
child: Hero(
tag: this.widget.urls[index] + this.widget.postId.toString(),
child: ZoomableWidget(
child: InteractiveViewer(
transformationController: transformationController,
minScale: 1.0,
maxScale: 2.0,
zoomSteps: 3,
enableFling: true,
autoCenter: true,
multiFingersPan: false,
bounceBackBoundary: true,
onZoomChanged: (double zoom) {
if (zoom > 1.0 && !_isZooming) {
panEnabled: true,
maxScale: 3.0,
onInteractionUpdate: (ScaleUpdateDetails update) {
if (update.scale > 1.0 && !_isZooming) {
setState(() {
_isZooming = true;
});
}

if (zoom == 1.0 && _isZooming) {
} else if (update.scale < 1.0 && _isZooming) {
setState(() {
_isZooming = false;
});
}
},
// default factor is 1.0, use 0.0 to disable boundary
panLimit: 1.0,
child: CachedNetworkImage(imageUrl: this.widget.urls[index]),
child: GestureDetector(
child: CachedNetworkImage(imageUrl: this.widget.urls[index]),
onTapDown: _handleTapDown,
),
),
),
);
Expand Down
9 changes: 6 additions & 3 deletions lib/widget/Thread/ThreadPostItem.dart
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ class _ThreadPostItemState extends State<ThreadPostItem> {
if (ratings != null) {
ratings.sort((a, b) => b.count.compareTo(a.count));
ratings.forEach((rating) {
RatingistItem icon =
ratingsIconList.firstWhere((icon) => icon.id == rating.rating);

RatingistItem icon;
try {
icon = ratingsIconList.firstWhere((icon) => icon.id == rating.rating);
} catch (e) {
return;
}
if (icon != null) {
items.add(
Container(
Expand Down
3 changes: 2 additions & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ publish_to: 'none' # Remove this line if you wish to publish to pub.dev
# In iOS, build-name is used as CFBundleShortVersionString while build-number used as CFBundleVersion.
# Read more about iOS versioning at
# https://developer.apple.com/library/archive/documentation/General/Reference/InfoPlistKeyReference/Articles/CoreFoundationKeys.html
version: 1.6.0+48
version: 1.6.1+49

environment:
sdk: ">=2.7.0 <3.0.0"
Expand Down Expand Up @@ -50,6 +50,7 @@ dependencies:
permission_handler: ^5.0.1+1
image_picker: ^0.6.7+4
device_info: ^0.4.2+4
matrix4_transform: ^1.1.4
flutter:
sdk: flutter

Expand Down

0 comments on commit 8f92ddf

Please sign in to comment.