import 'package:eitc_erm_app/record_registration.dart';
import 'package:eitc_erm_app/utils/Constants.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:permission_handler/permission_handler.dart';

import 'home.dart';

/*void main() {
  WidgetsFlutterBinding.ensureInitialized();
  runApp(SuccessRegistration());
}*/

String mPatient = "";
String mVisitTime = "";
String mDeptName = "";
String mDoctorName = "";
String mRemark = "";

class SuccessRegistration extends StatefulWidget {
  SuccessRegistration(
      {required Key key, required patient, required visitTime, required deptName, required doctorName, required remark})
      : super(key: key) {
    mPatient = patient;
    mVisitTime = visitTime;
    mDeptName = deptName;
    mDoctorName = doctorName;
    mRemark = remark;
  }
  @override
  State<StatefulWidget> createState() => SuccessRegistrationState();
}

class SuccessRegistrationState extends State<SuccessRegistration> {
  final GlobalKey<ScaffoldState> _scaffoldKey =
      GlobalKey<ScaffoldState>(); //重要代码 需要绑定key不然切换页面会停止摄像头采集

  @override
  void initState() {
    super.initState();

    initPlatformState(); //检查权限

    //延迟1秒 直播推流
    Future.delayed(Duration(milliseconds: 1000), () {});
  }

  Future<void> initPlatformState() async {
    //相机权限
    if (await requestCameraPermission() == false) {
      return;
    }
    //录音权限
    if (await requestMicrophonePermission() == false) {
      return;
    }
  }

  Future<bool> requestCameraPermission() async {
    var status = await Permission.camera.status;
    if (status == PermissionStatus.granted) {
      return true;
    } else {
      status = await Permission.camera.request();
      if (status == PermissionStatus.granted) {
        return true;
      } else {
        return false;
      }
    }
  }

  Future<bool> requestMicrophonePermission() async {
    var status = await Permission.microphone.status;
    if (status == PermissionStatus.granted) {
      return true;
    } else {
      status = await Permission.microphone.request();
      if (status == PermissionStatus.granted) {
        return true;
      } else {
        return false;
      }
    }
  }

