219 lines
7.0 KiB
Dart
219 lines
7.0 KiB
Dart
import 'package:flutter/cupertino.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
import 'package:aslan/app_localizations.dart';
|
|
import 'package:aslan/chatvibe_ui/components/at_compontent.dart';
|
|
import 'package:aslan/chatvibe_ui/components/text/at_text.dart';
|
|
import 'package:aslan/chatvibe_core/utilities/at_loading_manager.dart';
|
|
import 'package:aslan/chatvibe_data/sources/repositories/user_repository_impl.dart';
|
|
import 'package:aslan/chatvibe_domain/models/res/login_res.dart';
|
|
import 'package:provider/provider.dart';
|
|
import 'package:aslan/chatvibe_ui/components/dialog/dialog_base.dart';
|
|
import 'package:aslan/chatvibe_ui/components/at_tts.dart';
|
|
import 'package:aslan/chatvibe_managers/user_profile_manager.dart';
|
|
import 'package:aslan/chatvibe_ui/widgets/countdown_timer.dart';
|
|
|
|
class WearMedalDialog extends StatefulWidget {
|
|
@override
|
|
_WearMedalDialogState createState() => _WearMedalDialogState();
|
|
}
|
|
|
|
class _WearMedalDialogState extends State<WearMedalDialog> {
|
|
List<WearBadge> wearBadgeList = [];
|
|
|
|
@override
|
|
void initState() {
|
|
super.initState();
|
|
_loadData();
|
|
}
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return SafeArea(
|
|
top: false,
|
|
child: Container(
|
|
height: 420.w,
|
|
width: ScreenUtil().screenWidth,
|
|
decoration: BoxDecoration(
|
|
image: DecorationImage(
|
|
image: AssetImage("atu_images/index/at_icon_wear_honor_dialog_bg.png"),
|
|
fit: BoxFit.fill,
|
|
),
|
|
),
|
|
child: Column(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
SizedBox(height: 12.w),
|
|
text(
|
|
ATAppLocalizations.of(context)!.wearMedal,
|
|
fontSize: 15.sp,
|
|
textColor: Colors.white,
|
|
fontWeight: FontWeight.w600,
|
|
),
|
|
SizedBox(height: 5.w),
|
|
Expanded(
|
|
child:
|
|
wearBadgeList.isNotEmpty
|
|
? GridView.builder(
|
|
shrinkWrap: true,
|
|
padding: EdgeInsets.symmetric(horizontal: 12.w),
|
|
gridDelegate: SliverGridDelegateWithFixedCrossAxisCount(
|
|
crossAxisCount: 2,
|
|
childAspectRatio: 0.88,
|
|
mainAxisSpacing: 8.w,
|
|
crossAxisSpacing: 8.w,
|
|
),
|
|
itemCount: wearBadgeList.length,
|
|
itemBuilder: (BuildContext context, int index) {
|
|
return _bagItem(wearBadgeList[index]);
|
|
},
|
|
)
|
|
: mainEmpty(textColor: Colors.white),
|
|
),
|
|
SizedBox(height: 6.w,)
|
|
],
|
|
),
|
|
));
|
|
}
|
|
|
|
Widget _bagItem(WearBadge wearBadge) {
|
|
return Container(
|
|
alignment: AlignmentDirectional.center,
|
|
decoration: BoxDecoration(
|
|
image: DecorationImage(
|
|
image: AssetImage(
|
|
(wearBadge.use ?? false)
|
|
? "atu_images/index/at_icon_wear_honor_dialog_item_un_use.png"
|
|
: "atu_images/index/at_icon_wear_honor_dialog_item_on_use.png",
|
|
),
|
|
fit: BoxFit.fill,
|
|
),
|
|
),
|
|
child: Stack(
|
|
alignment: AlignmentDirectional.center,
|
|
children: [
|
|
Column(
|
|
children: [
|
|
SizedBox(height: 15.w),
|
|
netImage(url: wearBadge.selectUrl ?? "", width: 75.w),
|
|
SizedBox(height: 5.w),
|
|
Row(
|
|
mainAxisSize: MainAxisSize.min,
|
|
children: [
|
|
SizedBox(width: 8.w),
|
|
Image.asset(
|
|
"atu_images/store/at_icon_bag_clock.png",
|
|
width: 22.w,
|
|
height: 22.w,
|
|
color: Colors.white,
|
|
),
|
|
SizedBox(width: 5.w),
|
|
CountdownTimer(
|
|
color: Colors.white,
|
|
expiryDate: DateTime.fromMillisecondsSinceEpoch(
|
|
wearBadge.expireTime ?? 0,
|
|
),
|
|
),
|
|
SizedBox(width: 8.w),
|
|
],
|
|
),
|
|
SizedBox(height: 5.w),
|
|
Container(
|
|
margin: EdgeInsetsDirectional.symmetric(horizontal: 12.w),
|
|
alignment: AlignmentDirectional.center,
|
|
child: text(
|
|
maxLines: 2,
|
|
textAlign: TextAlign.center,
|
|
wearBadge.badgeName ?? "",
|
|
fontSize: 13.sp,
|
|
fontWeight: FontWeight.w600,
|
|
textColor: Colors.white,
|
|
),
|
|
),
|
|
],
|
|
),
|
|
PositionedDirectional(
|
|
bottom: 5.w,
|
|
child: GestureDetector(
|
|
behavior: HitTestBehavior.opaque,
|
|
child: Container(
|
|
width: 120.w,
|
|
padding: EdgeInsets.symmetric(vertical: 3.w),
|
|
alignment: AlignmentDirectional.center,
|
|
child: text(
|
|
(wearBadge.use ?? false)
|
|
? ATAppLocalizations.of(context)!.inUse
|
|
: ATAppLocalizations.of(context)!.use,
|
|
fontWeight: FontWeight.w600,
|
|
fontSize: 14.sp,
|
|
textColor: Colors.white,
|
|
),
|
|
),
|
|
onTap: () {
|
|
_badgeToggle(wearBadge);
|
|
},
|
|
),
|
|
),
|
|
],
|
|
),
|
|
);
|
|
}
|
|
|
|
void _badgeToggle(WearBadge wearBadge) {
|
|
SmartDialog.show(
|
|
tag: "showConfirmDialog",
|
|
alignment: Alignment.center,
|
|
debounce: true,
|
|
animationType: SmartAnimationType.fade,
|
|
builder: (_) {
|
|
return MsgDialog(
|
|
title: ATAppLocalizations.of(context)!.tips,
|
|
msg:
|
|
(wearBadge.use ?? false)
|
|
? ATAppLocalizations.of(context)!.confirmUnUseTips
|
|
: ATAppLocalizations.of(context)!.confirmUseTips,
|
|
btnText: ATAppLocalizations.of(context)!.confirm,
|
|
onEnsure: () {
|
|
_use(wearBadge, wearBadge.use ?? false);
|
|
},
|
|
);
|
|
},
|
|
);
|
|
}
|
|
|
|
void _loadData() {
|
|
AccountRepository()
|
|
.badgeOwnList("")
|
|
.then((result) {
|
|
wearBadgeList = result;
|
|
ATLoadingManager.veilRoutine();
|
|
setState(() {});
|
|
})
|
|
.catchError((e) {
|
|
ATLoadingManager.veilRoutine();
|
|
});
|
|
}
|
|
|
|
void _use(WearBadge wearBadge, bool unload) {
|
|
ATLoadingManager.exhibitOperation();
|
|
AccountRepository()
|
|
.badgeToggle(wearBadge.id ?? "")
|
|
.then((b) {
|
|
_loadData();
|
|
Provider.of<ChatVibeUserProfileManager>(
|
|
context,
|
|
listen: false,
|
|
).getMyUserInfo(needLoadUserCountGuard: false);
|
|
if (!unload) {
|
|
ATTts.show(ATAppLocalizations.of(context)!.successfulWear);
|
|
} else {
|
|
ATTts.show(ATAppLocalizations.of(context)!.successfullyUnloaded);
|
|
}
|
|
})
|
|
.catchError((e) {
|
|
ATLoadingManager.veilRoutine();
|
|
});
|
|
}
|
|
}
|