import 'package:flutter/material.dart';
import 'package:flutter/cupertino.dart';
import '../styles/colors.dart';
import 'dart:ui';
import '../styles/totast.dart';
import 'LoginSecond.dart';
import '../utils/Utils.dart';
import '../widget/LinearButton.dart';
import '../net/HttpManager.dart';
import '../net/Result.dart';
import '../utils/Utils.dart';

class LoginFirst extends StatefulWidget {
  @override
  LoginFirstState createState() => LoginFirstState();
}

class LoginFirstState extends State<LoginFirst> {
  String inputVal;

 

  @override
  void initState() {
    super.initState();
    Future.delayed(Duration.zero, () {
      getVersion(context);
    });
  }

  @override
  Widget build(BuildContext context) {
    return WillPopScope(
        child: Scaffold(
            body: Container(
          color: BG_SUB_COLOR,
          child: CustomScrollView(
            slivers: <Widget>[
              SliverAppBar(
                backgroundColor: BG_SUB_COLOR,
                centerTitle: true,
                elevation: 0,
                leading: Container(),
              ),
              SliverToBoxAdapter(
                child: Container(
                  width: double.infinity,
                  padding: EdgeInsets.symmetric(vertical: 20, horizontal: 15),
                  color: BG_SUB_COLOR,
                  child: Column(
                    crossAxisAlignment: CrossAxisAlignment.start,
                    children: <Widget>[
                      // Text(
                      //   'LOGO',
                      //   style: TextStyle(
                      //     color: Colors.white,
                      //     fontSize: 64,
                      //   ),
                      // ),
                      Image.asset('images/icon_logo.png'),
                      Container(
                        margin: EdgeInsets.only(top: 30),
                        child: Text('手机账号登录', style: TextStyle(color: Colors.white, fontSize: 28, fontWeight: FontWeight.w500)),
                      ),
                      Container(
                          margin: EdgeInsets.only(top: 20),
                          child: TextField(
                              autofocus: true,
                              keyboardType: TextInputType.phone,
                              maxLength: 11,
                              style: TextStyle(color: Colors.white, fontSize: 18, fontWeight: FontWeight.w500),
                              decoration: InputDecoration(
                                  hintText: '输入手机号',
                                  hintStyle: TextStyle(
                                    fontSize: 16,
                                    color: Color(0xFF727785),
                                  ),
                                  prefixIcon: Container(
                                    padding: EdgeInsets.all(10),
                                    // color: PRIMARY_COLOR,
                                    child: Image.asset(
                                      'images/list_icon_shouji.png',
                                      width: 20,
                                    ),
                                  ),
                                  // suffixIcon:Container(
                                  //   padding: EdgeInsets.all(10),
                                  //   // color: PRIMARY_COLOR,
                                  //   child: Image.asset(
                                  //     'images/list_icon_shouji.png',
                                  //     width: 20,
                                  //   ),
                                  // ),
                                  counterStyle: TextStyle(color: BG_SUB_COLOR, fontSize: 0)),
                              onChanged: (value) {
                                inputVal = value;
                              })),
                      // Text('未注册的手机号验证后自动创建账户', style: TextStyle(color: Color(0xFF727785), fontSize: 13)),
                      Container(
                        height: 52,
                      ),
                      LinearButton(
                          btntext: '下一步',
                          onTapHomeMenu: () async {
                            if (!checkPhone(inputVal)) {
                              Toast.show(context, '手机号格式错误', 1500, 'info');
                            } else {
                              final Result res = await HttpManager.get('userInfo/getOne', data: {'phone': inputVal});

                              if (res.data != null && res.data['id'] != null) {
                                Navigator.push(
                                  context,
                                  CupertinoPageRoute(
                                    builder: (context) => LoginSecond(phone: inputVal, userId: res.data['id']),
                                  ),
                                );
                              } else {
                                Navigator.push(
                                  context,
                                  CupertinoPageRoute(
                                    builder: (context) => LoginSecond(phone: inputVal, userId: 0),
                                  ),
                                );
                              }
                            }
                          }),

                      //  FlatButton(
                      //   textColor: Colors.white,
                      //   color: PRIMARY_COLOR,
                      //   highlightColor: Color(0xFF763434),
                      //   child: Text('下一步'),
                      //   onPressed: () {
                      //     if (!checkPhone(inputVal)) {
                      //       Toast.show(context, '手机号格式错误', 1500, 'info');
                      //     } else {
                      //       Navigator.push(
                      //         context,
                      //         CupertinoPageRoute(
                      //           builder: (context) => LoginSecond(phone: inputVal),
                      //         ),
                      //       );
                      //     }
                      //   },
                      // ),
                    ],
                  ),
                ),
              )
            ],
          ),
        )),
        onWillPop: () {
          Toast.hide();
          // Navigator.pop(context);
          return Future.value(false);
        });
  }
}
