当前位置:网站首页>[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 .
边栏推荐
- container of()函数简介
- Unity technical manual - interference / noise sub module
- SQL Server real time backup library requirements
- Article 7: there is no code prompt in clion,,,
- MySQL mysql-8.0.19-winx64 installation and Navicat connection
- The icon is missing. What does the URL come from with the jesssionid?
- Qi v1.2.4协议 之 定频调压方案
- Accumulation of some common knowledge points
- 解决nvprof 报错ERR_NVGPUCTRPERM - The user does not have permission to profile on the target device.
- CGI connects to database through ODBC
猜你喜欢

20 provinces and cities announce the road map of the meta universe

Computing architecture of microblog comments

Article 7: there is no code prompt in clion,,,

A simple and easy-to-use graph visualization tool developed recently

Kotlin of Android cultivation manual - several ways to write a custom view

Garbage collector and memory allocation strategy

微信小程序报错:request:fail url not in domain list

SDN系统方法 | 10. SDN的未来
![[daily record] - bug encountered during BigDecimal Division](/img/76/efb117986ac319987d4453bf00bec9.png)
[daily record] - bug encountered during BigDecimal Division

什么是算子?
随机推荐
About queryinterface functions
卷积操作的本质特性+TextCNN文本分类
Unity technical manual - lifecycle rotation rotationoverlifetime speed rotation rotationbyspeed external forces
OSError: Unable to open file (truncated file: eof = 254803968, sblock->base_addr = 0, stored_eof = 2
Introduction to the container of() function
哈希竞猜游戏系统开发如何开发?哈希竞猜游戏系统开发应用详情案例及源码
Qt产生指定范围内随机数(随机字符串)
SDN系统方法 | 9. 接入网
篇6:CLion:Toolchains are not configured Configure Disable profile
Introduction to microservices
Li Kou daily question - day 27 -561 Array splitting I
Swagger实现后台接口自动化文档
Idea global search for Chinese characters [easy to understand]
微博评论的计算架构
SQL Server real time backup library requirements
图标丢失,URL附带JESSSIONID的什么来的?
About Equilibrium - Simplified bottleneck model
SDN system method | 9 Access network
使用DiskGenius拓展系统盘C盘的容量
延时函数如何延时