我遇到困难,但是我发现很难根据刚刚输入的通知对通知进行分组。因此目标是可以在顶部看到刚到达的通知。用于新通知的标记为“ NEW”,在这里我使用ListView对数据进行排序。这是用户买卖和聊天时的通知页面。关键是如何根据新通知设置正确的位置并对数据进行排序
Widget widget_purchase() {
return new Expanded(
child: RefreshIndicator(
onRefresh: () async {
pagePurchase = 1;
await getDataPurchase();
pagePurchase = 2;
return true;
},
child: LoadMore(
isFinish: lastPurchase == 0,
whenEmptyLoad: true,
textBuilder: DefaultLoadMoreTextBuilder.english,
onLoadMore: () async {
await getDataPurchase();
pagePurchase += 1;
return true;
},
child: ListView.builder(
itemCount: _purchase.length,
scrollDirection: Axis.vertical,
shrinkWrap: true,
itemBuilder: (context, index) {
return new Padding(
padding: EdgeInsets.fromLTRB(15, 5, 0, 0),
child: new GestureDetector(
onTap: () {
Navigator.pushNamed(
context, '/purchase_page',
arguments: _purchase[index]['id']
).then((val) async {
pagePurchase = 1;
await getDataPurchase();
pagePurchase = 2;
});
idPurchase = _purchase[index]['id'];
patchUpdatePurchase();
},
child: new Container(
//height: 100,
decoration: new BoxDecoration(
borderRadius: new BorderRadius.circular(8.0),
),
width: MediaQuery.of(context).size.width,
child: new Row(
crossAxisAlignment : CrossAxisAlignment.start,
children: <Widget>[
new Padding(
padding: EdgeInsets.fromLTRB(10, 0, 5, 0),
child: new FadeInImage.assetNetwork(
placeholder: "",
height: 70,
width: 100,
fit: BoxFit.fill,
image: _purchase[index]['filePath'][0],
),
),
new Flexible(
child: new Padding(
padding: EdgeInsets.only(top: 2),
child: new Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: <Widget>[
new Row(
children : <Widget>[
Flexible(
child: new Padding(
padding: EdgeInsets.fromLTRB(5, 0, 0, 0),
child: new Text(
_purchase[index]['game_title'],
overflow: TextOverflow.ellipsis,
maxLines: 2,
style: new TextStyle(
fontSize: 14,
fontWeight: FontWeight.bold,
color: selectedColor,
),
),
),
),
_purchase[index]['isRead'] == false ?
new Padding(
padding: EdgeInsets.only(left: 5),
child: new Container(
child: new Icon(
Icons.fiber_new,
color: selectedColor,
),
),
)
: new SizedBox.shrink(),
],
),
new Padding(
padding: EdgeInsets.fromLTRB(5, 0, 0, 0),
child: new Text(
_purchase[index]['product_type_name'],
overflow: TextOverflow.ellipsis,
style: new TextStyle(fontSize: 12),
),
),
new Row(
children: <Widget>[
new Padding(
padding: EdgeInsets.fromLTRB(5, 0, 0, 0),
child: new Text(
'US\$',
style: new TextStyle(fontSize: 12),
),
),
new Flexible(
child: new Text(
" " + _purchase[index]['amount'].toString(),
style: new TextStyle(fontSize: 12),
overflow: TextOverflow.ellipsis,
),
),
],
),
new Padding(
padding: EdgeInsets.fromLTRB(5, 0, 0, 0),
child: new Text(
_purchase[index]['status'],
style: new TextStyle(fontSize: 12),
),
),
],
),
),
),
],
),
),
),
);
},
),
),
),
);}
答案 0 :(得分:0)
假定您具有新通知的属性。例如:status
:
purchases.sort((a, b) => a["status"].compareTo(b["status"])); // if list contains model: a.status
将所有值添加到purchases
列表后,只需在行上方调用,并注意List
的{{3}}不会返回任何内容。
答案 1 :(得分:0)
据我了解,您希望所有新购买商品都位于顶部。其余部分要低于新购买的产品。
在构建窗口小部件之前,您可以基于_purchase
对isRead
进行排序。如果isRead
属性为false
,请给其较低的排序顺序,使其升序显示为较高。
Widget widget_purchase() {
_purchase.sort((a, b) => (b['isRead']? 1 : 0) - (a['isRead']? 1 : 0));
//Your code....
}