我有一个应用程序可以使用OneSignal接收推送通知。我做了一个通知打开处理程序,应在单击通知时打开特定的屏幕。我如何导航到没有上下文的屏幕。或如何在应用启动时打开特定屏幕。我的代码:
OneSignal.shared.setNotificationOpenedHandler((notification) {
var notify = notification.notification.payload.additionalData;
if (notify["type"] == "message") {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => DM(user: notify['id']),
),
);
}
if (notify["type"] == "user") {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => Profileo(notify["id"]),
),
);
}
if (notify["type"] == "post") {
Navigator.of(context).push(
MaterialPageRoute(
builder: (context) => ViewPost(notify["id"]),
),
);
}
});
Run Code Online (Sandbox Code Playgroud)
首次打开该应用程序时,我可以实现此目的,但是,即使我关闭了该应用程序,即使重新打开它也只能打开主页。我想那是因为上下文已更改。
请帮忙!!
我正在使用 OneSignal 推送通知服务,我想在点击通知时直接将应用程序打开到特定页面。我正在通过数据发送页面。我试过 navigator.push 但我猜它没有用,因为上下文问题。我在登录后调用 _initializeonesignal() ,其中包含 onesignal init 和以下代码。
OneSignal.shared.setNotificationOpenedHandler((notification) {
var notify = notification.notification.payload.additionalData;
if (notify["type"] == "message") {
//open DM(user: notify["id"])
}
if (notify["type"] == "user") {
//open Profileo(notify["id"])
}
if (notify["type"] == "post") {
//open ViewPost(notify["id"])
}
print('Opened');
});
Run Code Online (Sandbox Code Playgroud) 我一直在尝试在 Flutter 中制作一个接收推送通知的应用程序。当我在 Redmi note 5 上运行它时,当应用程序位于前台或后台时,我会收到通知,但当应用程序终止时,我不会收到任何通知。另一方面,当我在 OnePlus 6T 上运行它时,即使应用程序终止,一切也能正常工作。我认为这里的问题是应用程序不允许在后台运行或其他东西,但 Instagram、Facebook...如何实现这一点?
我正在创建类似Instagram个人资料的屏幕,但mainaxisAlignment.spaceEvenly无法正常工作。如果该行不在任何其他行或列内,则工作正常,但在这种情况下则没有。我该如何解决?请帮忙。
Container(
margin: EdgeInsets.all(15.0),
child: Column(
children: <Widget>[
Row(
children: <Widget>[
Container(
width: 100.0,
height: 100.0,
margin: EdgeInsets.only(
right: 10.0,
),
decoration: new BoxDecoration(
shape: BoxShape.circle,
image: new DecorationImage(
fit: BoxFit.fill,
image: new CachedNetworkImageProvider(
profile.dp,
scale: 100.0,
),
),
),
),
Column(
children: <Widget>[
Row(
mainAxisAlignment:
MainAxisAlignment.spaceEvenly,
children: <Widget>[
Column(
children: <Widget>[
Text(
profile.postcount.toString(),
style: TextStyle(
fontWeight: FontWeight.bold),
),
Text('posts'),
],
),
Column(
children: <Widget>[
Text(
profile.followers.toString(),
style: TextStyle(
fontWeight: FontWeight.bold),
),
Text('followers'),
],
),
Column(
children: <Widget>[ …Run Code Online (Sandbox Code Playgroud) 我正在尝试开发一个聊天应用程序,并且试图在容器内显示文本消息,并根据消息的长度设置宽度。如何根据字符串的长度设置宽度?PS消息使用listview.builder显示,并且每个容器都有背景色。
ListView.builder(
padding: EdgeInsets.only(top: 8.0, left: 15.0, right: 15.0),
itemCount: messages.length,
itemBuilder: (context, index) {
return Container(
padding: EdgeInsets.all(20.0),
margin: index % 2 == 0
? EdgeInsets.only(bottom: 5.0, right: 60.0)
: EdgeInsets.only(bottom: 5.0, left: 60.0),
decoration: index % 2 == 0
? BoxDecoration(
border: Border.all(
color: Colors.grey,
),
borderRadius: BorderRadius.all(
Radius.circular(30.0),
),
)
: BoxDecoration(
color: Colors.grey[300],
borderRadius: BorderRadius.all(
Radius.circular(30.0),
),
),
child: Text(
messages[index].text,
style: TextStyle(color: Colors.black),
),
);
},
),
Run Code Online (Sandbox Code Playgroud)