  @override
  Widget build(BuildContext context) {
    return MaterialApp(
        home: Scaffold(
            resizeToAvoidBottomInset: false,
            backgroundColor: Global.BackgroundColor,
            appBar: new AppBar(title: new Text('预约挂号'), centerTitle: true),
            body: SingleChildScrollView(
    child:Container(
                padding: EdgeInsets.all(10),
                child: Column(
                    mainAxisSize: MainAxisSize.min,
                    crossAxisAlignment: CrossAxisAlignment.center,
                    children: <Widget>[
                      ClipRRect(
                        borderRadius: BorderRadius.circular(10.0),
                        child: Container(
                          color: Global.BackgroundColor,
                          padding: EdgeInsets.all(10),
                          child: const Column(
                              mainAxisSize: MainAxisSize.min,
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: <Widget>[
                                Padding(
                                  padding: EdgeInsets.all(10),
                                  child: Icon(
                                    Icons.check_circle,
                                    size: 85.0, // 设置Icon的大小
                                    color: Colors.blueAccent, // 设置Icon的颜色
                                  ),
                                ),
                                Text(
                                  '挂号成功',
                                  style: TextStyle(
                                    fontSize: 28,
                                    color: Colors.blue,
                                  ),
                                )
                              ]),
                        ),
                      ),
                      SizedBox(height: 8),
                      ClipRRect(
                        borderRadius: BorderRadius.circular(10.0),
                        child: Container(
                          color: Colors.white,
                          padding: const EdgeInsets.all(10),
                          child: Column(
                              mainAxisSize: MainAxisSize.min,
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: <Widget>[
                                /*Padding(
                                  padding: EdgeInsets.all(10),
                                  child: Row(
                                      mainAxisAlignment:
                                          MainAxisAlignment.spaceBetween,
                                      children: [
                                        Text(
                                          '挂号费',
                                          style: TextStyle(
                                              fontSize: 15, color: Colors.grey),
                                        ),
                                        Text(
                                          '¥12.5',
                                          style: TextStyle(fontSize: 15),
                                        ),
                                      ]),
                                ),*/
                                Padding(
                                  padding: EdgeInsets.all(10),
                                  child: Row(
                                      mainAxisAlignment:
                                          MainAxisAlignment.spaceBetween,
                                      children: [
                                        Text(
                                          '就诊人',
                                          style: TextStyle(
                                              fontSize: 15, color: Colors.grey),
                                        ),
                                        Text(
                                          mPatient,
                                          style: TextStyle(fontSize: 15),
                                        ),
                                      ]),
                                ),
                                Padding(
                                  padding: EdgeInsets.all(10),
                                  child: Row(
                                      mainAxisAlignment:
                                          MainAxisAlignment.spaceBetween,
                                      children: [
                                        Text(
                                          '就诊时间',
                                          style: TextStyle(
                                              fontSize: 15, color: Colors.grey),
                                        ),
                                        Text(
                                          mVisitTime,
                                          style: TextStyle(fontSize: 15),
                                        ),
                                      ]),
                                ),
                                Padding(
                                  padding: EdgeInsets.all(10),
                                  child: Row(
                                      mainAxisAlignment:
                                          MainAxisAlignment.spaceBetween,
                                      children: [
                                        Text(
                                          '挂号科室',
                                          style: TextStyle(
                                              fontSize: 15, color: Colors.grey),
                                        ),
                                        Text(
                                          mDeptName,
                                          style: TextStyle(fontSize: 15),
                                        ),
                                      ]),
                                ),
                                Padding(
                                  padding: EdgeInsets.all(10),
                                  child: Row(
                                      mainAxisAlignment:
                                          MainAxisAlignment.spaceBetween,
                                      children: [
                                        Text(
                                          '医生姓名',
                                          style: TextStyle(
                                              fontSize: 15, color: Colors.grey),
                                        ),
                                        Text(
                                          mDoctorName,
                                          style: TextStyle(fontSize: 15),
                                        ),
                                      ]),
                                ),
                              ]),
                        ),
                      ),
                      SizedBox(height: 8),
                      ClipRRect(
                        borderRadius: BorderRadius.circular(10.0),
                        child: Container(
                          color: Colors.white,
                          padding: const EdgeInsets.all(10),
                          child: Column(
                              mainAxisSize: MainAxisSize.min,
                              crossAxisAlignment: CrossAxisAlignment.start,
                              children: <Widget>[
                                Padding(
                                  padding: EdgeInsets.all(10),
                                  child: Row(
                                      mainAxisAlignment:
                                          MainAxisAlignment.spaceBetween,
                                      children: [
                                        Expanded(
                                          child: TextField(
                                            maxLines: 5, // 设置最大行数
                                            enabled: false,
                                            decoration: InputDecoration(
                                              border: OutlineInputBorder(),
                                              hintText: mRemark,
                                            ),
                                          ),
                                        ),
                                      ]),
                                ),
                              ]),
                        ),
                      ),
                      Padding(
                        padding: EdgeInsets.all(10),
                        child: Row(
                            mainAxisAlignment: MainAxisAlignment.spaceEvenly,
                            children: [
                              ElevatedButton(
                                style: ButtonStyle(
                                  backgroundColor:
                                      MaterialStateProperty.all(Colors.white),
                                ),
                                child: Text(
                                  '返回',
                                  style: const TextStyle(
                                      fontSize: 15, color: Colors.black),
                                ),
                                onPressed: () {
                                  Navigator.pop(context);
                                },
                              ),
                              ElevatedButton(
                                style: ButtonStyle(
                                  backgroundColor:
                                      MaterialStateProperty.all(Colors.blue),
                                ),
                                child: Text(
                                  '预约列表',
                                  style: const TextStyle(
                                      fontSize: 15, color: Colors.white),
                                ),
                                onPressed: () {
                                  Navigator.push(
                                    context,
                                    MaterialPageRoute(
                                        builder: (context) => RecordRegistration()),
                                  );
                                },
                              ),
                            ]),
                      ),
                    ])))));
  }
}
