import 'package:farmer_client/pages/infomation/widgets/Information/index.dart';
import 'package:farmer_client/widgets/layout/BasicPage.dart';
import 'package:flutter/material.dart';
import 'package:get/get_rx/src/rx_types/rx_types.dart';
import 'package:get/get_state_manager/get_state_manager.dart';

import '../../models/entities/NewsInformationModel.dart';
import '../../services/news.dart';

class Infomation extends BasicPage {
  // List<NewsInformationModel> newsListItem=[];

  Infomation({Key? key}) : super(key: key) {
    tabIndex = 2;
    naviTitle = '资讯';
  }

  final newsListItem = Rx<List<NewsInformationModel>>([]);

@override
  void beforeShow() {

    // TODO: implement beforeShow
    super.beforeShow();
  getNewsList().then((value) {
    final list = <NewsInformationModel>[];

     value['records'].forEach((item) {
       list.add(NewsInformationModel.fromJson(item));
       print('newsListItem');

       print(newsListItem.value);

     });
    newsListItem.value=list;

  });
}

  @override
  Widget builder(BuildContext context) {

    return Container(
        child:
            Obx(()=>
          Column(
            mainAxisSize: MainAxisSize.min,
            children:newsListItem.value.map((item) => Information(item: item,)).toList(),
          )

            )
    );


  }
}