import 'package:eitc_erm_app/utils/Constants.dart';
import 'package:flutter/material.dart';
import 'package:flutter_html/flutter_html.dart';

import 'bean/notice_manage_list.dart';
import 'notice_detail.dart';

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

NoticeManageList mNoticeManageList = new NoticeManageList();

class NoticeList extends StatefulWidget {
  NoticeList(noticeManageList, {super.key}) {
    mNoticeManageList = noticeManageList;
  }

  @override
  State<StatefulWidget> createState() => NoticeListState();
}

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

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: const Text('公告',
            style: TextStyle(
              color: Colors.white,
            )),
        centerTitle: true,
        elevation: 0.5,
        backgroundColor: Global.StatusBarColor,
        leading: 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 GestureDetector(
            child: Card(
                color: Colors.white,
                child: Padding(
                  padding: const EdgeInsets.all(10),
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: [
                      Text(
                        mNoticeManageList.data![index].noticeTitle ?? "",
                        style: Theme.of(context).textTheme.titleLarge,
                      ),
                      const SizedBox(
                        height: 5.0,
                      ),
                      Align(
                        alignment: Alignment.centerRight,
                        child: Text(
                          mNoticeManageList.data![index].noticeStartTime ?? "",
                          style: Theme.of(context)
                              .textTheme
                              .bodySmall
                              ?.copyWith(color: Colors.grey),
                        ),
                      ),
                      const SizedBox(
                        height: 5.0,
                      ),
                      Html(
                        data: mNoticeManageList.data![index].noticeContent,
                      ),
                      Align(
                        alignment: Alignment.bottomRight,
                        child: Text(
                          "查看详情",
                          style: Theme.of(context)
                              .textTheme
                              .bodyMedium
                              ?.copyWith(color: Global.StatusBarColor),
                        ),
                      ),
                    ],
                  ),
                )),
            onTap: () {
              Navigator.push(
                context,
                MaterialPageRoute(
                    builder: (context) =>
                        NoticeDetail(mNoticeManageList, index)),
              );
            },
          );
        },
      )),
    );
  }
}
