import 'package:carousel_slider/carousel_slider.dart'; import 'package:flutter/cupertino.dart'; import 'package:flutter/material.dart'; import 'package:flutter/widgets.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:get/get.dart'; import 'package:starwork_flutter/base/app_permission.dart'; import 'package:starwork_flutter/views/home/widget/home_attendance_chart_area_widget.dart'; import 'package:starwork_flutter/views/home/widget/home_carousel_area_widget.dart'; import 'package:starwork_flutter/views/home/widget/home_function_list_area_widget.dart'; import 'package:starwork_flutter/views/home/widget/home_left_drawer_widget.dart'; import 'package:starwork_flutter/views/home/widget/home_one_button_door_opening_widget.dart'; import 'package:starwork_flutter/views/home/widget/home_statistics_row_widget.dart'; import 'package:starwork_flutter/views/home/widget/home_team_notice_row_widget.dart'; import 'home_controller.dart'; class HomeView extends GetView { const HomeView({super.key}); static final GlobalKey _scaffoldKey = GlobalKey(); @override Widget build(BuildContext context) { return Obx( () => Container( decoration: BoxDecoration( gradient: LinearGradient( begin: Alignment.topCenter, // 渐变起点:顶部中心 end: Alignment.bottomCenter, // 渐变终点:底部中心 colors: [ controller.currentGradientColor.value, // 动态颜色 const Color(0xFFF6F7FB), // 底部颜色保持不变 ], stops: const [0.1, 1.0], // 第一个颜色到10%,然后第二个颜色开始直到100% ), ), child: Scaffold( key: _scaffoldKey, backgroundColor: Colors.transparent, body: SafeArea( child: Container( width: 1.sw, padding: EdgeInsets.symmetric(horizontal: 15.w, vertical: 4.h), child: Column( children: [ // 固定的上半部分 _buildPageHead(context), SizedBox( height: 10.h, ), _buildSystemNotificationPermissionRow(), // 可滚动的下半部分 Expanded( child: SingleChildScrollView( child: Column( mainAxisSize: MainAxisSize.min, children: [ HomeCarouselAreaWidget( carouselCurrentIndex: controller.carouselCurrentIndex, ), HomeTeamNoticeRowWidget(), HomeStatisticsRowWidget( personCount: 12, deviceCount: 1, ), SizedBox(height: 10.h), HomeFunctionListAreaWidget(), SizedBox( height: 10.h, ), HomeOnButtonDoorOpeningWidget( doorList: const [ '主门门禁', '车库门禁', '后门门禁', '单元门门禁', ], ), SizedBox( height: 10.h, ), HomeAttendanceChartAreaWidget(), SizedBox( height: 10.h, ), ], ), ), ), ], ), ), ), drawer: HomeLeftDrawerWidget( teamList: ['家庭群组', '测试团队1', '测试团队2'], ), ), ), ); } _buildPageHead(BuildContext context) { return GestureDetector( onTap: () { _scaffoldKey.currentState?.openDrawer(); }, child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, children: [ Row( mainAxisSize: MainAxisSize.min, mainAxisAlignment: MainAxisAlignment.center, children: [ Text( '19104656的互联', style: TextStyle( fontSize: 18.sp, fontWeight: FontWeight.w500, ), ), Icon( Icons.arrow_right_rounded, size: 22.sp, ) ], ), Icon( Icons.add_circle_outline, size: 22.sp, ), ], ), ); } _buildSystemNotificationPermissionRow() { return Obx( () => Visibility( visible: !controller.isOpenNotificationPermission.value, child: Container( padding: EdgeInsets.symmetric(horizontal: 10.w, vertical: 4.h), decoration: BoxDecoration( color: const Color(0xFFFEF2E5), borderRadius: BorderRadius.all( Radius.circular(8.r), ), ), margin: EdgeInsets.symmetric(vertical: 8.h), child: Row( mainAxisAlignment: MainAxisAlignment.spaceBetween, crossAxisAlignment: CrossAxisAlignment.center, children: [ Text( '系统通知未开启,报警消息无法通知'.tr, style: TextStyle( color: const Color(0xFFEE9846), fontSize: 12.sp, ), ), const Spacer(), GestureDetector( onTap: () async { controller.isOpenNotificationPermission.value = await AppPermission.requestNotificationPermission(); }, child: Container( padding: EdgeInsets.symmetric(horizontal: 6.w, vertical: 4.h), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.all( Radius.circular(4.r), ), ), child: Text( '去开启'.tr, style: TextStyle( color: const Color(0xFFEE9846), fontSize: 12.sp, ), ), ), ), SizedBox( width: 14.w, ), Icon( Icons.cancel, color: const Color(0xFFEE9846), size: 18.sp, ) ], ), ), ), ); } }