import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:liftmanager/internal/message/model/message_list_entity.dart';
import 'package:liftmanager/net/api_service.dart';
import 'package:liftmanager/res/colors.dart';
import 'package:liftmanager/res/gaps.dart';
import 'package:liftmanager/utils/theme_utils.dart';
import 'package:liftmanager/utils/toast.dart';
import 'package:liftmanager/widgets/app_bar.dart';

class MessageDetailPage extends StatefulWidget {
  MessageDetailPage(this.id);

  final String id;

  @override
  State<StatefulWidget> createState() {
    return MessageDetailPageState();
  }
}

class MessageDetailPageState extends State<MessageDetailPage> {
  MessageListItem item = MessageListItem();

  @override
  void initState() {
    super.initState();
    getNewsDetail();
  }

  getNewsDetail() {
    ApiService(context: context).messageDetail(widget.id, onSuccess: (res) {
      item = res;
      setState(() {});
    }, onError: (code, msg) {
      toasts(msg);
    });
  }

  @override
  Widget build(BuildContext context) {
    bool isDark = ThemeUtils.isDark(context);
    return Scaffold(
      backgroundColor: ThemeUtils.getTabsBg(context),
      appBar: MyAppBar(
        centerTitle: "消息详情",
      ),
      body: SafeArea(
          child: item.id.length == 0
              ? Container()
              : ListView(
            padding: EdgeInsets.fromLTRB(15, 18, 15, 18),
//              mainAxisAlignment: MainAxisAlignment.start,
//              crossAxisAlignment: CrossAxisAlignment.start,
            children: <Widget>[
              Text(
                "${item.content}",
                style: TextStyle(
                    fontSize: 15,
                    color: isDark ? Colours.dark_text : Colours.text,
                    fontWeight: FontWeight.w500),
              ),
              Container(
                padding: EdgeInsets.only(top: 10, bottom: 10),
                child: Row(
                  children: <Widget>[
                    Text(
                      "${item.createTime}",
                      style: TextStyle(
                          fontSize: 11, color: Color(0xFF999999)),
                    ),
                    Gaps.hGap10,
//                    Text(
//                      "${item.viewFlag==1?'已读':''}",
//                      style: TextStyle(
//                          fontSize: 11, color: Color(0xFF999999)),
//                    ),
                  ],
                ),
              ),
            ],
          )),
    );
  }
}
