flatter redux如何执行轮询
flatter redux如何执行轮询,redux,dart,flutter,Redux,Dart,Flutter,Redux似乎是一个非常好的移动应用程序开发架构。但是,移动应用程序具有一些web应用程序不常见的功能 在我的例子中,我希望在某个特定屏幕启动后启动长轮询/监视位置/跟踪文件系统(监视某些外部状态的任何操作),并在屏幕关闭时停止 假设我们有一个函数,它可以随时间发出多个事件 Streammonitor(); 我只想在某些特定屏幕处于活动状态时收听该功能 最好的方法是什么 假设您有3个页面:“PageHome.dart”、“Page1.dart”、“Page2.dart” 创建另一个dart文件
Redux
似乎是一个非常好的移动应用程序开发架构。但是,移动应用程序具有一些web应用程序不常见的功能
在我的例子中,我希望在某个特定屏幕启动后启动长轮询/监视位置/跟踪文件系统(监视某些外部状态的任何操作),并在屏幕关闭时停止
假设我们有一个函数,它可以随时间发出多个事件
Streammonitor();
我只想在某些特定屏幕处于活动状态时收听该功能
最好的方法是什么 假设您有3个页面:“PageHome.dart”、“Page1.dart”、“Page2.dart”
import 'package:redux/redux.dart';
enum Actions {
Increment
}
// The reducer, which takes the previous count and increments it in response to an Increment action.
int reducerRedux(int intSomeInteger, dynamic action) {
if (action == Actions.Increment) {
return intSomeInteger + 1;
}
return intSomeInteger;
}
class gv {
static Store<int> storePageHome =
new Store<int>(reducerRedux, initialState: 0);
static Store<int> storePage1 =
new Store<int>(reducerRedux, initialState: 0);
static Store<int> storePage2 =
new Store<int>(reducerRedux, initialState: 0);
static String strCurPage = 'PageHome';
static String strPageHomeVar = 'PageHomeInitialContent';
static String strPage1Var = 'Page1InitialContent';
static String strPage2Var = 'Page2InitialContent';
}
我不知道这是否是最好的方法,但使用redux和GlobalVariables.dart,我可以:
void thisFunctionCalledByExternalEvent(strPage1NewContent, strPage2NewContent) {
gv.strPage1Var = strPage1NewContent;
gv.strPage2Var = strPage2NewContent;
if (gv.strCurPage == 'Page1') {
// Dispatch storePage1 to refresh Page 1
storePage1.dispatch(Actions.Increment);
} else if (gv.strCurPage == 'Page2') {
// Dispatch storePage2 to refresh Page 2
storePage2.dispatch(Actions.Increment);
} else {
// Do not need to refresh page if user currently navigating other pages.
// so do nothing here
}
}