
import 'package:flutter/material.dart';
import 'package:bot_toast/bot_toast.dart';
import 'package:flutter/rendering.dart';

import 'package:twong/router/index.dart';
import 'package:twong/utils/index.dart';
import 'package:twong/config/protocols.dart';
import 'package:twong/widgets/round_check_box.dart';

class RegisterPage extends StatefulWidget {
  @override
  State<StatefulWidget> createState() {
    return _RegisterPageState();
  }
}

class _RegisterPageState extends State<RegisterPage> {
  bool read = false;
  TextEditingController _controller = TextEditingController();

  _onGetCodeClick (String phone) {
    if(!read) {
      BotToast.showText(text:"请先阅读并勾选同意协议!");
      return;
    }
    if(phone.trim() == '') {
      BotToast.showText(text:"手机号不能为空!");
      return;
    }
//    Http.inst.getVerifyCode();
  }

  wechatLogin () {
    Utils.notOpen();
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Container(
        decoration: BoxDecoration(
            image: DecorationImage(
              fit: BoxFit.cover,
              image: AssetImage('assets/images/launcher.png'),
            )
        ),
        child: Flex(
          direction: Axis.vertical,
          children: <Widget>[
            Container(
              padding: EdgeInsets.only(top: 24),
              alignment: Alignment.topRight,
              child: FlatButton(
                child: Text('跳过，看好货 >', style: TextStyle(color: Colors.white),),
                onPressed: () {
                  Navigator.pop(context);
                },),
            ),
            Container(
              height: 100.px,
              margin: EdgeInsets.only(bottom: 60.px, top: 10.px),
              child: Center(
                child: Image.asset("assets/images/logo.png"),
              ),
            ), Container(
                padding: EdgeInsets.only(left: 30, right: 30, top: 10.px),
                child: TextField(
                  autofocus: true,
                  controller: _controller,
                  textAlign: TextAlign.center,
                  onSubmitted: _onGetCodeClick,
                  keyboardType: TextInputType.phone,
                  style: TextStyle(color: Colors.white),
                  textInputAction: TextInputAction.done,
                  decoration: InputDecoration(
                    filled: true,
                    hintText: '请输入手机号码',
                    border: InputBorder.none,
                    hintStyle: TextStyle(color: Colors.white70),
                    enabledBorder: OutlineInputBorder(
                      borderSide: BorderSide(color: Color(0x00FF00a0)),
                      borderRadius: BorderRadius.all(
                        Radius.circular(100),
                      ),
                    ),
                    focusedBorder: OutlineInputBorder(
                      borderSide: BorderSide(color: Color(0x000000a0)),
                      borderRadius: BorderRadius.all(
                        Radius.circular(100),
                      ),
                    ),
                    contentPadding: EdgeInsets.all(10.px),
                  ),
                )
            ),
            Container(
              width: 200.px,
              height: 50.px,
              padding: EdgeInsets.only(top: 10),
              child: RaisedButton(child: Text('获取验证码'), onPressed: () {
                _onGetCodeClick(_controller.text);
              },
                  shape: StadiumBorder()
              ),
            ),
            Container(
              padding: EdgeInsets.only(right: 20, bottom: 20),
              alignment: Alignment.topRight,
              child: GestureDetector(
                  child: Text('遇到问题?', style: TextStyle(color: Colors.white)),
                  onTap: () {
                    Utils.notOpen();
                  }),
            ),
            Text('其他登录方式', style: TextStyle(color: Colors.white)),
            Expanded(child: Container(
              padding: EdgeInsets.only(top: 30),
              child: Flex(
                direction: Axis.horizontal,
                children: <Widget>[
                  Spacer(),
                  Container(width: 46, height: 46,
                      child: GestureDetector(
                        onTap: () => wechatLogin(),
                        child: Image.asset("assets/images/wechat.png"),
                      )
                  ),
                  Spacer(),
                ],
              ),
            )),
            Container(
              margin: EdgeInsets.only(bottom: 32.px),
              child: Row(
                mainAxisAlignment: MainAxisAlignment.center,
                children: <Widget>[
                  Text("注册即视为已阅读并同意",
                      style: TextStyle(fontSize: 12.px, color: Colors.white54)),
                  GestureDetector(
                    onTap: () {
                      Navigator.pushNamed(context, RouteNames.protocol,
                          arguments: ProtocolType.USER);
                    },
                    child: Text("《用户注册协议》",
                        style: TextStyle(fontSize: 12.px, color: Colors.white)),
                  ),
                  Text(
                      "和", style: TextStyle(fontSize: 12.px, color: Colors.white54)),
                  GestureDetector(
                    onTap: () {
                      Navigator.pushNamed(context, RouteNames.protocol,
                          arguments: ProtocolType.VIP);
                    },
                    child: Text("《天旺会员隐私政策》",
                        style: TextStyle(fontSize: 12.px, color: Colors.white)),
                  ),
                ],
              ),
            ),
          ],
        ),
      ),
    );
  }
}