146 lines
5.5 KiB
Dart
146 lines
5.5 KiB
Dart
import 'dart:async';
|
||
import 'dart:ui';
|
||
|
||
import 'package:aiplot/network/NetworkConfig.dart';
|
||
import 'package:flutter/material.dart';
|
||
import 'package:flutter/rendering.dart';
|
||
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
||
|
||
import '../generated/l10n.dart';
|
||
import '../tools/me/me_info_model.dart';
|
||
|
||
///填写邀请码弹框
|
||
class InvitationCodeDialog extends StatefulWidget {
|
||
InvitationCodeDialog({Key? key}) : super(key: key);
|
||
|
||
@override
|
||
State<InvitationCodeDialog> createState() => _InvitationCodeDialogState();
|
||
}
|
||
|
||
class _InvitationCodeDialogState extends State<InvitationCodeDialog> {
|
||
TextEditingController _textEditingController = TextEditingController();
|
||
String text = "";
|
||
|
||
void _textFieldChanged(String str) {
|
||
text = str.toUpperCase();
|
||
_textEditingController.value = _textEditingController.value.copyWith(text: text.toUpperCase());
|
||
}
|
||
|
||
StreamSubscription? subscription;
|
||
final MeInfoModel _viewModel = MeInfoModel();
|
||
|
||
@override
|
||
void initState() {
|
||
// TODO: implement initState
|
||
super.initState();
|
||
|
||
//网络请求回调
|
||
subscription = _viewModel.streamController.stream.listen((newData) {
|
||
String code = newData['code'];
|
||
if (code.isNotEmpty) {
|
||
EasyLoading.dismiss();
|
||
switch (code) {
|
||
case "fillInInvitationCode":
|
||
Navigator.pop(context);
|
||
String message = newData['data'];
|
||
EasyLoading.showToast(message);
|
||
break;
|
||
default:
|
||
String message = newData['data'];
|
||
EasyLoading.showToast(message);
|
||
break;
|
||
}
|
||
}
|
||
setState(() {});
|
||
});
|
||
}
|
||
|
||
@override
|
||
Widget build(BuildContext context) {
|
||
final size = MediaQuery.of(context).size;
|
||
return Material(
|
||
type: MaterialType.transparency, //透明类型
|
||
color: const Color(0x00000000),
|
||
child: Container(
|
||
alignment: Alignment.center,
|
||
child: Column(
|
||
mainAxisSize: MainAxisSize.min,
|
||
children: [
|
||
Container(
|
||
width: size.width,
|
||
margin: EdgeInsets.only(left: 25, right: 25),
|
||
decoration: BoxDecoration(color: Colors.white, borderRadius: BorderRadius.all(Radius.circular(7))),
|
||
child: Column(
|
||
children: [
|
||
Container(
|
||
alignment: Alignment.centerLeft,
|
||
margin: EdgeInsets.only(top: 22, left: 34),
|
||
child: Text(
|
||
S.of(context).Invitation_code,
|
||
style: TextStyle(fontSize: 16, fontWeight: FontWeight.w500),
|
||
),
|
||
),
|
||
Container(
|
||
alignment: Alignment.centerLeft,
|
||
margin: EdgeInsets.only(top: 11, left: 34, right: 34),
|
||
child: Text("${S.of(context).Fill_in} ${NetworkConfig.appConfigBean!.InviteeNumber} ${S.of(context).Painting_points}"),
|
||
),
|
||
Container(
|
||
height: 37,
|
||
alignment: Alignment.center,
|
||
margin: const EdgeInsets.only(top: 11, left: 34, right: 34),
|
||
decoration: const BoxDecoration(
|
||
color: Color(0xFFF0F0FF),
|
||
borderRadius: BorderRadius.all(Radius.circular(7)),
|
||
),
|
||
child: TextField(
|
||
controller: _textEditingController,
|
||
keyboardType: TextInputType.name,
|
||
cursorColor: Color(0xFF843FFF),
|
||
decoration: InputDecoration.collapsed(hintStyle: const TextStyle(fontSize: 16.0, color: Color(0xFFB5B5B5)), hintText: ''),
|
||
//文本对齐方式
|
||
textAlign: TextAlign.center,
|
||
//最大长度,设置此项会让TextField右下角有一个输入数量的统计字符串
|
||
//最大行数
|
||
maxLines: 1,
|
||
//输入文本的样式
|
||
style: const TextStyle(fontSize: 18.0, color: Color(0xFF843FFF), fontWeight: FontWeight.w500),
|
||
onChanged: _textFieldChanged,
|
||
autofocus: false,
|
||
),
|
||
),
|
||
GestureDetector(
|
||
onTap: () {
|
||
if (text != "") {
|
||
_viewModel.fillInInvitationCode(text);
|
||
} else {
|
||
EasyLoading.showToast(S.of(context).Please_fill_in);
|
||
}
|
||
},
|
||
child: Container(
|
||
height: 45,
|
||
width: double.infinity,
|
||
alignment: Alignment.center,
|
||
margin: EdgeInsets.only(top: 30),
|
||
decoration: const BoxDecoration(
|
||
gradient: LinearGradient(
|
||
begin: Alignment.centerLeft, //渐变开始于上面的中间开始
|
||
end: Alignment.centerRight, //渐变结束于下面的中间
|
||
colors: [Color(0xFF843FFF), Color(0xFFF87DFF)]),
|
||
borderRadius: BorderRadius.only(bottomLeft: Radius.circular(7), bottomRight: Radius.circular(7))),
|
||
child: Text(
|
||
S.of(context).Sure,
|
||
style: TextStyle(color: Colors.white, fontSize: 16),
|
||
),
|
||
),
|
||
)
|
||
],
|
||
),
|
||
)
|
||
],
|
||
),
|
||
),
|
||
);
|
||
}
|
||
}
|