
import 'package:flutter/material.dart';
import 'package:provider/provider.dart';
import 'package:twong/api/index.dart';
import 'package:twong/models/index.dart';
import 'package:twong/providers/message.dart';
import 'package:twong/widgets/app_bar.dart';

class MessagePage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _MessageState();
  }
}
class _MessageState extends State<MessagePage> {

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

  void loadData() async {
    // Network.inst.getMessage().then((res) {
    //   Provider.of<MessageModel>(context, listen: false).update(res);
    // });
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: DAppBar("消息"),
      body: SafeArea(
        child: Consumer<MessageModel>(
          builder: (context, model, child) => _buildMessages(model.data),
        ),
      )
    );
  }

  Widget _buildMessages(List<Message> list) {
    if(list == null) return Container();
    List<Widget> widgets = List<Widget>();
    for(var item in list){
      widgets.add(Container(
        child: Text(item.subject),
      ));
    }

    return Container(
      child: Column(children: widgets),
    );
  }
}