I wrote a flutter application where the end customer doesn't want to scroll but wants to change the image simply by gestures.
So far so good I can handle this request, but the only problem is that when the image changes so I move from one to 'another, before seeing the next I get a white screen, immediately after the image. How can I remove this problem?
this is the sample code List elenco = []; //this variabile was loading in initstate
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text("${widget.nome}(${lstDoc.length})"),
backgroundColor: MyColors.navy,
),
resizeToAvoidBottomInset: false,
body: myView(),
);
}
void incrementaImmagine(String direzione, BuildContext context){
if (direzione == "avanti") {
if (pagina < lstDoc.length - 1) {
if (pagina + 2 <= lstDoc.length - 1) {
setState(() {
current = elenco[pagina];
});
}
}
} else if (direzione == "centro") {
setState(() {
current = elenco[pagina];
});
} else if (direzione == "indietro") {
setState(() {
current = elenco[pagina];
});
}
}
Widget myView() {
return Listener(
onPointerDown: (p) {
startx1 = p.localPosition.dx;
debugPrint("down: ${p.localPosition.dx}");
},
onPointerUp: (p) {
startx2 = p.localPosition.dx;
debugPrint("up: ${p.localPosition.dx}");
if (startx > 0) {
if (startx2 - startx1 > margSwipe) {
debugPrint("indietro_$pagina");
if (pagina >= 0) {
if (pagina >= 1) {
pagina -= 1;
} else {
pagina = 0;
}
incrementaImmagine("indietro", context);
} else {
pagina = 0;
incrementaImmagine("indietro", context);
}
}
}
if (startx < 0) {
if (startx1 - startx2 > margSwipe) {
debugPrint("avanti$pagina");
if (pagina + 1 < lstDoc.length - 1) {
pagina += 1;
incrementaImmagine("avanti", context);
}
}
}
},
onPointerMove: (moveEvent) {
startx = moveEvent.delta.dx;
},
child: current;
}
}