| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192 |
- 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';
- 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: 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(),
- ),
- )
- ],
- ),
- ));
- }
- 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: Color(0xFFC2524D), width: 1),
- textColor: Color(0xFFC2524D),
- highlightedBorderColor: Color(0xFF9B4040),
- 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,
- ),
- height: 40,
- child: TextField(
- style: TextStyle(color: Color(0xFFAF4946), fontWeight: FontWeight.w500),
- textAlign: TextAlign.center,
- decoration: InputDecoration(hintText: '请输入刺激战场游戏昵称', border: InputBorder.none, hintStyle: TextStyle(fontSize: 12, color: Color(0xFF727785))),
- onChanged: (value) {
- setState(() {
- bindName = value;
- });
- },
- ),
- ),
- Container(
- margin: EdgeInsets.only(left: 45, right: 45, bottom: 15),
- width: double.infinity,
- height: 40,
- child: RaisedButton(
- textTheme: ButtonTextTheme.primary,
- child: Text('绑定角色'),
- onPressed: () {
- bindEvent();
- },
- ),
- )
- ];
- }
- return widgetList;
- }
- }
|