import 'package:dio/dio.dart'; import 'package:flutter/material.dart'; import 'package:flutter_smart_dialog/flutter_smart_dialog.dart'; import 'package:flutter_swiper/flutter_swiper.dart'; import 'package:huixiang/generated/l10n.dart'; import 'package:huixiang/retrofit/data/base_data.dart'; import 'package:huixiang/retrofit/data/rank.dart'; import 'package:huixiang/retrofit/retrofit_api.dart'; import 'package:huixiang/view_widget/mine_vip_view.dart'; import 'package:flutter_screenutil/flutter_screenutil.dart'; import 'package:huixiang/view_widget/my_appbar.dart'; import 'package:shared_preferences/shared_preferences.dart'; class MineVipLevelPage extends StatefulWidget { final Map arguments; MineVipLevelPage({this.arguments}); @override State createState() { return _MineVipLevelPage(); } } class _MineVipLevelPage extends State { ApiService apiService; List ranks = []; SwiperController controller = SwiperController(); @override void initState() { super.initState(); SharedPreferences.getInstance().then((value) { apiService = ApiService(Dio(), context: context, token: value.getString("token")); queryVipLevel(); }); } queryVipLevel() async { BaseData rankData = await apiService.rankList(); if (rankData != null && rankData.isSuccess) { ranks.clear(); ranks.addAll((rankData.data as List) .map((e) => Rank.fromJson(e)) .toList()); setState(() { controller.move((widget.arguments["rankLevel"] - 1), animation: false); }); } else { SmartDialog.showToast(rankData.msg, alignment: Alignment.center); } } @override Widget build(BuildContext context) { return Scaffold( appBar: MyAppBar( title: S.of(context).wodehuiyuandengji, titleColor: Colors.black, titleSize: 18.sp, background: Color(0xFFFFFFFF), leadingColor: Colors.black, ), body: SingleChildScrollView( physics: BouncingScrollPhysics(), child: Column( children: [ AspectRatio( aspectRatio: 1.7, child: Swiper( viewportFraction: 0.95, loop: false, physics: BouncingScrollPhysics(), // index: (ranks != null && ranks.isNotEmpty) ? widget.arguments["rankLevel"] - 1 : 0, controller: controller, itemBuilder: (context, position) { // if(ranks == null || ranks.isEmpty) return Container(width: 10, height: 10,); return MineVipView( position + 1, curLevel: widget.arguments["rankLevel"], padding: 6.w, rank: widget.arguments["points"], rankMax: (position < (ranks.length - 1)) ? ranks[position + 1].rankOrigin : ranks[position].rankOrigin, createTime: widget.arguments["createTime"], ); }, itemCount: (ranks != null && ranks.isNotEmpty) ? ranks.length : 0, ), ), Container( margin: EdgeInsets.fromLTRB(0, 16.h, 0, 0), padding: EdgeInsets.fromLTRB(16.w, 16.h, 16.w, 16.h), decoration: BoxDecoration( color: Colors.white, borderRadius: BorderRadius.only( topLeft: Radius.circular(8), topRight: Radius.circular(8), ), ), child: Column( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Text( S.of(context).huiyuandengjishuoming, style: TextStyle( fontWeight: FontWeight.bold, fontSize: 16.sp, color: Colors.black, ), ), SizedBox( height: 12.h, ), Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( width: 6.w, height: 6.h, margin: EdgeInsets.fromLTRB(4.w, 7.h, 4.w, 7.h), decoration: BoxDecoration( borderRadius: BorderRadius.circular(3), color: Color(0xFF32A060), ), ), Expanded( child: Text( S.of(context).chenggongdengluzhuce, style: TextStyle( textBaseline: TextBaseline.alphabetic, fontSize: 14.sp, fontWeight: FontWeight.w400, color: Color(0xFF353535), ), ), flex: 1, ), ], ), SizedBox( height: 20.h, ), Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( child: Text( S.of(context).huiyuandengji, textAlign: TextAlign.center, style: TextStyle( fontWeight: FontWeight.bold, fontSize: 14.sp, color: Color(0xFF353535), ), ), flex: 1, ), Expanded( child: Text( S.of(context).jifen, textAlign: TextAlign.center, style: TextStyle( fontWeight: FontWeight.bold, fontSize: 14.sp, color: Color(0xFF353535), ), ), flex: 1, ), ], ), SizedBox( height: 8.h, ), Column( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: ranks != null ? ranks.map((e) { return levelItem( e, ranks[ranks.indexOf(e)].rankOrigin, ranks.indexOf(e) == (ranks.length - 1) ? 0 : ranks[ranks.indexOf(e) + 1].rankOrigin); }).toList() : [], ), SizedBox( height: 32.h, ), Text( S.of(context).jifendejisuanshuoming, style: TextStyle( fontWeight: FontWeight.bold, fontSize: 16.sp, color: Colors.black, ), ), SizedBox( height: 12.h, ), Row( mainAxisAlignment: MainAxisAlignment.start, crossAxisAlignment: CrossAxisAlignment.center, children: [ Container( width: 6.w, height: 6.h, margin: EdgeInsets.fromLTRB(4.w, 7.h, 4.w, 7.h), decoration: BoxDecoration( borderRadius: BorderRadius.circular(3), color: Color(0xFF32A060), ), ), Text( S.of(context).yonghuxiaofeijifen, style: TextStyle( textBaseline: TextBaseline.alphabetic, fontSize: 14.sp, fontWeight: FontWeight.w400, color: Color(0xFF353535), ), ), ], ), SizedBox( height: 12.h, ), Row( mainAxisAlignment: MainAxisAlignment.start, mainAxisSize: MainAxisSize.min, crossAxisAlignment: CrossAxisAlignment.start, children: [ Container( width: 6.w, height: 6.h, margin: EdgeInsets.fromLTRB(4.w, 7.h, 4.w, 7.h), decoration: BoxDecoration( borderRadius: BorderRadius.circular(3), color: Color(0xFF32A060), ), ), Expanded( child: Text( S.of(context).youhuiquanwufajileijifen, style: TextStyle( fontSize: 14.sp, fontWeight: FontWeight.w400, color: Color(0xFF353535), ), ), flex: 1, ), ], ), ], ), ), ], ), ), ); } Widget levelItem(Rank rank, rankOrigin, rankOriginMax) { return Container( margin: EdgeInsets.symmetric(vertical: 8.h), child: Row( mainAxisAlignment: MainAxisAlignment.center, crossAxisAlignment: CrossAxisAlignment.center, children: [ Expanded( child: Text( rank.rankName, textAlign: TextAlign.center, style: TextStyle( fontSize: 14.sp, fontWeight: FontWeight.w400, color: Color(0xFF353535), ), ), flex: 1, ), Expanded( child: Text( "$rankOrigin - ${rankOriginMax == 0 ? "无限" : rankOriginMax}", textAlign: TextAlign.center, style: TextStyle( fontSize: 14.sp, fontWeight: FontWeight.w400, color: Color(0xFF353535), ), ), flex: 1, ), ], ), ); } }