import 'package:flutter/material.dart';
import 'message_content.dart';
//import 'messages_data.dart';
import '../../../components/doJSON.dart';
import '../../../components/hyxx_data_handle.dart';
import '../../../components/customDialogG.dart';

class MessagesInbox extends StatefulWidget {
  MessagesInbox({Key key}) : super(key: key);

  _LoginPageState createState() => _LoginPageState();
}

class _LoginPageState extends State<MessagesInbox> {
  Widget _getListTile(BuildContext context, index) {
    return Column(
      children: <Widget>[
        ListTile(
          //leading: new Icon(Icons.phone),
          title: new Text(listMessagesInbox2[index]['date'], style: TextStyle(fontSize: 10)),
          subtitle: Text(listMessagesInbox2[index]['time'], style: TextStyle(fontSize: 10)),
          trailing: Container(
            width: 260,
            child: Text(
              listMessagesInbox2[index]['title'],
              maxLines: 1,
              overflow: TextOverflow.ellipsis,
              //textAlign: TextAlign.right,
              style: TextStyle(fontSize: 16),
            ),
          ),
          contentPadding: EdgeInsets.symmetric(horizontal: 20.0, vertical: 0),
          enabled: true,
          onTap: () {
            // Navigator.of(context).push(MaterialPageRoute(
            //     builder: (context) => MessagesView(
            //         title: '收到的消息', mapData: listMessagesInbox2[index])));

            Navigator.of(context).push(
              MaterialPageRoute(
                builder: (context) => MessagesView(title: '收到的消息', listIndex: index),
              ),
            );

            // Navigator.push(context, MaterialPageRoute(builder: (context) {
            //   return MessagesOutbox(
            //       title: "PeakPlayer帮助信息", mapData: listMessagesInbox2[index]);
            // }));
          },
          onLongPress: () async {
            bFlash = false;
            // Navigator.of(context).push(
            //   MaterialPageRoute(
            //     builder: (context) => customDialogG(
            //         title: '收到的消息',
            //         index: index),
            //   ),
            // );
            Navigator.of(context).push(
              PageRouteBuilder(
                opaque: false,
                pageBuilder: (context, animation, secondaryAnimation) =>
                    customDialogG(title: '收到的消息', index: index),
              ),
              // pageBuilder: (context, animation, secondaryAnimation) {
              //   return Scaffold(
              //     backgroundColor: Colors.transparent,
              //     body: SafeArea(
              //       child: Stack(
              //         children: <Widget>[
              //           Text('text'),
              //           //...
              //         ],
              //       ),
              //     ),
              //   );
              // },
            ).then((value) {
              print('Page2_Contacts bFlash = $bFlash');
              if (bFlash) {
                setState(() {});
              }
            });
          },
        ),
        Divider(
          height: 1.0,
        ),
      ],
    );
  }

  @override
  Widget build(BuildContext context) {


    return Scaffold(
      body: Container(
        child: Column(
          children: <Widget>[
            Expanded(
              //Flutter Column套ListView不显示，可将ListView用Expanded包裹起来。
              child: ListView.builder(
                itemCount: listMessagesInbox2.length,
                itemBuilder: _getListTile,
              ),
            ),
          ],
        ),
      ),
    );
  }
}
