|
|
|
import 'dart:async';
|
|
|
|
import 'dart:convert';
|
|
|
|
import 'package:dio/dio.dart';
|
|
|
|
import 'package:flutter/material.dart';
|
|
|
|
import 'package:flutter_easyloading/flutter_easyloading.dart';
|
|
|
|
import 'package:huixiang/retrofit/data/base_data.dart';
|
|
|
|
import 'package:huixiang/retrofit/retrofit_api.dart';
|
|
|
|
import 'package:huixiang/utils/font_weight.dart';
|
|
|
|
import 'package:huixiang/view_widget/custom_image.dart';
|
|
|
|
import 'package:huixiang/view_widget/my_appbar.dart';
|
|
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
|
|
import 'package:pull_to_refresh/pull_to_refresh.dart';
|
|
|
|
import 'package:qr_flutter/qr_flutter.dart';
|
|
|
|
import 'package:shared_preferences/shared_preferences.dart';
|
|
|
|
|
|
|
|
import '../retrofit/data/user_info.dart';
|
|
|
|
|
|
|
|
class VipPayCode extends StatefulWidget {
|
|
|
|
@override
|
|
|
|
State<StatefulWidget> createState() {
|
|
|
|
return _VipPayCode();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
class _VipPayCode extends State<VipPayCode> {
|
|
|
|
ApiService apiService;
|
|
|
|
|
|
|
|
@override
|
|
|
|
void dispose() {
|
|
|
|
super.dispose();
|
|
|
|
refreshController?.dispose();
|
|
|
|
_timer?.cancel();
|
|
|
|
isDispose = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
void initState() {
|
|
|
|
super.initState();
|
|
|
|
queryUser();
|
|
|
|
}
|
|
|
|
|
|
|
|
UserInfo userInfo;
|
|
|
|
final RefreshController refreshController = RefreshController();
|
|
|
|
bool vipCodeText = false;
|
|
|
|
Timer _timer;
|
|
|
|
bool isDispose = false;
|
|
|
|
|
|
|
|
///查询用户信息
|
|
|
|
queryUser() async {
|
|
|
|
SharedPreferences prefs;
|
|
|
|
try {
|
|
|
|
prefs = await SharedPreferences.getInstance();
|
|
|
|
if (prefs.getString("bannerData") != null) {
|
|
|
|
userInfo = UserInfo.fromJson(jsonDecode(prefs.getString('userInfo')));
|
|
|
|
setState(() {});
|
|
|
|
}
|
|
|
|
if (apiService == null)
|
|
|
|
apiService = ApiService(
|
|
|
|
Dio(),
|
|
|
|
context: context,
|
|
|
|
token: prefs.getString("token"),
|
|
|
|
showLoading: true
|
|
|
|
);
|
|
|
|
BaseData<UserInfo> baseData = await apiService.queryInfo().catchError((onError) {
|
|
|
|
refreshController.refreshFailed();
|
|
|
|
});
|
|
|
|
if (baseData != null && baseData.isSuccess) {
|
|
|
|
userInfo = baseData.data;
|
|
|
|
prefs.setString('userInfo', jsonEncode(baseData.data));
|
|
|
|
setState(() {});
|
|
|
|
refreshController.refreshCompleted();
|
|
|
|
} else {
|
|
|
|
refreshController.refreshFailed();
|
|
|
|
}
|
|
|
|
} finally {
|
|
|
|
refreshCode();
|
|
|
|
EasyLoading.dismiss();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
refreshCode(){
|
|
|
|
if (_timer != null) return;
|
|
|
|
const oneSec = const Duration(minutes: 2);
|
|
|
|
_timer = Timer.periodic(oneSec, (timer) {
|
|
|
|
if (isDispose) {
|
|
|
|
timer.cancel();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
queryUser();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
@override
|
|
|
|
Widget build(BuildContext context) {
|
|
|
|
return Scaffold(
|
|
|
|
appBar: MyAppBar(
|
|
|
|
title: "会员码",
|
|
|
|
background: Color(0xFF32A060),
|
|
|
|
titleColor: Colors.white,
|
|
|
|
brightness: Brightness.dark,
|
|
|
|
leadingColor: Colors.white,
|
|
|
|
),
|
|
|
|
body: Container(
|
|
|
|
color: Color(0xFF32A060),
|
|
|
|
height: double.infinity,
|
|
|
|
padding: EdgeInsets.only(top: 45.h),
|
|
|
|
child: Stack(
|
|
|
|
alignment: Alignment.topCenter,
|
|
|
|
children: [
|
|
|
|
Container(
|
|
|
|
color: Color(0xFF32A060),
|
|
|
|
// height: 485.h,
|
|
|
|
padding: EdgeInsets.only(top: 47.h),
|
|
|
|
child: Container(
|
|
|
|
height: 438.h,
|
|
|
|
width: double.infinity,
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
color: Colors.white,
|
|
|
|
boxShadow: [
|
|
|
|
BoxShadow(
|
|
|
|
color: Colors.black.withAlpha(12),
|
|
|
|
offset: Offset(0, 2),
|
|
|
|
blurRadius: 14,
|
|
|
|
spreadRadius: 0,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
borderRadius: BorderRadius.circular(6),
|
|
|
|
),
|
|
|
|
margin: EdgeInsets.symmetric(horizontal: 16.w,),
|
|
|
|
child: Column(
|
|
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
|
|
crossAxisAlignment: CrossAxisAlignment.center,
|
|
|
|
children: [
|
|
|
|
SizedBox(height: 46.h,),
|
|
|
|
Text(
|
|
|
|
"请保持屏幕常亮,并对准扫码盒或枪口",
|
|
|
|
style: TextStyle(
|
|
|
|
fontWeight: MyFontWeight.regular,
|
|
|
|
fontSize: 12.sp,
|
|
|
|
color: Color(0xFF4D4D4D),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
SizedBox(height: 30.h,),
|
|
|
|
QrImage(
|
|
|
|
data:userInfo?.vipScanNo ?? "622868c3c2c5a02508ed7064c7c27387a1c2c0cb2052ba344d82266a64feb1cfc75014532616b2fb179024c83a6066757cf2639efca8f2731c54a24859e200ca",
|
|
|
|
version: QrVersions.auto,
|
|
|
|
size: 200.w,
|
|
|
|
gapless: true,
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(56),
|
|
|
|
color: Color(0xFF32A060),
|
|
|
|
border: Border.all(
|
|
|
|
color: Color(0xFF32A060),
|
|
|
|
width: 8.w,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: Container(
|
|
|
|
decoration: BoxDecoration(
|
|
|
|
borderRadius: BorderRadius.circular(56),
|
|
|
|
color: Colors.white,
|
|
|
|
border: Border.all(
|
|
|
|
color: Colors.white,
|
|
|
|
width: 2.w,
|
|
|
|
),
|
|
|
|
),
|
|
|
|
child: MImage(
|
|
|
|
userInfo?.headimg ?? "",
|
|
|
|
width: 80,
|
|
|
|
height: 80,
|
|
|
|
radius: BorderRadius.circular(56),
|
|
|
|
fit: BoxFit.cover,
|
|
|
|
errorSrc: "assets/image/default_1.webp",
|
|
|
|
fadeSrc: "assets/image/default_1.webp",
|
|
|
|
),
|
|
|
|
),
|
|
|
|
),
|
|
|
|
],
|
|
|
|
),
|
|
|
|
),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|