import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';

class MyDrawer extends StatefulWidget {
  final List list;
  final bool isGrade;
  final ValueChanged<dynamic> onChanged;
  final Function refresh;

  MyDrawer({required this.list, required this.isGrade, required this.onChanged,required this.refresh,Key? key}) : super(key: key);

  @override
  State<MyDrawer> createState() => _MyDrawerState();
}

class _MyDrawerState extends State<MyDrawer> {
  @override
  void dispose() {
   widget.refresh();
    super.dispose();
  }

  @override
  Widget build(BuildContext context) {
    return Container(
      // margin:EdgeInsets.only(top: 100.r),
      child: Drawer(
          width: MediaQuery.of(context).size.width / 2 - 20.r,
          child: Padding(
            padding: EdgeInsets.only(top: MediaQuery.of(context).padding.top + 50.r),
            child: Column(
              children: [
                Text(widget.isGrade?'年级':'考试类别',style: TextStyle(fontSize: 16.sp,fontWeight: FontWeight.w500),),
                Expanded(
                  child: ListView.builder(
                    itemBuilder: (BuildContext context, int index) {
                      var item = widget.list[index];
                      return InkWell(
                        onTap: (){
                          widget.onChanged(item);
                          Navigator.pop(context);
                        },
                        child: Padding(
                          padding: EdgeInsets.symmetric(vertical: 20.r),
                          child: Center(
                              child: Text(item.text,style: TextStyle(fontSize: 14.sp,fontWeight: FontWeight.w400,color: item.isCheck?Color(0xFF5F81FD):Color(0xFF2E2E2E)),)),
                        ),
                      );
                    },
                    itemCount: widget.list.length,
                  ),
                ),
              ],
            ),
          )),
    );
  }
}
