flutter - 如何检测用户是否在颤动中打开页面
问题描述
我正在制作一个聊天应用程序并想在其中添加一个“已看到”选项,为此我想知道用户何时打开的页面我对此一无所知这些是我的路线
class Routes {
final routes = <String, WidgetBuilder>{
'/auth': (BuildContext context) => AuthScreen(),
'/home': (BuildContext context) => HomeScreen(),
'/profile/edit': (BuildContext context) => EditUserScreen(),
'/': (BuildContext context) => SplashScreen(),
'/phonelog': (BuildContext context) => MobileAuthScreen(),
'/Chat': (BuildContext context) => Chat(),
};
解决方案
这是一个例子:
您可以在路线创建期间添加模型,或者如果您使用任何类型的服务定位器或继承的小部件,则可以提供它。
不仅仅是向该模型添加一个您已经看到路线的标志。
class Routes {
final routes;
final RouteModel routeModel;
Routes()
: routeModel = RouteModel(),
routes = <String, WidgetBuilder>{
'/auth': (BuildContext context) => AuthScreen(routeModel),
'/home': (BuildContext context) => HomeScreen(routeModel),
'/profile/edit': (BuildContext context) => EditUserScreen(routeModel),
'/': (BuildContext context) => SplashScreen(routeModel),
'/phonelog': (BuildContext context) => MobileAuthScreen(routeModel),
'/Chat': (BuildContext context) => Chat(routeModel),
};
}
class RouteModel {
Map<String,bool> seen = {};
}
稍后在您的路线中,您希望以某种方式添加您看到的标志,并基于该标志构建小部件。
void aboutToNavigateOut(){
routeModel.seen['/home'] = true;
}
Widget build(context){
return Text(routeModel.seen['/home']?"Seen":"UnSeen");
}
推荐阅读
- flutter - 使用 Velocity_x Flutter 通过 url 传递参数
- c - 为什么这段代码不起作用?我需要一个字符串和一个数字并向后打印字符串,并且对于每个字符我需要将它移动 n 次
- azure-functions - 如何获取类似于 Windows 任务调度程序的 Azure 函数计时器触发器的信息
- service - 在嵌套 js 微服务控制器中使用功能模块服务的问题
- ubuntu - Gtk-rs 错误:无法加载模块“appmenu-gtk-module”
- xml - 为什么我的模板不起作用?只有空行
- c# - 更改后面代码中的数据后如何刷新 XAML 窗口?
- firebase - 颤振发布请求创建错误无效的基数 10 数字(在字符 1)
- android - 在 Facebook Android SDK 中,如何使用 GraphRequest 获取 is_verified 标志?
- javascript - 如何在 django 中使用 Bootstrap Modal 发送更新的数据并保存它?