404 lines
15 KiB
Dart
404 lines
15 KiB
Dart
import 'package:cached_network_image/cached_network_image.dart';
|
|
import 'package:circle_app/common/colors/app_color.dart';
|
|
import 'package:circle_app/util/util.dart';
|
|
import 'package:flutter/material.dart';
|
|
import 'package:flutter/rendering.dart';
|
|
import 'package:flutter/services.dart';
|
|
import 'package:flutter_screenutil/flutter_screenutil.dart';
|
|
import 'package:flutter_smart_dialog/flutter_smart_dialog.dart';
|
|
import 'package:flutter_swiper/flutter_swiper.dart';
|
|
import 'package:get/get.dart';
|
|
import 'package:get/get_core/src/get_main.dart';
|
|
import 'package:get/get_state_manager/src/simple/get_state.dart';
|
|
import 'package:image_gallery_saver/image_gallery_saver.dart';
|
|
import 'package:qr_flutter/qr_flutter.dart';
|
|
|
|
import '../../router/app_routers.dart';
|
|
import '../home/logic.dart';
|
|
import 'logic.dart';
|
|
import 'dart:ui' as ui;
|
|
class SwiperPage extends StatefulWidget {
|
|
const SwiperPage({Key? key}) : super(key: key);
|
|
|
|
@override
|
|
State<SwiperPage> createState() => _SwiperPageState();
|
|
}
|
|
|
|
class _SwiperPageState extends State<SwiperPage> {
|
|
|
|
GlobalKey _globalKey = GlobalKey();
|
|
|
|
var homeLogic = Get.find<HomeLogic>();
|
|
|
|
|
|
@override
|
|
Widget build(BuildContext context) {
|
|
return GetBuilder<SwiperLogic>(builder: (logic) {
|
|
List<Widget> imgList = [];
|
|
logic.imgList.forEach((element) {
|
|
imgList.add(CachedNetworkImage(
|
|
imageUrl: element,
|
|
|
|
fit: BoxFit.cover,
|
|
height: Get.height,
|
|
width: Get.width,
|
|
));
|
|
|
|
});
|
|
|
|
return Stack(
|
|
children: [
|
|
Stack(
|
|
children: [
|
|
RepaintBoundary(
|
|
key: _globalKey, child: itemWidget(logic, logic.index, true)),
|
|
Container(
|
|
width: Get.width,
|
|
height: Get.height,
|
|
color: Colors.black,
|
|
),
|
|
],
|
|
),
|
|
Scaffold(
|
|
appBar: null,
|
|
backgroundColor: Colors.black87,
|
|
body: GestureDetector(
|
|
behavior: HitTestBehavior.translucent,
|
|
onTap: (() {
|
|
//点击任意地方都能关闭页面,并且不影响你的滑动查看
|
|
Navigator.pop(context);
|
|
}),
|
|
child: Stack(
|
|
children: [
|
|
Container(
|
|
child: Swiper(
|
|
controller: logic.swiperController,
|
|
index: logic.index,
|
|
loop: false,
|
|
|
|
itemBuilder: (BuildContext context, int index) {
|
|
// if (logic.index == index) {
|
|
// return RepaintBoundary(
|
|
// key: _globalKey,
|
|
// child:itemWidget(logic,index));
|
|
// }
|
|
return itemWidget(logic,index,false);
|
|
},
|
|
|
|
onIndexChanged: (int index) {
|
|
logic.index = index;
|
|
logic.update();
|
|
},
|
|
itemCount: logic.imgList.length,
|
|
pagination: const SwiperPagination(
|
|
builder: DotSwiperPaginationBuilder(
|
|
activeColor: Color(0xFFD14CFF),
|
|
color: Colors.white)), //下面的分页小点
|
|
)),
|
|
Positioned(
|
|
bottom: Get.bottomBarHeight,
|
|
right: 15.sp,
|
|
child: InkWell(
|
|
onTap: () {
|
|
_saveLocalImage();
|
|
},
|
|
child: Container(
|
|
alignment: Alignment.center,
|
|
padding: EdgeInsets.all(5.sp),
|
|
decoration: BoxDecoration(
|
|
color: Colors.black.withOpacity(0.5),
|
|
borderRadius: BorderRadius.circular(17.5.sp)),
|
|
child: Icon(
|
|
Icons.download,
|
|
color: Colors.white,
|
|
size: 25.sp,
|
|
),
|
|
),
|
|
)),
|
|
if (logic.userId.isNotEmpty)
|
|
Positioned(
|
|
right: 16.sp,
|
|
top: 16.sp,
|
|
child: SafeArea(
|
|
child: GestureDetector(
|
|
onTap: () {
|
|
Get.toNamed(AppRoutes.UserInfoActivity,
|
|
arguments: logic.userId);
|
|
Get.delete<SwiperLogic>();
|
|
},
|
|
child: Container(
|
|
width: 73.sp,
|
|
height: 25.sp,
|
|
decoration: BoxDecoration(
|
|
gradient:
|
|
AppColor.mainVerLinearGradient,
|
|
borderRadius:
|
|
BorderRadius.circular(12.5.sp)),
|
|
child: Row(
|
|
mainAxisAlignment:
|
|
MainAxisAlignment.center,
|
|
children: [
|
|
Container(
|
|
margin: EdgeInsets.only(left: 5.sp),
|
|
child: Text(
|
|
'查看主页',
|
|
style: TextStyle(
|
|
color: Colors.white,
|
|
fontSize: 10.sp,
|
|
),
|
|
),
|
|
),
|
|
Image(
|
|
width: 15.sp,
|
|
image: AssetImage(
|
|
getDisCoverImage("right_icon")),
|
|
// width: 44.sp,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
)),
|
|
Positioned(
|
|
left: 5.sp,
|
|
top: 10.sp + MediaQuery.of(context).padding.top,
|
|
child: IconButton(
|
|
onPressed: () {
|
|
Get.back();
|
|
},
|
|
padding: EdgeInsets.only(left: 15.sp),
|
|
icon: Image.asset('assets/images/navigator/back.png',
|
|
width: 30.sp,
|
|
height: 30.sp,
|
|
),
|
|
)),
|
|
],
|
|
),
|
|
),
|
|
),
|
|
],
|
|
);
|
|
});
|
|
}
|
|
|
|
itemWidget(SwiperLogic logic,int index,bool isShow) {
|
|
String link = homeLogic.link + '#code=' + homeLogic.inviteCode;
|
|
return Stack(
|
|
children: [
|
|
Container(
|
|
color: Colors.black,
|
|
width: double.infinity,
|
|
height: Get.height,
|
|
alignment: Alignment.center,
|
|
child: SingleChildScrollView(
|
|
child: Column(
|
|
mainAxisAlignment: MainAxisAlignment.center,
|
|
children: [
|
|
Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
Container(
|
|
child: CachedNetworkImage(
|
|
imageUrl: logic.imgList[index],
|
|
fit: BoxFit.contain,
|
|
),
|
|
),
|
|
Positioned(
|
|
right: 10.sp,
|
|
bottom: 20.sp,
|
|
child: Container(
|
|
margin: EdgeInsets.only(top: Get.height * 0.45),
|
|
child: Text(
|
|
'微乐园APP',
|
|
style:
|
|
TextStyle(color: Colors.white, fontSize: 25.sp),
|
|
),
|
|
))
|
|
],
|
|
),
|
|
],
|
|
))),
|
|
if (isShow)
|
|
Positioned(
|
|
bottom: 0,
|
|
child: SafeArea(
|
|
child: Container(
|
|
width: Get.width,
|
|
color: Colors.black,
|
|
height: 60.sp,
|
|
child: Row(
|
|
children: [
|
|
Image.asset(
|
|
getBaseImage("ic_launcher"),
|
|
width: 50.sp,
|
|
height: 50.sp,
|
|
),
|
|
SizedBox(
|
|
width: 10.sp,
|
|
),
|
|
// Expanded(
|
|
// child:
|
|
Column(
|
|
crossAxisAlignment: CrossAxisAlignment.start,
|
|
children: [
|
|
Container(
|
|
margin: EdgeInsets.only(top: 5.sp, bottom: 5.sp),
|
|
width: Get.width - 150.sp,
|
|
child: Text('微乐园APP-认识更多小众圈子的人',
|
|
style: TextStyle(
|
|
color: Colors.white, fontSize: 14.sp))),
|
|
Container(
|
|
alignment: Alignment.center,
|
|
padding: EdgeInsets.only(left: 10.sp, right: 10.sp),
|
|
height: 25.sp,
|
|
decoration: BoxDecoration(
|
|
// color: Color(0xFFDC5BFD),
|
|
gradient: AppColor.mainVerLinearGradient,
|
|
borderRadius: BorderRadius.circular(12.5.sp)),
|
|
child: Text(
|
|
'专属邀请码:${homeLogic.inviteCode}',
|
|
style:
|
|
TextStyle(color: Colors.white, fontSize: 12.sp),
|
|
),
|
|
),
|
|
],
|
|
),
|
|
// ),
|
|
Expanded(child: Container()),
|
|
// SizedBox(width: 10.sp,),
|
|
Stack(
|
|
alignment: Alignment.center,
|
|
children: [
|
|
Container(
|
|
color: Colors.white,
|
|
width: 50.sp,
|
|
height: 50.sp,
|
|
),
|
|
QrImageView(
|
|
data: link,
|
|
padding: EdgeInsets.zero,
|
|
version: QrVersions.auto,
|
|
size: 45.sp,
|
|
gapless: false,
|
|
// backgroundColor: Colors.black,
|
|
)
|
|
],
|
|
),
|
|
SizedBox(
|
|
width: 10.sp,
|
|
),
|
|
],
|
|
),
|
|
),
|
|
)),
|
|
],
|
|
);
|
|
// return Container(
|
|
// width: Get.width,
|
|
// child: Column(
|
|
// mainAxisAlignment: MainAxisAlignment.center,
|
|
// children: [
|
|
// Stack(
|
|
// alignment: Alignment.center,
|
|
// children: [
|
|
//
|
|
// Container(
|
|
// // color: Colors.red,
|
|
//
|
|
// child: CachedNetworkImage(
|
|
// // progressIndicatorBuilder: (context,str,progress) {
|
|
// // return Container();
|
|
// // },
|
|
// placeholder: (context,str) {
|
|
// print(str + '进度');
|
|
// if (Get.arguments['index'] == index) {
|
|
// return Container(
|
|
// // color: Colors.red,
|
|
// child: CachedNetworkImage(
|
|
// imageUrl: logic.imgList[index].toString(),
|
|
//
|
|
// fit: BoxFit.cover,
|
|
// width: Get.width,
|
|
// ),
|
|
// );
|
|
// } else {
|
|
// return Container();
|
|
// }
|
|
// },
|
|
// imageUrl: logic.imgList[index].toString().contains('?') ? logic.imgList[index].toString().split('?').first : logic.imgList[index].toString(),
|
|
// fit: BoxFit.cover,
|
|
// width: Get.width,
|
|
// ),
|
|
// ),
|
|
// Positioned(
|
|
// left: 10.sp,
|
|
// bottom: 20.sp,
|
|
// child: Container(
|
|
// margin:
|
|
// EdgeInsets.only(top: Get.height * 0.45),
|
|
// child: Text(
|
|
// '微乐园APP',
|
|
// style: TextStyle(
|
|
// color: Colors.white, fontSize: 25.sp),
|
|
// ),
|
|
// ))
|
|
// ],
|
|
// )
|
|
// ],
|
|
// ));
|
|
}
|
|
|
|
_saveLocalImage() async {
|
|
RenderRepaintBoundary boundary =
|
|
_globalKey.currentContext!.findRenderObject() as RenderRepaintBoundary;
|
|
ui.Image image =
|
|
await boundary.toImage(pixelRatio: ui.window.devicePixelRatio);
|
|
ByteData? byteData =
|
|
await (image.toByteData(format: ui.ImageByteFormat.png));
|
|
if (byteData != null) {
|
|
SmartDialog.showLoading(msg: '正在保存...');
|
|
final result =
|
|
await ImageGallerySaver.saveImage(byteData.buffer.asUint8List());
|
|
print(result);
|
|
SmartDialog.dismiss();
|
|
// isSuccess
|
|
if (result['isSuccess']) {
|
|
showOKToast('保存成功');
|
|
} else {
|
|
showOKToast('保存失败,请检查相册权限是否开启');
|
|
}
|
|
}
|
|
}
|
|
// Widget build(BuildContext context) {
|
|
|
|
// return GetBuilder<SwiperLogic>(builder: (logic) {
|
|
//
|
|
// return Scaffold(
|
|
// appBar: null,
|
|
// backgroundColor: Colors.black87,
|
|
// body: GestureDetector(
|
|
// behavior: HitTestBehavior.translucent,
|
|
// onTap: (() {
|
|
// //点击任意地方都能关闭页面,并且不影响你的滑动查看
|
|
// Navigator.pop(context);
|
|
// }),
|
|
// child: Swiper(
|
|
// controller: logic.swiperController,
|
|
// index:logic.index,
|
|
// itemBuilder: (BuildContext context, int index) {
|
|
// print("img="+logic.imgList[index]);
|
|
// // return SizedBox(
|
|
// // width: double.infinity,
|
|
// // child: Image.network(
|
|
// // "${logic.imgList[index]}?imageView2/0/q/60|watermark/2/text/5b6u5LmQ5ZutQVBQ/font/5b6u6L2v6ZuF6buR/fontsize/2160/fill/I0ZGRkZGRg==/dissolve/50/gravity/SouthEast/dx/60/dy/120", fit: BoxFit.contain,)
|
|
// // );
|
|
// },
|
|
// itemCount: logic.imgList.length,
|
|
// pagination: SwiperPagination(), //下面的分页小点
|
|
// // control: new SwiperControl(), //左右的那个箭头,在某模拟器中会出现蓝线
|
|
// ),
|
|
// ),
|
|
// );
|
|
// });
|
|
// }
|
|
} |