import 'package:betting/commom/utils/color_utils.dart';
import 'package:betting/commom/utils/textstyle.dart';
import 'package:betting/routes/app_pages.dart';
import 'package:betting/view/mobile/favourites_view/teams/team_info_view/news_view/news_controller.dart';
import 'package:betting/view/mobile/home_page/home_controller.dart';
import 'package:flutter/material.dart';
import 'package:get/get.dart';

class NewsView extends StatelessWidget {
  NewsView({Key? key}) : super(key: key);
  final newsController = Get.put(NewsTeamController());

  @override
  Widget build(BuildContext context) {
    return RefreshIndicator(
      onRefresh: () async {
        Get.find<HomeController>().onRefreshPressed();

      },
      color: ColorUtils.PRIMARY_COLOR,
      child: ListView.builder(
        itemCount: newsController.news.length,
        itemBuilder: (context, index) {
          return GestureDetector(
            onTap: () {
              Get.toNamed(Routes.detailNews);
            },
            child: Container(
              padding: const EdgeInsets.all(8),
              width: Get.width,
              height: 120,
              margin: const EdgeInsets.only(top: 10),
              child: Row(
                crossAxisAlignment: CrossAxisAlignment.start,
                children: [
                  ClipRRect(
                    borderRadius:
                    const BorderRadius.all(Radius.circular(8)),
                    child: Image.network( newsController.news[index]['image'],
                      width: 100,
                      height: 100,
                      fit: BoxFit.cover,
                    ),
                  ),
                  const SizedBox(
                    width: 10,
                  ),
                  Expanded(
                    child: Column(
                      crossAxisAlignment: CrossAxisAlignment.start,
                      children: [
                        Text(newsController.news[index]['title'] ,
                            textAlign: TextAlign.left,
                            overflow: TextOverflow.ellipsis,
                            style: TextStyleUtils.sizeText14Weight500()
                                ?.copyWith(
                                height: 1.3, color: Colors.white),
                            maxLines: 3),
                        const SizedBox(
                          height: 10,
                        ),
                        Container(
                          alignment: Alignment.bottomRight,
                          child: Text(newsController.news[index]['time'],
                              style: TextStyleUtils.sizeText10Weight400()
                                  ?.copyWith(color: Colors.white60),
                          textAlign: TextAlign.end,),
                        )
                      ],
                    ),
                  ),
                ],
              ),
            ),
          );
      },),
    );
  }
}
