import 'package:flutter/cupertino.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:news_getx/modules/main/main_controller.dart'; import 'package:news_getx/theme/app_colors.dart'; class NewsCategoriesWidget extends GetView { @override Widget build(BuildContext context) { // 用的是Row 而不是 Tab return Obx( () => controller.state.categories == null ? Container() : SingleChildScrollView( scrollDirection: Axis.horizontal, child: Row( children: controller.state.categories!.map( (item) { return Container( alignment: Alignment.center, height: 52.h, padding: EdgeInsets.symmetric(horizontal: 8), child: GestureDetector( onTap: () { // 拉取对应分类的数据 controller.asyncLoadNewsData(item.code); }, child: Text( item.title, style: TextStyle( color: controller.state.selCategoryCode == item.code ? AppColors.secondaryElementText : AppColors.primaryText, fontSize: 18.h, fontFamily: 'Montserrat', fontWeight: FontWeight.w600, ), ), ), ); }, ).toList(), ), ), ); } }