颤振的本地通知发送带有有效负载选项的ID

问题描述 投票:0回答:1

我有一个使用sqflite存储数据的应用程序。我使用构造函数方法从详细信息页面访问使用listview列出的记录。简短的代码如下。

notes.dart->主页

 child: ListView.builder(
                            itemCount: notes.length,
                            itemBuilder: (context, index) {
                              return NoteClass(
                                  notes: notes[index],
                                  );
                            },
                          ),

note_class.dart->

  return Column(
      children: <Widget>[
        Dismissible(
            key: UniqueKey(),
            movementDuration: Duration(milliseconds: 400),
            background: Container(
              child: Padding(
                padding: EdgeInsets.only(left: 38),
                child: Align(
                  alignment: Alignment.centerLeft,
                  child: Icon(
                    LineIcons.trash,
                    color: Colors.red.shade900,
                    size: 27,
                  ),
                ),
              ),
            ),
            onDismissed: (direction) {
              _deleteNote(widget.notes.noteID);
            },
            child: Card(
              margin: EdgeInsets.only(top: 2, bottom: 2),
              elevation: 2,
              shape: RoundedRectangleBorder(),
              child: Container(
                height: 80,
                child: ListTile(
                  onTap: (){
                    _detailPage(context, widget.notes);
                  },
                  contentPadding: EdgeInsets.only(left: 10, right: 5),
                  title: Stack(
                    children: <Widget>[
                      Container(
                        padding: EdgeInsets.only(top: 17),
                        child: Icon(Icons.note)
                      ),
                      Container(
                        padding: EdgeInsets.only(left: 45),
                        child: Row(
                          mainAxisAlignment:
                          MainAxisAlignment.spaceBetween,
                          children: <Widget>[
                            Column(
                              mainAxisAlignment:
                              MainAxisAlignment.spaceBetween,
                              crossAxisAlignment:
                              CrossAxisAlignment.start,
                              children: <Widget>[
                                Container(
                                    padding: EdgeInsets.only(top: 0),
                                    child: Text(
                                      widget.notes.noteHeader,
                                      style: TextStyle(
                                          fontSize: 19,
                                          color: Colors.grey[900]),
                                    )),
                                Container(
                                  padding: EdgeInsets.only(top: 0),
                                  child: Text(
                                     widget.notes.noteBody,
                                    style:  TextStyle(
                                        fontSize: 17,
                                        color: Colors.grey[900]),
                                  ),
                                ),
                              ],
                            ),
                          ],
                        ),
                      ),
                    ],
                  ),
                ),
              ),
            )),
      ],
    );



_detailPage(BuildContext context, NoteModel noteModel) {
    Navigator.push(
        context,
        PageTransition(
            type: PageTransitionType.rightToLeft,
            child: NoteDetail(
              content: notModel,
            )));
  }

note_detail.dart

Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      children: <Widget>[
                        Card(
                          elevation: 3,
                          shape: RoundedRectangleBorder(),
                          child: Container(
                            alignment: Alignment.centerLeft,
                            height: 50,
                            width: MediaQuery.of(context).size.width,
                            padding: EdgeInsets.only(left: 8, top: 0),
                            child: SelectableText(
                              widget.content.noteHeader,
                              style: TextStyle(fontSize: 18, color: Colors.grey[800],),
                            ),
                          ),
                        ),
                        Card(
                          elevation: 3,
                          shape: RoundedRectangleBorder(),
                          child: Container(
                            alignment: Alignment.centerLeft,
                            height: 50,
                            width: MediaQuery.of(context).size.width,
                            padding: EdgeInsets.only(left: 8, top: 0),
                            child: SelectableText(
                              widget.content.noteBody,
                              style: TextStyle(fontSize: 18, color: Colors.grey[800],),
                            ),
                          ),
                        ),],
                    ),

[在便笺详细信息页面上,我使用flutterLocalNotificationsPlugin.schedule设置了通知,我可以查看带有通知的便笺详细信息。但是,当我单击通知时,我想转到相关注释的详细信息页面。我发送了带有有效负载参数的记录ID。


然后,我在notes.dart中添加了onSelectNotification方法。

Future onSelectNotification(String payload) async {
    if (payload != null) {

######## what should I write here? ########

    }
  }

有效负载中有一个ID值。如何访问有关ID信息的注释详细信息。或单击通知,以这种方式我可以转到注释详细信息页面。

flutter localnotification
1个回答
0
投票

几乎您要做的就是与此类似的事情

class NoteDetail extends StatefulWidget {
  final String payload;
  NoteDetail (this.payload);

  @override
  State<StatefulWidget> createState() => NoteDetailState(payload);

}
class NoteDetailState extends State {
 Todo todo;
 TodoDetailState(this.todo);

 @override
 Widget build(BuildContext context) {
 return Scaffold(
  appBar: AppBar()
  body:Column( your column code here))
  }
// call this after something
void save() {
  //dosomething
  // go back to the old page 
  // notice the true, if all goes good with save send true otherwise false
  Navigator.pop(context, true);
}

}

// use this code to go to detail
void navigateToDetail(String payload) async {
bool result = await Navigator.push(context, 
    MaterialPageRoute(builder: (context) => NoteDetail(payload)),
);
if (result == true) {
  getData(); // refresh data from db
}

}

© www.soinside.com 2019 - 2024. All rights reserved.