import 'dart:convert';
import 'dart:io';
import 'dart:typed_data';

import 'package:eitc_erm_app/utils/Component.dart';
import 'package:eitc_erm_app/utils/Constants.dart';
import 'package:eitc_erm_app/widget/loading.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';
import 'package:fluttertoast/fluttertoast.dart';
import 'package:http/http.dart' as http;

import 'bean/favourite_doctor_list.dart';
import 'bean/message_box_s_list_entity.dart';
import 'bean/normal_response.dart';
import 'bean/notice_manage_list.dart';
import 'bean/pda_patrol_time_list.dart';
import 'doctor_detail.dart';
import 'notice_detail.dart';

void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(NoticeList(""));
}

NoticeManageList mNoticeManageList = new NoticeManageList();

class NoticeList extends StatefulWidget {
  NoticeList(noticeManageList) {
    mNoticeManageList = noticeManageList;
  }
  @override
  State<StatefulWidget> createState() => NoticeListState();
}

class NoticeListState extends State<NoticeList> {
  @override
  void initState() {
    super.initState();
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: Scaffold(
        appBar: new AppBar(
          title: new Text('公告',
              style: TextStyle(
                color: Colors.white,
              )),
          centerTitle: true,
          elevation: 0.5,
          backgroundColor: Global.StatusBarColor,
          leading: new IconButton(
            tooltip: '返回上一页',
            icon: const Icon(
              Icons.arrow_back_ios,
              color: Colors.white,
            ),
            onPressed: () {
              Navigator.of(context).pop();
              //_nextPage(-1);
            },
          ),
        ),
        body: Center(
            child: ListView.builder(
          itemCount: mNoticeManageList.data?.length,
          itemBuilder: (context, index) {
            return Container(
              margin: const EdgeInsets.all(8),
              width: double.infinity,
              decoration: BoxDecoration(
                color: Colors.white,
                borderRadius: BorderRadius.circular(3.0),
                boxShadow: [
                  BoxShadow(
                    color: Colors.black54,
                    offset: Offset(5.0, 5.0),
                    blurRadius: 5.0,
                  ),
                ],
              ),
              child: ListTile(
                title: Expanded(
                  child: Column(
                      mainAxisAlignment: MainAxisAlignment.start,
                      mainAxisSize: MainAxisSize.max,
                      children: [
                        SizedBox(
                          height: 20,
                        ),
                        Container(
                          width: MediaQuery.of(context).size.width - 50,
                          child: Text(
                            mNoticeManageList.data![index].noticeTitle
                                .toString(),
                            style: const TextStyle(fontSize: 18),
                            maxLines: 3,
                          ),
                        ),
                        Text(
                          mNoticeManageList.data![index].noticeStartTime
                              .toString(),
                          style: const TextStyle(
                              fontSize: 15, color: Colors.orange),
                          maxLines: 1,
                          textAlign: TextAlign.left,
                        ),
                        SizedBox(
                          height: 5,
                        ),
                        Row(children: [
                          Padding(
                            padding: EdgeInsets.fromLTRB(0, 0, 0, 0),
                            child: Container(
                              width: MediaQuery.of(context).size.width - 60,
                              child: Html(
                                data: mNoticeManageList.data![index].noticeContent,
                              ),
                            ),
                          ),
                        ]),
                      ]),
                ),
                subtitle: Padding(
                  padding: EdgeInsets.fromLTRB(0, 20, 10, 0),
                  child: Text(
                    "查看详情",
                    style: const TextStyle(fontSize: 15, color: Colors.blue),
                    textAlign: TextAlign.right,
                  ),
                ),
                onTap: () {
                  Navigator.push(
                          context,
                          MaterialPageRoute(builder: (context) => NoticeDetail(mNoticeManageList, index)),
                        );
                },
              ),
            );
          },
        )),
      ),
    );
  }
}
