I need that when I press a button on the screen of my mobile device the screen is relocated in a specific part, that is to say I am in a scroll and when I press a button, I need that the screen goes up at the moment of pressing the button.
I need to relocate the screen to a specific place.
you have to use a scroll controller final ScrollController _controller = ScrollController(); and when you press the button you call this function:
void _animateToIndex(int index) {
_controller.animateTo(
index * _height,
duration: Duration(seconds: 2),
curve: Curves.fastOutSlowIn,
);}
Related
The docs says
// Called when the camera starts moving.
///
/// This can be initiated by the following:
/// 1. Non-gesture animation initiated in response to user actions.
/// For example: zoom buttons, my location button, or marker clicks.
/// 2. Programmatically initiated animation.
/// 3. Camera motion initiated in response to user gestures on the map.
/// For example: pan, tilt, pinch to zoom, or rotate.
final VoidCallback onCameraMoveStarted;
How to check if the map is moved by user gestures only (3) (pan, tilt, pinch...) not programmatically (1) and (2)
Anyway, you can track taps and gestures and camera updates together and decide is map moved due to user gestures or not. Or even disable gestures for map like Mangaldeep Pannu proposed:
return AbsorbPointer(
absorbing: true,
child: GoogleMap(
mapType: MapType.normal,
initialCameraPosition: cameraPosition,
gestureRecognizers: {
Factory<OneSequenceGestureRecognizer>(() => ScaleGestureRecognizer()),
}
)
);
then process all of them programmatically and decide what to do with map.
I'm trying to increase the speed of my change in text by pressing a button. So my text is a number.toString() and is increasing by 1 (++) every time I click my GestureDetector that I've created. But I'm trying to use the property onLongPress to increase the speed by which my text increases when I hold the button down. But nothing I've tried has worked successfully!
I've scoured the internet for info and all I found was how to slow it down one by one, which is not only the opposite of what I need but also it doesn't continue decreasing in count when I hold down the button, it only decreases the speed at which the button is pressed per number. The code I used was:
import 'package:flutter/scheduler.dart' show timeDilation;
...
Row(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: <Widget>[
GestureDetector(onTap: () => age >= 100 ? null : setState(() {
age++; }),
child: Icon(Icons.add_circle_outline, size: 40.0, color:
Colors.white,),
onLongPress: () { setState(() {
timeDilation = 10.0;
weight++;
});
},
), //GestureDetector
I expected the animation time to decrease, but I didn't expect to have to repeat tapping the button each time to allow for this decrease. I really want to increase the animation time and keep it increasing without having to constantly repeat pressing the button.
Although onLongPress in the GestureDetector is used for longer taps, it's still designed for a single press, not for contnual presses. What you're looking for though can be accomplished with the Listener widget, using onPointerDown, which would allow you to continuously process a tap down. There's a simple example here.
While testing out an application on Android I noticed something funky going on. A double click event handler has been triggering without any double clicks occurring on that particular item.
Trying to isolate the issue I discovered that pretty much every chain of clicks rapid as a double click on regardless what two objects would cause the second click on the second object to register as a double click, when in fact it is just a single click.
Below is an example consisting of a row of 3 randomly colored rectangles, each one with a mouse area inside of it. The double click of each mouse area is rigged to set the parent rectangle's color to a different random color. Clicking rapidly two different rectangles under android triggers a double click and a color change for the second. This does not happen on Windows or Ubuntu Linux.
Window {
id: main
visible: true
width: 400
height: 400
title: qsTr("Hello World")
Row {
Rectangle {
width: main.width * .33
height: main.height
color: Qt.rgba(Math.random(), Math.random(), Math.random(), 1)
border.color: "black"
border.width: 2
MouseArea {
anchors.fill: parent
onDoubleClicked: parent.color = Qt.rgba(Math.random(), Math.random(), Math.random(), 1)
}
}
Rectangle {
width: main.width * .33
height: main.height
color: Qt.rgba(Math.random(), Math.random(), Math.random(), 1)
border.color: "black"
border.width: 2
MouseArea {
anchors.fill: parent
onDoubleClicked: parent.color = Qt.rgba(Math.random(), Math.random(), Math.random(), 1)
}
}
Rectangle {
width: main.width * .33
height: main.height
color: Qt.rgba(Math.random(), Math.random(), Math.random(), 1)
border.color: "black"
border.width: 2
MouseArea {
anchors.fill: parent
onDoubleClicked: parent.color = Qt.rgba(Math.random(), Math.random(), Math.random(), 1)
}
}
}
}
It looks as if the "previous click" or whatever property that's supposed to be used to detect double clicks is shared between different mouse areas instead of being per mouse area. The issue manifests in both Qt 5.7 and 5.7.1.
It definitely looks like my 10th discovered Qt bug this year, but I still feel like asking on the odd chance someone knows what's going on and how to fix it, because I need this fixed, and the Qt bugreport process is not speedy. So any ideas are more than welcome.
Until there is a better answer with an actual solution, it may be useful to know that it is possible to somewhat mitigate the devastating effect this issue has on user experience by reducing the global interval for double click detection.
By default it is the rather lethargic 500 msec. I found out that by reducing it to 250 msec helps to avoid over 90% of the incorrect double clicks:
QGuiApplication app(argc, argv);
app.styleHints()->setMouseDoubleClickInterval(250);
Additionally, there is a quick and hacky qml-only way to create a "fixed" copy of MouseArea:
// MArea.qml
Item {
id: main
property alias mouseX : ma.mouseX
property alias mouseY : ma.mouseY
property alias acceptedButtons: ma.acceptedButtons
// etc aliases
signal clicked(var mouse)
signal doubleClicked(var mouse)
// etc signals, function accessors
MouseArea {
id: ma
property real lClick : 0
anchors.fill: parent
onClicked: {
var nc = Date.now()
if ((nc - lClick) < 500) main.doubleClicked(mouse)
else main.clicked(mouse)
lClick = nc
}
}
}
This one actually works as intended and can be made almost entirely "plug and play" compatible with the original one.
I have a NativeScript project which contains a ListView. I used its event "onItemTap" and this is the function I wrote:
onItemTap(args){
let clicked = args.view.bindingContext;
let fav = this.page.getViewById("star-"+clicked.id);
fav.animate({
rotate: 360,
duration: 1000
});
}
Basically I'm retrieving the item I clicked, inside the item there is a label which has the id "star-N" [N is the intex of the item] and I'm animating it.
It works fine, the problem is that it just works once! From the second tap, it animates no more. The console isn't returning any errors. I'm using my Android device to debug it.
Any idea? Thanks!
Apparently after the rotation, the "rotate" property of the element isn't reset to its initial value. This means that in the first tap your rotate property goes from 0 => 360 and then on the second tap from 360 => 360 so no animation occurs.
Not sure if it is really intended to be like this but you can always manually set the rotate property to 0 once the animation is done:
onItemTap(args) {
let clicked = args.view.bindingContext;
let fav = this.page.getViewById("star-"+clicked.id);
fav.animate({
rotate: 360,
duration: 1000
}).then(() => fav.rotate = 0);
}
I have this
int MainWindow::messageBox( QString button, QMessageBox::ButtonRole buttons, QString info, QMessageBox::Icon icon )
{
QFont f;
f.setPointSize(6);
QMessageBox *message = new QMessageBox(this);
message->setWindowModality(Qt::WindowModal);
message->setFont(f);
message->setText(info);
message->addButton( button, buttons );
message->setWindowTitle("MainWindow");
message->setIcon(icon);
message->move( this->width() / 2, this->height() / 2 );
return message->exec();
}
But I can't make the qmessagebox go to the center of the screen, I also tried using setGeometry, but it doesn't work. Any ideas on this?
I solved using show() before moving it. This is the code:
int MainWindow::messageBox( QString button, QMessageBox::ButtonRole buttons, QString info, QMessageBox::Icon icon )
{
QFont f;
QMessageBox *message = new QMessageBox(this);
QDesktopWidget *win = new QDesktopWidget();
f.setPointSize(6);
message->setWindowModality(Qt::WindowModal);
message->setFont(f);
message->setText(info);
message->addButton( button, buttons );
message->setWindowTitle("MainWindow");
message->setIcon(icon);
message->show();
message->move( win->width() / 2 - message->width() / 2, win->height() / 2 - message->height() / 2 );
return message->exec();
}
A QMessageBox is created with the window flag Qt::Dialog (and indirectly, Qt::Window). This means that it will be treated like a system window even though it has a parent assigned. When you call move() on it, it will be positioned in desktop coordinates.
When you move the message box in your code above, you are telling it to appear at desktop coordinates equal to half the width and height of your main application window size offset from origin (the top left corner of you desktop).
If your main application window has a size of 400x200, then your message box will appear at desktop coordinates 200,100 no matter where your main application window is located.
If you make your application window full screen and then display the message box, the message box should appear (roughly) at the center of your desktop display. I say roughly because you are specifying the position of the top left corner of the message box, not where the center of the message box will appear to be.
If you want the message box to always appear at the center of the screen, then you need to use the information provided by QDesktopWidget to determine what the correct screen coordinates should be.