import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:get/get.dart';
import 'package:making_school_asignment_app/page/global_widget/ReturnToHomepage.dart';
import 'package:making_school_asignment_app/page/global_widget/my_text.dart';
import 'package:making_school_asignment_app/page/home_page/children/annotate_class/annotate_class_logic.dart';

import 'components/bottom_operation_bar.dart';
import 'components/button_floating_action.dart';
import 'components/dropdown_switch_students_type.dart';
import 'components/favorite_widget.dart';
import 'components/question_paper_view.dart';
import 'configuration_files/index.dart';

class HomeworkReview extends StatefulWidget {
  const HomeworkReview({super.key});

  @override
  State<HomeworkReview> createState() => _HomeworkReviewState();
}

class _HomeworkReviewState extends State<HomeworkReview> {
  final logic = Get.find<HomeworkReviewLogic>();
  final sateData = Get.find<HomeworkReviewLogic>().state;
  final AnnotateClassLogic _controller = Get.find<AnnotateClassLogic>();

  @override
  void initState() {
    WidgetsFlutterBinding.ensureInitialized();
    super.initState();
  }

  @override
  void dispose() {
    Get.delete<HomeworkReviewLogic>();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return PopScope(
      canPop: false,
      onPopInvoked: (e) {
        if (e && sateData.needRefresh) _controller.getList();
      },
      child: SafeArea(
        child: Scaffold(
          appBar: AppBar(
            // titleSpacing: 0,
            leading: IconButton(icon: const Icon(Icons.arrow_back_ios), onPressed: () => Get.back()),
            iconTheme: const IconThemeData(color: Colors.black),
            title: quickText(sateData.param.value.homeworkName),
            backgroundColor: Colors.white,
            elevation: 0,
            actions: [const FavoriteWidget(), SizedBox(width: 5.w), const ReturnToHomepage()],
          ),
          body: SafeArea(
            child: Column(
              children: [
                // 下拉切换
                const DropdownSwitchStudentsType(),
                SizedBox(height: 1.h),
                const Expanded(child: QuestionPaperView()),
                const BottomAnnotationSwitch()
              ],
            ),
          ),
          // floatingActionButton: const ButtonFloatingAction(),
          // floatingActionButtonLocation: FloatingActionButtonLocation.startFloat,
        ),
      ),
    );
  }
}
