import 'dart:collection'; import 'package:flutter/material.dart'; import 'package:huixiang/view_widget/message_item.dart'; class MineMessagePage extends StatefulWidget { final int status; final Function(bool) onChanged; MineMessagePage(this.status, this.onChanged); @override State createState() { return _MineMessagePage(); } } class _MineMessagePage extends State { Map map; @override void initState() { super.initState(); map = HashMap(); } @override Widget build(BuildContext context) { return SingleChildScrollView( child: Container( margin: EdgeInsets.only( left: 16, right: 16, top: 32, ), padding: EdgeInsets.only(top: 16, bottom: 16), decoration: BoxDecoration( color: Colors.white, boxShadow: [ BoxShadow( color: Colors.black.withAlpha(12), offset: Offset(0, 3), blurRadius: 14, spreadRadius: 0) ], borderRadius: BorderRadius.all(Radius.circular(8))), child: ListView.builder( itemCount: 12, shrinkWrap: true, physics: new NeverScrollableScrollPhysics(), itemBuilder: (context, position) { return Container( margin: EdgeInsets.only(top: 12, bottom: 12), child: GestureDetector( onTap: () { Navigator.of(context).pushNamed('/router/system_msg_page'); }, child: MessageItem(widget.status, (check) { map[position] = check; refreshStatus(); }), ), ); }), ), ); } refreshStatus() { var isOneCheck = false; map.forEach((key, value) { if (value) { isOneCheck = true; } }); if (widget.onChanged != null) { widget.onChanged.call(isOneCheck); } } }