Commit 776990f1754a981484ad711918b0016f456d4d3c

Authored by weixin_45529955
1 parent baabadcb

扫码领消费金 UI OK

import 'package:flutter/material.dart';
import 'package:flutter/services.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/res/colors.dart';
import 'package:one_key/route/navigator_util.dart';
import 'package:one_key/utils/screen_util.dart';
import 'package:one_key/widgets/h_empty_view.dart';
import 'package:one_key/widgets/round_button.dart';
import 'package:one_key/widgets/system_app_bar.dart';
/**
* 发放消费金
*/
class GrantPage extends StatefulWidget {
const GrantPage({super.key});
@override
State<GrantPage> createState() => _GrantPageState();
}
class _GrantPageState extends State<GrantPage> {
ScrollController controller = ScrollController();
List ladderSelectFree = [];
@override
void initState() {
super.initState();
ladderSelectFree.add('1');
WidgetsBinding.instance.addPostFrameCallback((_) {
// _getConsumeConfig();
});
}
///发放阶梯
Widget _ladderWidget() {
return ListView.builder(
controller: controller,
shrinkWrap: true,
itemCount: ladderSelectFree.length,
itemBuilder: (context, index) {
dynamic data = ladderSelectFree[index];
return Container(
padding: EdgeInsets.only(
left: w(16),
// top: w(12),
bottom: w(12),
),
child: Column(
children: [
Container(
height: w(48),
padding: EdgeInsets.only(right: w(16)),
decoration: BoxDecoration(
border: Border(
bottom: BorderSide(
color: MyColours.color_E7E7E7, width: w(0.5)))),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'发放(${index + 1})',
style: TextStyle(
color: MyColours.color_515151, fontSize: font(14)),
),
InkWell(
onTap: () {
//删除媒体
ladderSelectFree.remove(data);
setState(() {});
},
child: Padding(
padding: EdgeInsets.only(top: w(8), bottom: w(8)),
child: Text(
'删除',
style: TextStyle(
color: MyColours.color_438E93,
fontSize: font(12)),
),
))
],
),
),
_ladderPriceWidget(TextEditingController(), FocusNode(),
width: 50),
],
),
);
});
}
//阶梯返还金额widget
Widget _ladderPriceWidget(
TextEditingController controllerGive, FocusNode focusNodeGive,
{num width = 40}) {
return Container(
height: w(40),
margin: EdgeInsets.only(left: w(width)),
padding: EdgeInsets.only(top: w(8), bottom: w(8)),
decoration: BoxDecoration(
border: Border(
bottom:
BorderSide(color: MyColours.color_E7E7E7, width: w(0.5)))),
child: Row(
mainAxisAlignment: MainAxisAlignment.spaceBetween,
children: [
Text(
'发放消费金',
style: TextStyle(color: MyColours.color_515151, fontSize: font(14)),
),
HEmptyView(10),
Container(
width: w(54),
height: w(26),
alignment: Alignment.center,
decoration: BoxDecoration(
border: Border.all(color: MyColours.color_999999, width: w(1))),
child: TextField(
controller: controllerGive,
textAlign: TextAlign.center,
textAlignVertical: TextAlignVertical.center,
maxLines: 1,
// //光标颜色
// cursorColor:
// widget.isSelect ? Colors.white : MyColours.color_199095,
//输入文本的样式
inputFormatters: [
FilteringTextInputFormatter.allow(RegExp("[0-9.]")),
], // 限制输入为数字,
style: TextStyle(
color: MyColours.color_515151,
fontSize: ScreenUtil().setSp(20),
),
focusNode: focusNodeGive,
decoration: InputDecoration(
isCollapsed: true,
border: OutlineInputBorder(borderSide: BorderSide.none),
hintText: '请输入数字',
hintStyle: TextStyle(
color: MyColours.color_999999,
fontSize: ScreenUtil().setSp(20),
),
enabledBorder: new UnderlineInputBorder(
borderSide: BorderSide.none,
),
focusedBorder: new UnderlineInputBorder(
borderSide: BorderSide.none,
),
),
onChanged: (value) {},
onEditingComplete: () {
FocusScope.of(context).requestFocus(FocusNode()); //点击空白处隐藏键盘
},
keyboardType: TextInputType.numberWithOptions()),
),
HEmptyView(10),
Text(
'元',
style: TextStyle(color: MyColours.color_515151, fontSize: font(14)),
),
HEmptyView(10),
Spacer(),
RoundButton(
text: '查看二维码',
width: w(86),
height: w(24),
fontSize: 28,
gradientStart: MyColours.color_438E93,
gradientEnd: MyColours.color_438E93,
textColor: MyColours.color_ffffff,
isBold: false,
radius: 5,
onPressed: () {
//跳转到二维码展示页面
NavigatorUtil.goGrantWechatPage(context);
},
),
HEmptyView(32),
],
),
);
}
@override
Widget build(BuildContext context) {
return Scaffold(
backgroundColor: MyColours.color_ffffff,
appBar: SystemAppBar('发放消费金'),
body: Column(
children: [
_ladderWidget(),
InkWell(
onTap: () {
// LadderData data = LadderData();
ladderSelectFree.add('1');
setState(() {});
},
child: Container(
height: w(30),
margin: EdgeInsets.only(left: w(60), right: w(16)),
alignment: Alignment.centerLeft,
child: Text(
'+增加阶梯',
style: TextStyle(
color: MyColours.color_438E93, fontSize: font(12)),
),
)),
],
),
);
}
}
... ...
import 'dart:io';
import 'dart:typed_data';
import 'dart:ui';
import 'package:cached_network_image/cached_network_image.dart';
import 'package:flutter/cupertino.dart';
import 'package:flutter/material.dart';
import 'package:flutter/rendering.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:image_gallery_saver/image_gallery_saver.dart';
import 'package:one_key/provider/user_model.dart';
import 'package:one_key/widgets/round_button.dart';
import 'package:one_key/widgets/system_app_bar.dart';
import 'package:one_key/widgets/v_empty_view.dart';
import 'package:permission_handler/permission_handler.dart';
import 'package:provider/provider.dart';
import '../../../constant/state.dart';
import '../../../provider/finance_provider.dart';
import '../../../res/colors.dart';
import '../../../utils/screen_util.dart';
import '../../../utils/utils.dart';
import '../../../widgets/h_empty_view.dart';
import '../../../widgets/loading.dart';
import 'dart:ui' as ui;
/**
* 扫码领消费金
*/
class GrantWechatPage extends StatefulWidget {
const GrantWechatPage({super.key});
@override
State<GrantWechatPage> createState() => _GrantWechatPageState();
}
class _GrantWechatPageState extends State<GrantWechatPage> {
FinanceProvider? financeProvider;
final GlobalKey globalKey = GlobalKey();
@override
void initState() {
super.initState();
WidgetsBinding.instance.addPostFrameCallback((_) async {
_createPayQrcode();
});
}
_createPayQrcode() {
financeProvider!.createPayQrcode(context);
}
/// 截图
Future<Uint8List?> _capturePng(
GlobalKey globalKey,
// {
// double pixelRatio = 2.0, //截屏的图片与原图的比例
// }
) async {
try {
RenderRepaintBoundary boundary =
globalKey.currentContext?.findRenderObject() as RenderRepaintBoundary;
double dpr = ui.window.devicePixelRatio; // 获取当前设备的像素比
var image = await boundary.toImage(pixelRatio: dpr);
ByteData? byteData = await image.toByteData(format: ImageByteFormat.png);
Uint8List? pngBytes = byteData?.buffer.asUint8List();
return pngBytes;
} catch (e) {
print(e);
}
return null;
}
@override
Widget build(BuildContext context) {
financeProvider = Provider.of<FinanceProvider>(context, listen: true);
return Scaffold(
appBar: SystemAppBar('扫码领消费金'),
backgroundColor: MyColours.color_ffffff,
body: Column(
children: [
Expanded(
child: SingleChildScrollView(
child: Column(
crossAxisAlignment: CrossAxisAlignment.start,
children: [
VEmptyView(100),
//二维码图片
//
RepaintBoundary(
key: globalKey,
child: Column(
children: [
Container(
margin: EdgeInsets.symmetric(horizontal: w(57)),
padding: EdgeInsets.symmetric(
horizontal: w(25), vertical: w(35)),
color: MyColours.color_438E93,
child: Column(
children: [
Text(
'微信扫码领取消费金\n消费时可直接抵扣',
style: TextStyle(
color: MyColours.color_ffffff,
fontSize: font(16),
fontWeight: FontWeight.bold),
),
VEmptyView(20),
Consumer<FinanceProvider>(
builder: (context, model, _) {
if (model.pageState != PageState.Success) {
return Container(
height: w(210),
child: Center(
child: SizedBox(
width:
ScreenUtil().setWidth(40),
height:
ScreenUtil().setWidth(40),
child:
CupertinoActivityIndicator(
color: MyColours.color_ffffff,
))),
);
} else {
return Container(
padding: EdgeInsets.symmetric(
horizontal: w(21),
vertical: w(16)),
color: MyColours.color_ffffff,
child: Column(
children: [
CachedNetworkImage(
imageUrl: financeProvider!
.paymentCodeUrl),
// VEmptyView(28),
Text(
'${Provider.of<UserModel>(context).user!.sellername}',
maxLines: 3,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color:
MyColours.color_000000,
fontSize: font(14)),
),
VEmptyView(28),
Text(
'消费金:¥50.00',
maxLines: 3,
overflow: TextOverflow.ellipsis,
style: TextStyle(
color:
MyColours.color_000000,
fontSize: font(14)),
),
],
));
}
})
],
),
),
// Container(
// margin: EdgeInsets.symmetric(horizontal: w(57)),
// padding: EdgeInsets.symmetric(
// horizontal: w(25), vertical: w(11)),
// decoration: BoxDecoration(
// color: MyColours.color_ffffff,
// border: Border.all(
// color: MyColours.color_09BB07,
// width: w(2))),
// child: Row(
// mainAxisAlignment: MainAxisAlignment.center,
// children: [
// Image.asset(
// Utils.getImgPath('vector'),
// width: w(37),
// ),
// HEmptyView(12),
// Text(
// '微信支付',
// style: TextStyle(
// color: MyColours.color_515151,
// fontSize: font(28)),
// )
// ],
// )),
],
)),
VEmptyView(160),
// Padding(
// padding: EdgeInsets.symmetric(horizontal: w(16)),
// child: Text(
// '提示:',
// textAlign: TextAlign.left,
// style: TextStyle(
// fontSize: w(16),
// height: 1.5,
// fontWeight: FontWeight.bold,
// color: MyColours.color_000000),
// )),
// Padding(
// padding: EdgeInsets.symmetric(horizontal: w(16)),
// child: Text(
// '请将收款码出示给顾客,顾客扫码支付时可以自动识别拥有的代金券,并自动在餐厅设定的规则下使用。',
// textAlign: TextAlign.left,
// style: TextStyle(
// fontSize: w(14),
// height: 1.5,
// color: MyColours.color_000000),
// ))
],
),
),
),
Container(
padding: EdgeInsets.symmetric(vertical: w(13), horizontal: w(79)),
child: RoundButton(
text: '保存二维码图片',
height: w(43),
radius: r(5),
gradientStart: MyColours.color_ffffff,
gradientEnd: MyColours.color_ffffff,
borderColor: MyColours.color_438E93,
textColor: MyColours.color_438E93,
isBold: true,
fontSize: 32,
onPressed: () {
Utils.getPickPermission(context, () async {
//获取截屏图像
//添加到图片数组中
Loading.showLoading(
context,
);
Uint8List? value = await _capturePng(globalKey);
if (value != null) {
print(value);
final result = await ImageGallerySaver.saveImage(value,
quality: 100);
if (result != null) {
Utils.showToast("保存成功");
} else {
print('error');
Utils.showToast("保存失败");
// toast("");
}
Loading.hideLoading(context);
// setState(() {});
}
}, Platform.isIOS ? Permission.photos : Permission.storage);
},
),
)
],
));
}
}
... ...
import 'package:flutter/material.dart';
import 'package:flutter_screenutil/flutter_screenutil.dart';
import 'package:one_key/route/navigator_util.dart';
... ... @@ -444,6 +443,41 @@ class _MarketingCenterHomePageState extends State<MarketingCenterHomePage> {
padding: EdgeInsets.only(left: w(16)),
child: MyDivider(double.infinity, w(0.5),
color: MyColours.color_E7E7E7)),
VEmptyView(24),
InkWell(
onTap: () {
NavigatorUtil.goGrantPage(context);
},
child: Padding(
padding: EdgeInsets.only(
left: w(16),
top: w(12),
bottom: w(12),
right: w(12)),
child: Row(
children: [
Text(
'为团购客户发消费金',
style: TextStyle(
color: MyColours.color_515151,
fontSize: ScreenUtil().setWidth(32)),
),
Spacer(),
Container(
padding: EdgeInsets.symmetric(
horizontal: w(7), vertical: w(4)),
child: Image.asset(
"assets/arrow_right_new.png",
width: ScreenUtil().setWidth(18),
height: ScreenUtil().setWidth(32),
),
)
],
))),
Padding(
padding: EdgeInsets.only(left: w(16)),
child: MyDivider(double.infinity, w(0.5),
color: MyColours.color_E7E7E7)),
// InkWell(
// onTap: () {
// setState(() {
... ...
... ... @@ -2442,6 +2442,23 @@ class NavigatorUtil {
replace: replace);
}
///发放消费金
static Future<dynamic> goGrantPage(
BuildContext context, {
replace = false,
}) {
return _navigateTo(context, "${Routes.grant_page}", replace: replace);
}
///发放消费金
static Future<dynamic> goGrantWechatPage(
BuildContext context, {
replace = false,
}) {
return _navigateTo(context, "${Routes.grant_wechat_page}",
replace: replace);
}
///支付返券------优惠券选择
static Future<dynamic> goPaymentGiftSelectPage(
BuildContext context, String type, Map object, String from, String end,
... ...
... ... @@ -90,6 +90,8 @@ import 'package:one_key/pages/my/finance_manage/deposit_record_detail_page.dart'
import 'package:one_key/pages/my/finance_manage/record_home_classify_home_page.dart';
import 'package:one_key/pages/my/finance_manage/vip_record_detail_page.dart';
import 'package:one_key/pages/my/marketing_center/book_notification/marking_interaction_page.dart';
import 'package:one_key/pages/my/marketing_center/grant_page.dart';
import 'package:one_key/pages/my/marketing_center/grant_wechat_image_page.dart';
import 'package:one_key/pages/my/menu_type/menu_set_price_page.dart';
import 'package:one_key/pages/my/personnel_type/base_info_personnal_page.dart';
import 'package:one_key/pages/my/personnel_type/personnel_detail_page.dart';
... ... @@ -4315,6 +4317,20 @@ var returnMoneyPageHandle = new Handler(
create: (_) => FinanceProvider(), child: ReturnMoneyPage());
});
///发放消费金
var grantPageHandle = new Handler(
handlerFunc: (BuildContext? context, Map<String, List<Object>> params) {
return ChangeNotifierProvider<FinanceProvider>(
create: (_) => FinanceProvider(), child: GrantPage());
});
///扫码领消费金
var grantWechatPageHandle = new Handler(
handlerFunc: (BuildContext? context, Map<String, List<Object>> params) {
return ChangeNotifierProvider<FinanceProvider>(
create: (_) => FinanceProvider(), child: GrantWechatPage());
});
// /选择优惠券
// var paymentGiftSelectPageHandle = new Handler(
// handlerFunc: (BuildContext? context, Map<String, List<Object>> params) {
... ...
... ... @@ -433,6 +433,13 @@ class Routes {
static String return_money_page = "/return_money_page"; // 支付返消费金
static String grant_page = "/grant_page"; // 发放消费金
static String grant_wechat_page = "/grant_wechat_page"; // 扫码领消费金
static void configureRoutes(FluroRouter router) {
router.notFoundHandler = new Handler(
handlerFunc: (BuildContext? context, Map<String, List<String>> params) {
... ... @@ -819,5 +826,11 @@ class Routes {
router.define(table_home, handler: tableHomeHandle);
router.define(return_money_page, handler: returnMoneyPageHandle);
router.define( grant_page, handler: grantPageHandle);
router.define( grant_wechat_page , handler: grantWechatPageHandle);
}
}
... ...