| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376 |
- import 'dart:async';
- import 'package:flutter/material.dart';
- import 'package:flutter/services.dart';
- import 'package:get/get.dart';
- import 'package:link/view/choose_country.dart';
- import 'package:link/view/component/link_btn.dart';
- import 'package:link/view/component/toast.dart';
- import 'package:dio/dio.dart';
- import '../constants.dart';
- import '../utils/api.dart';
- import '../utils/http_utils.dart';
- import '../utils/size_fit.dart';
- import 'component/top_container.dart';
- class SignUp extends StatefulWidget {
- bool _isBind = false;
- SignUp({Key? key,bool? isBind}) : super(key: key){
- if (isBind!=null){
- _isBind = isBind;
- }
- }
- @override
- State<SignUp> createState() => _SignUpState();
- }
- class _SignUpState extends State<SignUp> {
- String code = '';
- String strContent = '';
- bool isPhoneSignup = true;
- TextEditingController controller = TextEditingController();
- FocusNode focusNode = FocusNode();
- FocusNode blankNode = FocusNode();
- bool checked = true;
- @override
- void initState() {
- // Map<String, dynamic> data = Get.parameters;
- // code = data['code'];
- Map<String, dynamic> data = Get.parameters;
- if (data.isNotEmpty) {
- code = data['code']??'';
- isPhoneSignup = data['type'] == 'sms';
- }
- WidgetsBinding.instance.addPostFrameCallback((timeStamp) {
- focusNode.requestFocus();
- });
- super.initState();
- }
- @override
- void dispose() {
- // TODO: implement dispose
- focusNode.dispose();
- blankNode.dispose();
- super.dispose();
- }
- showLoginAlert(bool isPhone) {
- FocusScope.of(context).requestFocus(blankNode);
- if (widget._isBind){
- Toast().showInfoText('${isPhone ? '手机号' : '邮箱'}已绑定其他账号\n请重新输入', context: context);
- return;
- }
- Toast().showCustomHud(
- Container(
- alignment: Alignment.center,
- padding: EdgeInsets.only(top: 32.px, bottom: 32.px),
- child: Column(
- children: [
- Text(
- '该${isPhone ? '手机号' : '邮箱'}已注册!\n可直接前往登录',
- 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('/login', parameters: {
- "content": strContent,
- "type": isPhone ? 'sms' : 'email'
- });
- }),
- 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'] == false) {
- Toast().hideHud();
- showLoginAlert(true);
- 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'] == false) {
- Toast().hideHud();
- showLoginAlert(false);
- return;
- }
- Map<String, dynamic> data2 = await HttpUtils.post(Api.emailSendCode,
- data: {'email': strContent});
- print(data2.toString());
- }
- } on DioError catch (e) {
- print(e.toString());
- }
- // ignore: nullable_type_in_catch_clause
- Toast().hideHud();
- Get.toNamed('/verify_code', parameters: {
- "code": code,
- "type": isPhoneSignup ? 'sms' : 'email',
- "content": strContent,
- "bind":widget._isBind?'1':'0'
- });
- }
- choose(){
- showDialog(
- context: context,
- barrierDismissible: false,
- barrierColor: Colors.transparent,
- useSafeArea: false,
- builder: (BuildContext context) {
- return ChooseCountry();
- });
- }
- @override
- Widget build(BuildContext context) {
- SizeFit.initialize(context);
- return Material(
- color: kBgColor,
- child: TopContainer(
- child: Stack(children: [
- // Positioned(
- // left: 0,
- // top: 0,
- // right: 0,
- // child: Container(
- // padding: EdgeInsets.only(
- // left: 12.px, right: 12.px, top: 14.px, bottom: 14.px),
- // alignment: Alignment.topLeft,
- // child: Image.asset(
- // 'assets/images/navi_back.png',
- // width: 20.px,
- // height: 20.px,
- // ),
- // )),
- 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: (){
- choose();
- },
- 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,
- controller: controller,
- focusNode: focusNode,
- // maxLength: 11,
- 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();
- }),
- 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,
- )
- ]))
- ])));
- }
- }
|