invit_code.dart 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. import 'package:flutter/material.dart';
  2. import 'package:get/get.dart';
  3. import 'package:link/constants.dart';
  4. import 'package:link/utils/global.dart';
  5. import 'package:link/utils/util.dart';
  6. import 'package:link/view/component/code.dart';
  7. import 'package:link/view/component/link_btn.dart';
  8. import 'package:link/view/component/toast.dart';
  9. import '../utils/api.dart';
  10. import '../utils/http_utils.dart';
  11. import '../utils/size_fit.dart';
  12. import 'component/top_container.dart';
  13. class InviteCode extends StatefulWidget {
  14. const InviteCode({Key? key}) : super(key: key);
  15. @override
  16. State<InviteCode> createState() => _InviteCodeState();
  17. }
  18. class _InviteCodeState extends State<InviteCode> {
  19. String code = '';
  20. @override
  21. void initState() {
  22. // TODO: implement initState
  23. super.initState();
  24. code = Global().code;
  25. Util().setPageTitle('invite');
  26. }
  27. tapBegin() {
  28. if (code.length != 4) {
  29. Toast().showInfoText('邀请码错误,请重新输入', context: context);
  30. setState(() {
  31. code = '';
  32. });
  33. return;
  34. }
  35. checkCode();
  36. //
  37. }
  38. Future checkCode() async {
  39. Map<String, dynamic> data = await HttpUtils.get(Api.inviteCodeExist,params: {
  40. 'invite_code':code
  41. });
  42. if (data['success']==false){
  43. Toast().showInfoText(data['message'], context: context);
  44. return;
  45. }
  46. Get.toNamed('/signup',parameters: {'code':code});
  47. }
  48. updateCode(strCode) {
  49. setState(() {
  50. code = strCode;
  51. });
  52. }
  53. @override
  54. Widget build(BuildContext context) {
  55. SizeFit.initialize(context);
  56. return Material(
  57. color: kBgColor,
  58. child: TopContainer(
  59. child: Stack(children: [
  60. // Positioned(
  61. // left: 0,
  62. // top: 0,
  63. // right: 0,
  64. // child: Container(
  65. // padding: EdgeInsets.only(
  66. // left: 12.px, right: 12.px, top: 14.px, bottom: 14.px),
  67. // alignment: Alignment.topLeft,
  68. // child: Image.asset(
  69. // 'assets/images/navi_back.png',
  70. // width: 20.px,
  71. // height: 20.px,
  72. // ),
  73. // )),
  74. Container(
  75. padding: EdgeInsets.only(top: 47.px),
  76. child: Column(
  77. crossAxisAlignment: CrossAxisAlignment.center,
  78. children: [
  79. Image.asset(
  80. 'assets/images/logo.png',
  81. width: 167.px,
  82. height: 64.px,
  83. ),
  84. SizedBox(
  85. height: 20.px,
  86. ),
  87. Text(
  88. '如果你已获得邀请码且尚未注册,请输入邀请码\n如果你尚未获得邀请码,请耐心等待',
  89. textAlign: TextAlign.center,
  90. style: TextStyle(
  91. color: const Color(0xFF74747A),
  92. fontSize: 14.px,
  93. height: 1.71),
  94. ),
  95. SizedBox(
  96. height: 12.px,
  97. ),
  98. Code(
  99. type: 1,
  100. code: code,
  101. changed: (e) {
  102. updateCode(e);
  103. }),
  104. SizedBox(
  105. height: 24.px,
  106. ),
  107. LinkButton(
  108. title: '使用邀请码·开始注册',
  109. disable: false,
  110. isBlack: false,
  111. callback: () {
  112. tapBegin();
  113. }),
  114. SizedBox(
  115. height: 52.px,
  116. ),
  117. Row(
  118. mainAxisAlignment: MainAxisAlignment.center,
  119. children: [
  120. Text('如果你已完成注册,请点击',
  121. style: TextStyle(
  122. color: const Color(0xFF444447),
  123. fontSize: 14.px)),
  124. GestureDetector(
  125. onTap: (){Get.toNamed('/login');},
  126. child: Text(
  127. '前往登录',
  128. style: TextStyle(color: kBtnColor, fontSize: 14.px),
  129. ),
  130. )
  131. ],
  132. )
  133. ]))
  134. ])));
  135. }
  136. }