Now, the image is smoothly rotating only from left to right when I make a gesture of 360 degree.
Required result:
- Should rotate from right to left when we make a gesture of 360 degree.
- Done: Should rotate from right to left when we make a gesture of 360 degree.
- Once we start rotating from left to right at some point and again back to right to left it should rotate from either direction from which the gesture is made.
import 'dart:math';
import 'package:flutter/material.dart';
class RotateImage extends StatefulWidget {
RotateImage({Key key}) : super(key: key); // changed
@override
_RotateImageState createState() => _RotateImageState();
}
class _RotateImageState extends State<RotateImage> {
double finalAngle = 0.0;
@override
Widget build(BuildContext context) {
return _defaultApp(context);
}
_defaultApp(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Single finger Rotate text'), // changed
),
body: Center(
child: Column(
children: <Widget>[
Container(
color: Colors.red,
padding: EdgeInsets.all(10),
margin: EdgeInsets.only(top: 50),
child: Transform.rotate(
angle: finalAngle,
origin: Offset(0, 0),
child: Container(
height: 100.0,
width: 100.0,
child: Image.network(
'https://picsum.photos/250?image=9',
),
),
),
),
GestureDetector(
onPanStart: (detials) {},
onPanEnd: (detials) {},
onPanUpdate: (details) {
setState(
() {
finalAngle += details.delta.distance * -pi / 180;
},
);
},
child: Container(
margin: EdgeInsets.only(top: 30),
color: Colors.black54,
width: 50,
height: 50,
child: Icon(
Icons.rotate_left,
color: Colors.white,
),
),
)
],
),
),
);
}
}