How can I refresh the page on button tap? I am displaying one default image which is initialized at the beggining with some url. My goal is when I press a button refresh that image. For that, I placed a button in other part of the code and I refresh the state changing the value of the variable (url) with the one I want to display:
The card where I want to refresh the image with the variable urlImgCard.
Expanded(
child: Container(
decoration: BoxDecoration(
borderRadius:
const BorderRadius.only(
topLeft:
Radius.circular(15),
topRight:
Radius.circular(
15)),
image: DecorationImage(
image: NetworkImage(
urlImgCard,
),
fit: BoxFit.cover,
),
),
),
),
This is how I initialize the variable with a default url:
child: FloatingActionButton(
shape: RoundedRectangleBorder(
borderRadius:
BorderRadius.circular(10)),
child: const Text('Show'),
onPressed: () async {
setState(() {
showImgPushed = true;
urlImgCard =
AppConstants.BACK4APP_IMG_URL +
snapshot.data![currentIndex
as int]['DogImg'];
});
beginning of the code, in initState:
var urlImgCard;
@override
void initState() {
super.initState();
setState(() {
urlImgCard = AppConstants.QUESTION_MARK_IMG;
});