| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197 |
- import 'package:dio/dio.dart';
- import 'package:fast/constants.dart';
- import 'package:fast/utils/api.dart';
- import 'package:fast/utils/http_utils.dart';
- import 'package:fast/utils/size_fit.dart';
- import 'package:fast/view/index.dart';
- import 'package:flutter/material.dart';
- import 'package:get/get.dart';
- import 'component/fast_btn.dart';
- import 'component/header.dart';
- import 'component/toast.dart';
- class InviteCode extends StatefulWidget {
- const InviteCode({Key? key}) : super(key: key);
- @override
- State<InviteCode> createState() => _InviteCodeState();
- }
- class _InviteCodeState extends State<InviteCode> {
- String code = '';
- bool showError = false;
- @override
- Widget build(BuildContext context) {
- SizeFit.initialize(context);
- return Material(
- child: Container(
- color: kBgColor,
- child: Column(children: [
- Header(
- isIndexPage: false,
- ),
- SizedBox(
- height: 50.px,
- ),
- Opacity(
- opacity: showError ? 1 : 0,
- child: Text(
- '输入的邀请码错误,请重新输入',
- style: TextStyle(color: kThemeColor, fontSize: 12.px),
- ),
- ),
- SizedBox(
- height: 10.px,
- ),
- Stack(
- children: [
- Container(
- width: 311.px,
- height: 48.px,
- alignment: Alignment.center,
- decoration: BoxDecoration(
- color: const Color(0x26C4CCDA),
- borderRadius:
- BorderRadius.all(Radius.circular(16.px))),
- child: Opacity(
- opacity: code.isEmpty ? 1 : 0,
- child: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Text(
- '请输入邀请码,你和朋友各得',
- style: TextStyle(
- color: const Color(0x66FFFFFF),
- fontSize: 16.px),
- ),
- SizedBox(
- width: 3.px,
- ),
- Text(
- '5',
- style: TextStyle(
- color: const Color(0x99FFFFFF),
- fontSize: 24.px,
- fontFamily: 'Exo2',
- fontWeight: FontWeight.w600),
- ),
- SizedBox(
- width: 3.px,
- ),
- Image.asset(
- 'assets/images/stone.png',
- width: 24.px,
- height: 24.px,
- )
- ],
- ),
- )),
- SizedBox(
- width: 311.px,
- height: 48.px,
- child: TextField(
- onChanged: (value) {
- setState(() {
- code = value;
- });
- },
- style: TextStyle(
- color: Colors.white,
- fontSize: 24.px,
- fontFamily: 'Exo2',
- fontWeight: FontWeight.w600),
- cursorColor: Colors.white,
- maxLength: 4,
- autofocus: true,
- textAlign: TextAlign.center,
- decoration: const InputDecoration(
- counterText: "",
- border: InputBorder.none,
- contentPadding: EdgeInsets.zero,
- hintStyle: TextStyle(color: Color(0x66FFFFFF))),
- ))
- ],
- ),
- SizedBox(
- height: 28.px,
- ),
- FastBtn(
- title: '提交',
- disable: false,
- // color: const Color(0x80AAFF00),
- width: 311.px,
- height: 48.px,
- callback: () {
- invite();
- }),
- SizedBox(
- height: 30.px,
- ),
- GestureDetector(
- onTap: () {
- jump();
- },
- child: Text(
- '无邀请码,跳过',
- style: TextStyle(
- color: const Color(0x99C4CCDA), fontSize: 14.px),
- ))
- ])));
- }
- Future invite() async {
- try {
- Map<String, dynamic> data = await HttpUtils.post(Api.inviteCode,
- data: {'skip': false, 'invite_code': code});
- showToast();
- Get.offAll(const IndexScreen());
- // Navigator.of(context).pop();
- } on DioError catch (e) {
- if (e.response?.data['error_code'] == 'INVITE_CODE_NOT_EXIST') {
- setState(() {
- showError = true;
- });
- }
- }
- }
- showToast() {
- showDialog(
- context: context,
- barrierDismissible: false,
- barrierColor: Colors.transparent,
- builder: (BuildContext context) {
- return Toast(
- title: '成功受邀',
- content: Row(
- mainAxisAlignment: MainAxisAlignment.center,
- children: [
- Text(
- '+3',
- style: TextStyle(
- color: Colors.white,
- fontSize: 16.px,
- fontWeight: FontWeight.w800,
- fontFamily: 'Exo2',
- decoration: TextDecoration.none),
- ),
- SizedBox(
- width: 3.px,
- ),
- Image.asset(
- 'assets/images/stone.png',
- width: 24.px,
- height: 24.px,
- )
- ],
- ),
- );
- });
- }
- Future jump() async {
- var data = await HttpUtils.post(Api.inviteCode, data: {'skip': true});
- Get.offAll(const IndexScreen());
- }
- }
|