import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:hyzp_ybqx/components/commonFun.dart';

import '../../../widget/JdButton.dart';

class MyFeedback extends StatefulWidget {
  MyFeedback({Key key}) : super(key: key);

  _LoginPageState createState() => _LoginPageState();
}

class _LoginPageState extends State<MyFeedback> {
  void initState() {
    // TODO: implement initState
    super.initState();
  }

  doOK() {
    Navigator.pop(context); //返回
  }

  int radioSelect = 0;
  String opinionText = '';

  //监听登录页面销毁的事件
  dispose() {
    super.dispose();
  }

  Widget getTextField() {
    return Container(
      decoration: new BoxDecoration(
        color: Colors.white,
        borderRadius: BorderRadius.all(Radius.circular(4.0)),
        border: new Border.all(width: 1, color: Colors.blue),
      ),
      constraints: BoxConstraints(
        maxHeight: 240.0,
        maxWidth: MediaQuery.of(context).size.width,
        minHeight: 240.0,
        minWidth: MediaQuery.of(context).size.width,
      ),
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        crossAxisAlignment: CrossAxisAlignment.start,
        children: <Widget>[
          SizedBox(width: 10),
          Expanded(
            child: TextField(
              style: TextStyle(fontSize: 16),
              keyboardType: TextInputType.multiline,
              maxLines: null,
              //不限制行数
              decoration: InputDecoration(
                hintText: '請輸入反馈问题的详细描述内容',
                border: InputBorder.none, //TextField去掉下划线
                //border: OutlineInputBorder(),
              ),
              onChanged: (val) {
                opinionText = val;
              },
            ),
          ),
          SizedBox(width: 10),
        ],
      ),
    );
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: PreferredSize(
        preferredSize: Size.fromHeight(ScreenUtil().setHeight(173)), // 设置appBar高度
        // 设置appBar高度
        child: AppBar(
          automaticallyImplyLeading: false,
          centerTitle: true,
          titleSpacing: 0.0,
          //设置title的左边距
          flexibleSpace: Container(
            //SizedBox(height: ScreenUtil().statusBarHeight), //显示顶部状态栏
            // SizedBox(height: ScreenUtil().setHeight(10)), //显示顶部状态栏
            padding: EdgeInsets.only(top: ScreenUtil().statusBarHeight), //留出顶部状态栏高度
            child: Container(
              //height: ScreenUtil().setHeight(173),
              decoration: BoxDecoration(
                gradient: LinearGradient(
                  begin: Alignment.centerLeft,
                  end: Alignment.centerRight,
                  colors: [
                    Color.fromRGBO(12, 186, 156, 1),
                    Color.fromRGBO(39, 127, 235, 1),
                  ],
                ),
              ),
              // decoration: BoxDecoration(
              //   gradient: LinearGradient(colors: [
              //     Color(0xFF0018EB),
              //     Color(0xFF01C1D9),
              //   ], begin: Alignment.bottomCenter, end: Alignment.topCenter),
              // ),
            ),
          ),
          title: Padding(
            padding: EdgeInsets.only(left: 0, right: 0),
            child: Row(
              mainAxisAlignment: MainAxisAlignment.start,
              children: [
                getIconAndTextButton(
                  iconColor: Colors.white,
                  iconData: Icons.chevron_left_outlined,
                  onPress: () {
                    Navigator.pop(context);
                  },
                ),
                Expanded(
                  child: Text("意见反馈",
                      style: TextStyle(color: Colors.white, fontSize: 20),
                      textAlign: TextAlign.center,
                      overflow: TextOverflow.ellipsis),
                ),
                SizedBox(width: 50),
              ],
            ),
          ),
        ),
      ),
      body: Container(
        padding: EdgeInsets.only(top: 20, bottom: 20, left: 20, right: 20),
        child: ListView(
          children: <Widget>[
            Center(
              child: Container(
                margin: EdgeInsets.only(top: 10),
                height: ScreenUtil().setWidth(160),
                width: ScreenUtil().setWidth(160),
                //child: Image.asset('assets/images/user.png', fit: BoxFit.cover),
                child: Image.asset('assets/images/ybsthbj.png', fit: BoxFit.fitHeight),
              ),
            ),
            SizedBox(height: 10),
            Text('请选择问题类型'),
            getRadioRow(),
            Text('请輸入问题描述'),
            SizedBox(height: 10),
            getTextField(),
            SizedBox(height: 40),
            JdButton(
              height: 126,
              text: "确认",
              color: Colors.blueAccent,
              onTop: doOK,
            )
          ],
        ),
      ),
    );
  }

  Widget getRadio(int index) {
    return Container(
      alignment: Alignment(1, -1),
      height: 30,
      width: 30,
      child: Radio(
        value: index,
        onChanged: (v) {
          setState(() {
            radioSelect = v;
          });
        },
        groupValue: radioSelect,
      ),
    );
  }

  Widget getRadioRow() {
    return Row(
      mainAxisAlignment: MainAxisAlignment.center,
      children: <Widget>[
        Text(
          "投诉",
          style: TextStyle(
            color: (0 == radioSelect) ? Colors.blue : null,
            fontWeight: (0 == radioSelect) ? FontWeight.bold : null,
          ),
        ),
        getRadio(0),
        SizedBox(width: 25),
        Text(
          "故障",
          style: TextStyle(
            color: (1 == radioSelect) ? Colors.blue : null,
            fontWeight: (1 == radioSelect) ? FontWeight.bold : null,
          ),
        ),
        getRadio(1),
        SizedBox(width: 25),
        Text(
          "建议",
          style: TextStyle(
            color: (2 == radioSelect) ? Colors.blue : null,
            fontWeight: (2 == radioSelect) ? FontWeight.bold : null,
          ),
        ),
        getRadio(2),
        SizedBox(width: 25),
        Text(
          "其他",
          style: TextStyle(
            color: (3 == radioSelect) ? Colors.blue : null,
            fontWeight: (3 == radioSelect) ? FontWeight.bold : null,
          ),
        ),
        getRadio(3),
      ],
    );
  }
}
