You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

254 lines
9.5 KiB

import 'dart:convert';
import 'package:barcode_widget/barcode_widget.dart';
import 'package:dio/dio.dart';
import 'package:flutter/material.dart';
import 'package:flutter_bmflocation/flutter_bmflocation.dart';
import 'package:flutter_easyloading/flutter_easyloading.dart';
import 'package:huixiang/generated/l10n.dart';
import 'package:huixiang/retrofit/data/base_data.dart';
import 'package:huixiang/retrofit/data/product.dart';
import 'package:huixiang/retrofit/data/vip_card.dart';
import 'package:huixiang/retrofit/retrofit_api.dart';
import 'package:huixiang/store/scan.dart';
import 'package:huixiang/utils/font_weight.dart';
import 'package:huixiang/utils/location.dart';
import 'package:huixiang/utils/painter_bg.dart';
import 'package:huixiang/view_widget/custom_image.dart';
import 'package:huixiang/view_widget/my_appbar.dart';
import 'package:huixiang/view_widget/my_footer.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';
import '../view_widget/classic_header.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();
Location.getInstance().stopLocation();
}
@override
void initState() {
super.initState();
queryUser();
}
UserInfo userInfo;
final RefreshController refreshController = RefreshController();
bool vipCodeText = false;
///查询用户信息
queryUser() async {
try{
SharedPreferences value = await SharedPreferences.getInstance();
if (apiService == null)
apiService = ApiService(
Dio(),
context: context,
token: value.getString("token"),
);
BaseData<UserInfo> baseData =
await apiService.queryInfo().catchError((onError) {
refreshController.refreshFailed();});
if (baseData != null && baseData.isSuccess) {
userInfo = baseData.data;
setState(() {});
SharedPreferences.getInstance().then((value) => {
value.setString('user', jsonEncode(baseData.data)),
});
refreshController.refreshCompleted();
}else{
refreshController.refreshFailed();
}
}finally{
setState((){});
}
}
@override
Widget build(BuildContext context) {
return Scaffold(
appBar: MyAppBar(
title: "会员码",
background: Colors.white,
titleColor: Colors.black,
brightness: Brightness.dark,
leadingColor: Colors.black,
),
body: SmartRefresher(
controller: refreshController,
enablePullDown: true,
enablePullUp: false,
header: MyHeader(),
physics: BouncingScrollPhysics(),
onRefresh: () {
queryUser();
},
child: SingleChildScrollView(
child: Container(
color: Colors.white,
padding: EdgeInsets.only(top: 45.h),
child: Stack(
alignment: Alignment.topCenter,
children: [
Container(
padding: EdgeInsets.only(top: 50.h),
child: Container(
width: double.infinity,
margin: EdgeInsets.symmetric(horizontal: 14.w),
padding: EdgeInsets.only(top: 68.h, bottom: 16.h),
decoration: BoxDecoration(
color: Color(0xFF32A060),
boxShadow: [
BoxShadow(
color: Colors.black.withAlpha(12),
offset: Offset(0, 2),
blurRadius: 14,
spreadRadius: 0,
),
],
borderRadius: BorderRadius.circular(6),
),
child: Container(
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),
padding: EdgeInsets.only(
top: 46.h, left:16.w, right: 15.w, bottom: 79.h),
child: Column(
mainAxisAlignment: MainAxisAlignment.center,
crossAxisAlignment: CrossAxisAlignment.center,
children: [
GestureDetector(
onTap: (){
setState(() {
vipCodeText = !vipCodeText;
});
},
child:
vipCodeText ? Text(
userInfo != null
? "${(userInfo?.vipNo ?? "").substring(0, 4)} "
"${(userInfo?.vipNo ?? "").substring(4, 8)} "
"${(userInfo?.vipNo ?? "").substring(8, 12)} "
"${(userInfo?.vipNo ?? "").substring(12, 16)} "
"${(userInfo?.vipNo ?? "").substring(16, (userInfo?.vipNo ?? "").length)}"
: "",
style: TextStyle(
fontSize: 14.sp,
wordSpacing: userInfo == null
? 10
: (MediaQuery.of(context).size.width - 64.w) /
((((userInfo?.vipNo ?? "")
.length) *
4)),
letterSpacing: userInfo == null
? 8
: (MediaQuery.of(context).size.width - 64.w) /
((((userInfo?.vipNo ?? "")
.length) *
4)),
fontWeight: MyFontWeight.semi_bold,
color: Color(0xFF353535),
),
)
:Text(
"轻触可查看会员码数字",
style: TextStyle(
fontWeight: MyFontWeight.medium,
fontSize: 13.sp,
color: Color(0xFFCACACA),
),
),
),
SizedBox(
height: 12.h,
),
BarcodeWidget(
barcode: Barcode.code128(useCode128C: true),
data:
userInfo != null ? userInfo?.vipNo : "",
height: 72.h,
color: Colors.black,
drawText: false,
),
SizedBox(
height: 16.h,
),
QrImage(
data: userInfo != null
? (userInfo?.vipNo ?? "")
: "",
version: QrVersions.auto,
size: 200.w,
gapless: true,
),
],
),
),
),
),
Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(56),
color: Colors.white,
border: Border.all(
color: Colors.white,
width: 8.w,
),
),
child: Container(
decoration: BoxDecoration(
borderRadius: BorderRadius.circular(56),
color: Colors.white,
border: Border.all(
color: Color(0xFF32A060),
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",
),
),
),
],
),
),
),
),
);
}
}