Как поймать приложение, открыть новую страницу и вернуться
из Google Я получил много ответов, но ничто не решило мою проблему
некоторые из них:
SchedulerBinding.instance.addPostFrameCallback((_) => {
print("SchedulerBinding")
});
и
SystemChannels.lifecycle.setMessageHandler((msg){
debugPrint('SystemChannels> $msg');
if(msg==AppLifecycleState.resumed.toString())setState((){});
});
и
WidgetsBinding.instance.addObserver(
LifecycleEventHandler(resumeCallBack: () async => setState(() {
print("yes_resumeCallBack");
// do something
mBloc = NotificationBloc(context);
//mBloc.start();
mBloc.loadTodo();
//mBloc.getAllVisitNotificationFromApi(startLimit: 1, endLimit: 1);
}))
);
import 'package:flutter/material.dart';
import 'package:flutter/foundation.dart';
class LifecycleEventHandler extends WidgetsBindingObserver {
final AsyncCallback resumeCallBack;
final AsyncCallback suspendingCallBack;
LifecycleEventHandler({
this.resumeCallBack,
this.suspendingCallBack,
});
@override
Future<Null> didChangeAppLifecycleState(AppLifecycleState state) async {
print("state");
switch (state) {
case AppLifecycleState.resumed:
if (resumeCallBack != null) {
await resumeCallBack();
}
break;
case AppLifecycleState.inactive:
case AppLifecycleState.paused:
case AppLifecycleState.detached:
if (suspendingCallBack != null) {
await suspendingCallBack();
}
break;
}
}
}