| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347 |
- import 'dart:async';
- import 'package:dio/dio.dart';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:get/get.dart';
- import '../constants.dart';
- import '../utils/api.dart';
- import '../utils/http_utils.dart';
- import '../utils/size_fit.dart';
- import 'component/link_btn.dart';
- import 'component/toast.dart';
- import 'component/top_container.dart';
- class Login extends StatefulWidget {
- bool _isBind = false;
- Login({Key? key,bool? isBind}) : super(key: key){
- if (isBind!=null){
- _isBind = isBind;
- }
- }
- @override
- State<Login> createState() => _LoginState();
- }
- class _LoginState extends State<Login> {
- String strContent = '';
- bool isPhoneSignup = true;
- TextEditingController controller = TextEditingController();
- FocusNode focusNode = FocusNode();
- FocusNode blankNode = FocusNode();
- bool checked = true;
- @override
- void initState() {
- // TODO: implement initState
- Map<String, dynamic> data = Get.parameters;
- if (data.isNotEmpty) {
- strContent = data['content']??'';
- isPhoneSignup = data['type'] == 'sms';
- controller.text = strContent;
- }
- WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
- focusNode.requestFocus();
- });
- super.initState();
- }
- @override
- void dispose() {
- // TODO: implement dispose
- focusNode.dispose();
- blankNode.dispose();
- super.dispose();
- }
- showSignupAlert() {
- FocusScope.of(context).requestFocus(blankNode);
- Toast().showCustomHud(
- Container(
- alignment: Alignment.center,
- padding: EdgeInsets.only(top: 32.px, bottom: 32.px),
- child: Column(
- children: [
- Text(
- '该${isPhoneSignup ? '手机号' : '邮箱'}尚未注册!\n不可直接登录,请前往注册',
- textAlign: TextAlign.center,
- style: TextStyle(
- color: Colors.white,
- fontSize: 16.px,
- fontWeight: FontWeight.bold),
- ),
- SizedBox(
- height: 16.px,
- ),
- AlertButton(
- title: '前往注册',
- isCancel: false,
- width: 220.px,
- height: 40.px,
- callback: () {
- Toast().hideHud();
- Get.toNamed('/invite_code');
- }),
- SizedBox(
- height: 24.px,
- ),
- AlertButton(
- title: '返回重新输入',
- isCancel: true,
- width: 220.px,
- height: 40.px,
- callback: () {
- Toast().hideHud();
- }),
- ],
- ),
- ),
- context: context);
- }
- Future sendCode() async {
- if (!checked){
- Toast().showInfoText('请阅读并同意协议', context: context);
- return;
- }
- Toast().showHud(context: context);
- try {
- if (isPhoneSignup) {
- Map<String, dynamic> data = await HttpUtils.get(Api.phoneCanRegister,
- params: {'mobile': strContent});
- if (data['success'] == true) {
- Toast().hideHud();
- showSignupAlert();
- return;
- }
- Map<String, dynamic> data2 = await HttpUtils.post(Api.phoneSendCode,
- data: {'mobile': strContent});
- print(data2.toString());
- } else {
- Map<String, dynamic> data = await HttpUtils.get(Api.emailCanRegister,
- params: {'email': strContent});
- if (data['success'] == true) {
- Toast().hideHud();
- showSignupAlert();
- return;
- }
- Map<String, dynamic> data2 = await HttpUtils.post(Api.emailSendCode,
- data: {'email': strContent});
- print(data2.toString());
- }
- } on DioError catch (e) {
- Toast().hideHud();
- Toast().showInfoText(e.response?.data['error_message'], context: context);
- return;
- }
- // ignore: nullable_type_in_catch_clause
- Toast().hideHud();
- Get.toNamed('/verify_code', parameters: {
- "code": '',
- "type": isPhoneSignup ? 'sms' : 'email',
- "content": strContent
- });
- }
- @override
- Widget build(BuildContext context) {
- SizeFit.initialize(context);
- return Material(
- color: kBgColor,
- child: TopContainer(
- child: Stack(children: [
- Container(
- padding: EdgeInsets.only(top: 71.px),
- child: Column(
- crossAxisAlignment: CrossAxisAlignment.center,
- children: [
- Image.asset(
- 'assets/images/logo.png',
- width: 167.px,
- height: 64.px,
- ),
- SizedBox(
- height: 36.px,
- ),
- Container(
- width: 315.px,
- height: 68.px,
- padding: EdgeInsets.only(left: 16.px, right: 16.px),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.circular(16.px),
- color: const Color(0xFF2C2C2E)),
- child: Row(
- children: [
- if (isPhoneSignup)
- GestureDetector(
- onTap: () {
- Get.toNamed('/choose_country');
- },
- child: Row(
- children: [
- Text(
- '+86',
- style: TextStyle(
- fontFamily: 'Link1',
- color: Colors.white,
- fontSize: 28.px),
- ),
- SizedBox(
- width: 4.px,
- ),
- Image.asset(
- 'assets/images/arrow.png',
- width: 24.px,
- height: 24.px,
- )
- ],
- ),
- ),
- if (isPhoneSignup)
- SizedBox(
- width: 8.px,
- ),
- Expanded(
- child: TextField(
- autofocus: true,
- focusNode: focusNode,
- controller: controller,
- maxLength: isPhoneSignup ? 11 : 50,
- cursorColor: kBtnColor,
- keyboardType: isPhoneSignup
- ? TextInputType.number
- : TextInputType.emailAddress,
- onChanged: (value) {
- setState(() {
- strContent = value;
- });
- },
- onEditingComplete: (() {
- FocusScope.of(context).requestFocus(focusNode);
- }),
- style: TextStyle(
- color: Colors.white,
- fontSize: 28.px,
- fontFamily: 'Link1'),
- decoration: InputDecoration(
- border: InputBorder.none,
- hintText: isPhoneSignup ? '输入我的手机号' : '输入我的邮箱',
- hintStyle: TextStyle(
- fontSize: 20.px,
- color: const Color(0xFF74747A)),
- counterText: "",
- ),
- // keyboardType: TextInputType.number,
- inputFormatters: isPhoneSignup
- ? [
- FilteringTextInputFormatter(
- RegExp("[0-9.]"),
- allow: true),
- ]
- : [
- // FilteringTextInputFormatter(RegExp("[0-9.]"),
- // allow: true),
- ],
- )),
- Opacity(
- opacity: strContent.isNotEmpty ? 1 : 0,
- child: GestureDetector(
- onTap: () {
- setState(() {
- strContent = '';
- controller.clear();
- });
- },
- child: Image.asset(
- 'assets/images/clear.png',
- width: 24.px,
- height: 24.px,
- ),
- ),
- )
- ],
- ),
- ),
- SizedBox(
- height: 36.px,
- ),
- LinkButton(
- title: isPhoneSignup ? '发送短信验证码' : '发送邮箱验证码',
- disable: false,
- isBlack: false,
- callback: () {
- sendCode();
- // Get.toNamed('/signup_code');
- }),
- SizedBox(
- height: 37.px,
- ),
- if (!widget._isBind)
- Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- GestureDetector(
- onTap: (){
- setState(() {
- checked = !checked;
- });
- },
- child: Image.asset(
- checked?'assets/images/checked.png':'assets/images/check.png',
- width: 18.px,
- height: 18.px,
- ),
- ),
- SizedBox(
- width: 7.px,
- ),
- Text(
- '已阅读并同意',
- style: TextStyle(
- color: const Color(0xFF74747A), fontSize: 12.px),
- ),
- GestureDetector(
- child: Text(
- '《用户服务协议》',
- style: TextStyle(color: kBtnColor, fontSize: 12.px),
- ),
- ),
- GestureDetector(
- child: Text(
- '《隐私权政策》',
- style: TextStyle(color: kBtnColor, fontSize: 12.px),
- ),
- )
- ],
- ),
- Expanded(
- child: Container(),
- ),
- if (!widget._isBind)
- GestureDetector(
- onTap: () {
- setState(() {
- strContent = '';
- controller.clear();
- isPhoneSignup = !isPhoneSignup;
- });
- },
- child: Text(
- isPhoneSignup ? '使用邮箱登录' : '使用手机登录',
- style: TextStyle(
- color: const Color(0xFF808080), fontSize: 14.px),
- ),
- ),
- SizedBox(
- height: 50.px,
- )
- ]))
- ])));
- }
- }
|