当前位置:网站首页>[how do I refresh the shuttle page after jumping back?]
[how do I refresh the shuttle page after jumping back?]
2022-06-25 18:07:00 【Fishing Map】
Baidu a lot , But it's not clear , Quote an example on the Internet
https://www.nstack.in/blog/flutter-refresh-on-navigator-pop-or-go-back/
The code is as follows :
import 'package:flutter/material.dart';
void main() {
runApp(MyApp());
}
class MyApp extends StatelessWidget {
@override
Widget build(BuildContext context) {
return MaterialApp(
title: 'Refresh on Go Back',
home: HomePage(),
);
}
}
class HomePage extends StatefulWidget {
@override
_HomePageState createState() => _HomePageState();
}
class _HomePageState extends State<HomePage> {
int id = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Home'),
),
body: Center(
child: Column(
mainAxisSize: MainAxisSize.min,
children: <Widget>[
Text(
'Data: $id',
style: Theme.of(context).textTheme.headline5,
),
RaisedButton(
child: Text('Second Page'),
onPressed: navigateSecondPage,
),
],
),
),
);
}
void refreshData() {
id++;
}
onGoBack(dynamic value) {
refreshData();
setState(() {
});
}
// Part I places to be set
void navigateSecondPage() {
Route route = MaterialPageRoute(builder: (context) => SecondPage());
Navigator.push(context, route).then(onGoBack);
}
}
class SecondPage extends StatelessWidget {
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Text('Second Page'),
),
body: Center(
child: RaisedButton(
onPressed: () {
// Part II places to be set
Navigator.pop(context);
},
child: Text('Go Back'),
),
),
);
}
}
The key to backward refresh :
from HomePage To SecondPage Use
// Part I places to be set
void navigateSecondPage() {
Route route = MaterialPageRoute(builder: (context) => SecondPage());
Navigator.push(context, route).then(onGoBack);
}
The key is also here , There is .then Refresh method in .
onGoBack(dynamic value) {
refreshData();
setState(() {});
};
from SecondPage Back to HomePage when , Use
// Part II places to be set
Navigator.pop(context);
in other words , No additional pass parameters are required , Back to HomePage I will jump over according to the first time Navigator.push Medium .then Method auto refresh .
边栏推荐
- Bert's summary of me
- Deep understanding of ELF files
- Swagger implements background interface automation document
- Is the actual account opening complicated? Is online account opening safe?
- Video production material website arrangement
- 近来开发的一款简单易用的图可视化工具
- About Equilibrium - Simplified bottleneck model
- About queryinterface functions
- QT中QString包含“\u0000“的处理方式
- Computing architecture of microblog comments
猜你喜欢

观察者模式之通用消息发布与订阅

Deep understanding of ELF files

CentOS7 安装 Redis 7.0.2

Part 5:vs2017 build qt5.9.9 development environment

SDN系统方法 | 10. SDN的未来

Mobile heterogeneous computing technology - GPU OpenCL programming (basic)

HMS core machine learning service realizes simultaneous interpretation, supports Chinese-English translation and multiple voice broadcast

Chapter 4:win10 installing mingw64

有关均衡----简易版瓶颈模型

1、对范数的理解
随机推荐
Which of the top ten securities companies has the lowest commission? Is it safe to open an account
Bilstm and CRF
How to open a stock account is it safe to open an account
[machine learning] case study of college entrance examination prediction based on multiple time series
User scheduling problem
Introduction to microservices
Expressing integers by the sum of consecutive natural numbers
Video production material website arrangement
BILSTM和CRF的那些事
C语言中%含义
[compilation principle] lexical analysis
Kotlin of Android cultivation manual - several ways to write a custom view
存在重复元素III[利用排序后的有序性进行剪枝]
Li Kou daily question - day 27 -561 Array splitting I
New characteristics of cultural consumption in the era of digital economy
智能体白皮书 - 共建智能体,共创全场景智慧 | 云享书库NO.21推荐
Time series analysis of data mining [easy to understand]
win10安装cuda的操作步骤(不断完美中)
近来开发的一款简单易用的图可视化工具
SDN system method | 9 Access network