| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231 |
- import 'package:flutter/material.dart';
- import '../styles/colors.dart';
- import 'dart:ui';
- import '../styles/totast.dart';
- import 'package:flutter_redux/flutter_redux.dart';
- import '../redux/AppState.dart';
- import '../net/HttpManager.dart';
- import '../net/Result.dart';
- import '../model/BindGameInfo.dart';
- import '../widget/LinearButton.dart';
- class BindGame extends StatefulWidget {
- @override
- BindGameState createState() => BindGameState();
- }
- class BindGameState extends State<BindGame> {
- String bindName = '';
- bool isBind = false;
- BindGameInfo bindInfo;
- Future<void> getBindInfo() async {
- Toast.show(context, '加载中', -1, 'loading');
- Result res = await HttpManager.get('bindGame/all', data: {
- 'gameId': 1,
- 'userId': StoreProvider.of<AppState>(context).state.userInfo.id
- });
- Toast.hide();
- if (res.success) {
- if (res.data.length > 0) {
- setState(() {
- isBind = true;
- bindInfo = BindGameInfo.fromJson(res.data[0]);
- });
- } else {
- setState(() {
- isBind = false;
- });
- }
- }
- }
- @override
- void initState() {
- super.initState();
- Future.delayed(Duration.zero, () {
- getBindInfo();
- });
- }
- Future<void> bindEvent() async {
- if (bindName == '') {
- Toast.show(context, '请输入和平精英游戏编号', 1500, 'info');
- return;
- }
- Toast.show(context, '加载中', -1, 'loading');
- Result res = await HttpManager.post('bindGame/save', data: {
- 'gameId': 1,
- 'userId': StoreProvider.of<AppState>(context).state.userInfo.id,
- 'nickName': bindName
- });
- Toast.hide();
- if (res.success) {
- Toast.show(context, '绑定成功', 1000, 'success');
- getBindInfo();
- } else {}
- }
- Future<void> cancelBind() async {
- Toast.show(context, '加载中', -1, 'loading');
- final res =
- await HttpManager.post('bindGame/del', data: {'id': bindInfo.id});
- Toast.hide();
- if (res.success) {
- Toast.show(context, '解绑成功', 1000, 'success');
- getBindInfo();
- } else {}
- }
- @override
- Widget build(BuildContext context) {
- return Scaffold(
- appBar: AppBar(
- // backgroundColor: PRIMARY_COLOR,
- title: Text('绑定账号'),
- centerTitle: true,
- elevation: 0,
- ),
- body: SingleChildScrollView(
- child: Container(
- color: BG_SUB_COLOR,
- padding: EdgeInsets.all(15),
- child: Column(
- children: <Widget>[
- Container(
- height: 220,
- width: double.infinity,
- // padding: EdgeInsets.symmetric(vertical: 15, horizontal: 34),
- decoration: BoxDecoration(
- image: DecorationImage(
- image: AssetImage('images/img_chijizhanchang.png'),
- fit: BoxFit.cover)),
- child: Column(
- mainAxisAlignment: MainAxisAlignment.end,
- children: _bindWidegt(),
- ),
- ),
- Container(
- height: 20,
- ),
- Text('游戏编号位置',style:TextStyle(color:Colors.white,fontSize:14)),
- Container(
- height: 10,
- ),
- Image.asset('images/bangding_img_01.png'),
- Container(
- height: 10,
- ),
- Image.asset('images/bangding_img_02.png')
- ],
- ),
- ),
- ));
- }
- List<Widget> _bindWidegt() {
- List<Widget> widgetList = [];
- if (isBind) {
- widgetList.add(Container(
- height: 78,
- padding: EdgeInsets.all(15),
- decoration: BoxDecoration(
- gradient: LinearGradient(
- colors: [Color(0xFF464B6A), Color(0xFF35395E)],
- begin: Alignment.topCenter,
- end: Alignment.bottomCenter)),
- child: Row(
- children: <Widget>[
- Image.network(bindInfo.gameInfo.icon, width: 48),
- Container(
- width: 10,
- ),
- Expanded(
- flex: 1,
- child: Column(
- mainAxisAlignment: MainAxisAlignment.center,
- crossAxisAlignment: CrossAxisAlignment.start,
- children: <Widget>[
- Text(bindInfo.gameInfo.gameName,
- style: TextStyle(color: Colors.white, fontSize: 14)),
- Container(
- height: 5,
- ),
- Row(
- children: <Widget>[
- Text(
- '已绑定',
- style: TextStyle(
- color: Color(0xFF727785),
- fontSize: 13,
- fontWeight: FontWeight.w500),
- ),
- Container(
- width: 10,
- ),
- Text(
- bindInfo.nickName,
- style: TextStyle(
- color: Colors.white,
- fontSize: 13,
- fontWeight: FontWeight.w500),
- )
- ],
- )
- ],
- )),
- Container(
- width: 50,
- height: 30,
- child: OutlineButton(
- padding: EdgeInsets.all(0),
- borderSide: BorderSide(color: Theme.of(context).primaryColor, width: 1),
- textColor: Theme.of(context).primaryColor,
- highlightColor: Color(0xFF16161C),
- child: Text('解绑'),
- onPressed: () => cancelBind(),
- ))
- ],
- ),
- ));
- } else {
- widgetList = [
- Container(
- margin: EdgeInsets.only(bottom: 10, left: 45, right: 45),
- decoration: BoxDecoration(
- borderRadius: BorderRadius.all(Radius.circular(2)),
- color: Colors.white,
- ),
- child: TextField(
- style: TextStyle(
- color: Color(0xFFFFC30F),
- fontWeight: FontWeight.w500,
- ),
- textAlign: TextAlign.center,
- decoration: InputDecoration(
- hintText: '请输入刺激战场游戏昵称',
- border: InputBorder.none,
- hintStyle: TextStyle(fontSize: 12, color: Color(0xFF727785)),
- contentPadding: const EdgeInsets.symmetric(vertical:10.0),
- ),
- onChanged: (value) {
- setState(() {
- bindName = value;
- });
- },
- ),
- ),
- Container(
- margin: EdgeInsets.only(left: 45, right: 45, bottom: 15),
- width: double.infinity,
- child: LinearButton(
- btntext: '绑定角色',
- btnHeight: 36.0,
- onTapHomeMenu: () => bindEvent(),
- ))
- ];
- }
- return widgetList;
- }
- }
|