我有一个全局函数,我可以从应用程序的几乎所有屏幕调用它。我正在向它传递上下文。我只想知道是否有办法根据传递给函数的上下文刷新调用全局函数的页面?
appResumedPausedLogic(context,[bool isVisitPage]){
SystemChannels.lifecycle.setMessageHandler((msg)async{
if(msg=='AppLifecycleState.resumed' )
{
print("------------------------------------ App Resumed-----------------------------");
var serverConnected= await checkConnectionToServer();
if(globals.globalCameraOpenedStatus==false)
if(serverConnected!=1){
Navigator.pushReplacement(context, MaterialPageRoute(builder: (context) => OfflineHomePage()));
}
else{
Navigator.push(context, MaterialPageRoute(builder: (context) => HomePage()));
}
}
if(msg=='AppLifecycleState.paused' ){
if(globals.globalCameraOpenedStatus==false)
locationThreadUpdatedLocation=false;
}
});
}
Run Code Online (Sandbox Code Playgroud)
当应用程序当前恢复时,我的全局功能根据互联网的可用性将用户重定向到离线主页/主页。我希望它刷新当前活动的屏幕。
提前致谢!
我用命令做了一个flutter项目
flutter create -i swift myProject
Run Code Online (Sandbox Code Playgroud)
然后我使用 cd myProject 将目录更改为 myProject,然后运行 pod setup。它运行得很快,但是当我根据此处的教程将代码添加到 ios/Runner/Runner 目录中的 AppDeligate.swift 时:
https://flutter.dev/docs/development/platform-integration/platform-channels
这是我的 AppDeligate.swift:
@UIApplicationMain
@objc class AppDelegate: FlutterAppDelegate {
override func application(
_ application: UIApplication,
didFinishLaunchingWithOptions launchOptions:
[UIApplicationLaunchOptionsKey: Any]?
) -> Bool {
GeneratedPluginRegistrant.register(with: self)
let controller : FlutterViewController = window?.rootViewController as! FlutterViewController
let batteryChannel = FlutterMethodChannel(name: "samples.flutter.dev/battery",
binaryMessenger: controller.binaryMessenger)
batteryChannel.setMethodCallHandler({
(call: FlutterMethodCall, result: @escaping FlutterResult) -> Void in
// Note: this method is invoked on the UI thread.
// Handle battery messages. …
Run Code Online (Sandbox Code Playgroud) 我有一个 srting 日期 2019-09-30,我想在 dart 中将其转换为 30-09-2019