【发布时间】:2019-10-07 19:03:30
【问题描述】:
我正在我的颤振应用中实现推送通知,需要一些关于如何重定向的帮助..
基本上,这是正常的流程
app->root->home->list->detail。有一个默认的后退导航
当用户收到推送通知并单击它时,他们会直接转到详细信息页面。这是正确的,但我想看到一个后退按钮,他们可以在其中转到主屏幕。
应用程序->详细信息
我想要的是在用户查看详细信息后,他们应该返回主屏幕。但是,在这种情况下没有返回按钮
这是我的根页面
class RootPage extends StatefulWidget {
RootPage({Key key}) : super(key: key);
_RootPage createState() => _RootPage();
}
class _RootPage extends State<RootPage> with WidgetsBindingObserver {
AppLifecycleState _appLifecycleState;
var _message;
@override
void didChangeAppLifecycleState(AppLifecycleState state) {
setState(() {
_appLifecycleState = state;
});
}
final FirebaseMessaging _firebaseMessaging = FirebaseMessaging();
@override
void initState() {
super.initState();
WidgetsBinding.instance.addObserver(this);
_firebaseMessaging.configure(
onMessage: (Map<String, dynamic> message) {
setState(() {
_message = message;
});
},
//app in background
onResume: (Map<String, dynamic> message) {
setState(() {
_message = message;
});
},
);
_firebaseMessaging.requestNotificationPermissions(
const IosNotificationSettings(sound: true, badge: true, alert: true));
}
@override
void dispose() {
WidgetsBinding.instance.removeObserver(this);
super.dispose();
}
@override
Widget build(BuildContext context) {
if (_message != null) {
if (_appLifecycleState != null && _appLifecycleState.index == 0) {
// app is in resume state
if (_message["type"] == "Notification") {
String _Id = _message["Id"];
String _reference = _message["reference"];
return (DetailPage(Id: _Id, reference: _reference));
}
}
} //end if
return MyHomePage();
}
}
主页
class MyHomePage extends StatefulWidget {
MyHomePage({Key key, this.title}) : super(key: key);
final String title;
@override
_MyHomePageState createState() => _MyHomePageState();
}
class _MyHomePageState extends State<MyHomePage> {
@override
void initState() {
super.initState();
}
final List<Widget> _children = [
List(),
Search(),
MyCalendarPage(),
];
var _currentIndex = 0;
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: AppBar(
title: Center(child: Text("my app")),
actions: <Widget>[
new IconButton(
icon: new Icon(Icons.favorite),
onPressed: () {},
),
],
),
drawer: Drawer(),
body: _children[_currentIndex],
bottomNavigationBar: BottomNavigationBar(
type: BottomNavigationBarType.fixed,
onTap: onTabTapped, // new
currentIndex: _currentIndex, // new
items: [
new BottomNavigationBarItem(
icon: new Icon(Icons.home),
title: new Text("home"),
),
new BottomNavigationBarItem(
icon: new Icon(Icons.search),
title: new Text("search"),
),
new BottomNavigationBarItem(
icon: new Icon(Icons.schedule),
title: new Text("schedule"),
)
]
)
);
}
void onTabTapped(int index) {
setState(() {
_currentIndex = index;
});
}
}
如果有推送通知,我如何转到主屏幕然后重定向到详细信息页面?我相信那时我会看到一个后退按钮,因为上一页本来是主屏幕..
不知道如何重新编写我的代码来实现这一点
感谢您的帮助
【问题讨论】: